Commit Graph

154 Commits

Author SHA1 Message Date
Hector
e5714b7485 fix: read socket response data in chunks
Read the response data from the socket in chunks to prevent errors when
processing large payloads. The initial implementation solved large payloads
by just defining a very large buffer, but this is not a solution. The new
code reads the socket data in a loop until a terminator is found and
appends all the data into a single byte array.
Reduce the buffer size to `1024` bytes.
2021-08-29 16:02:31 +01:00
Hector
e083b48461 Merge branch 'feat/ping-fail2ban-server-over-socket' into 'main'
Feat/ping fail2ban server over socket

See merge request hectorjsmith/fail2ban-prometheus-exporter!23
2021-08-29 11:50:53 +00:00
Hector
39133d0a76 feat: collect new up metric from fail2ban socket
Add support for connecting the exporter directly to the fail2ban server's
socket to send requests and receive data. The path to the socket file is
optional and specified on startup.
Export a new metric based on the response of the `ping` command sent to the
fail2ban server. The metric is set to 1 if the server responds with `pong`
and 0 in any other case. This metric is only shown if the path to the
socket file was provided on startup.
2021-08-29 11:50:53 +00:00
Hector
9d6b35c59a Merge branch 'fix/update-banned-metric-to-exclude-expired-bans' into 'main'
Fix/update banned metric to exclude expired bans

See merge request hectorjsmith/fail2ban-prometheus-exporter!21
2021-08-27 15:34:21 +00:00
Hector
526b1c7272 fix: update banned metrics to exclude expired bans
Update the database query counting the number of banned IPs to filter out
any bans that have already expired. An expired ban is defined as a ban
where the "time of ban" plus the "duration of ban" is less than the
current time.
This is necessary because bans that have expired are not automatically
removed from the database and will cause metrics to diverge from the counts
reported by `fail2ban-client`.
2021-08-27 16:29:01 +01:00
Hector
a5e1ae4495 Merge branch 'feat/db-error-count-metric' into 'main'
Feat/db error count metric

See merge request hectorjsmith/fail2ban-prometheus-exporter!20
2021-04-07 20:50:23 +00:00
Hector
8726afcd6b feat: new metric to track error counts
Add a new metric to count the number of database errors that have been
found since startup. This complements the `up` metric to have better
visibility into occasional database errors.
2021-04-07 21:46:41 +01:00
Hector
a406e019e2 Merge branch 'feat/base-up-metric-on-errors' into 'main'
Feat/base up metric on errors

See merge request hectorjsmith/fail2ban-prometheus-exporter!19
2021-04-07 20:35:39 +00:00
Hector
bd841c3a35 feat: set up metric to 0 if errors found
The `up` metric is now based on whether an error was found while reading
data from the database to build other metrics. Note that there is a chance
the `up` metric will not be correctly set if the last metric to be built
before the `up` metric does not throw an error.
2021-04-07 21:32:49 +01:00
Hector
a9e41188f6 Merge branch '1-export-metrics-on-enabled-disabled-jails' into 'main'
Resolve "Export metrics on enabled/disabled jails"

Closes #1

See merge request hectorjsmith/fail2ban-prometheus-exporter!18
2021-04-07 18:00:26 +00:00
Hector
1282d635eb feat: new metric for enabled jails (#1)
Add a new prometheus metric to track which jails are currently enabled.
Add a new database query to read the jail name and enabled status from the
database.
Add new metric to readme file.
2021-04-07 18:55:34 +01:00
Hector
5f9085aa5a Merge branch 'release/0.1.0' into 'main'
Release/0.1.0

See merge request hectorjsmith/fail2ban-prometheus-exporter!17
2021-03-28 16:26:45 +00:00
Hector
da7943bf90 docs: update changelog for release 2021-03-28 17:14:48 +01:00
Hector
1682dac4af docs: fix branch name in chglog configuration
Fix the main branch name in the template CHANGELOG  file for the git
chglog tool.
2021-03-28 17:09:53 +01:00
Hector
7b1ff91ede Merge branch '9-reduce-docker-image-size' into 'main'
Resolve "Reduce docker image size"

Closes #9

See merge request hectorjsmith/fail2ban-prometheus-exporter!15
2021-03-27 17:34:41 +00:00
Hector
0751f3fca6 Merge branch 'main' into 9-reduce-docker-image-size 2021-03-27 17:31:41 +00:00
Hector
3c4a8f5495 build: split docker build into two images (#9)
Update the docker build file to use two images - one for building, and one
for running/deployment. This helps reduce the size of the final image.
2021-03-27 17:29:28 +00:00
Hector
0493c4dcb1 Merge branch 'ci/remove-dependency-step' into 'main'
Ci/remove dependency step

See merge request hectorjsmith/fail2ban-prometheus-exporter!16
2021-03-27 17:27:47 +00:00
Hector
1ac9f5a551 ci: remove dependency step from ci/cd pipeline
Remove the dependency check step to avoid breaking builds.
2021-03-27 17:19:45 +00:00
Hector
3de54b0b71 Merge branch 'docs/fix-readme-toc' into 'main'
docs: fix item in readme table of contents

See merge request hectorjsmith/fail2ban-prometheus-exporter!14
2021-02-11 09:06:44 +00:00
Hector
2ee63cca7d docs: fix item in readme table of contents 2021-02-11 09:04:38 +00:00
Hector
95f8026f7c Merge branch 'docs/fix-typo-in-readme-docker-compose' into 'main'
docs: fix typo in readme docker-compose

See merge request hectorjsmith/fail2ban-prometheus-exporter!13
2021-02-10 18:58:26 +00:00
Hector
c9ad2e826f docs: fix typo in readme docker-compose 2021-02-10 18:56:25 +00:00
Hector
26da913294 Merge branch 'docs/add-usage-instructions-to-readme-file' into 'main'
Docs/add usage instructions to readme file

See merge request hectorjsmith/fail2ban-prometheus-exporter!12
2021-02-10 13:09:25 +00:00
Hector
d6ad09341b docs: populate readme file with project information
Update the project README file to include information on what the project
does and how to run it.
2021-02-10 11:48:04 +00:00
Hector
51fa607c28 Merge branch '3-publish-docker-image' into 'main'
Resolve "Publish docker image"

Closes #3

See merge request hectorjsmith/fail2ban-prometheus-exporter!11
2021-02-08 20:10:01 +00:00
Hector
ac8ecfb1aa ci: restrict docker build to main branch and tags (#3) 2021-02-08 20:07:56 +00:00
Hector
dae6d559e5 ci: add docker build to gitlab ci/cd (#3)
Update the Gitlab CI/CD pipeline to include a step to build and push the
project docker image. The CI/CD step uses existing Makefile commands to
build the docker image.
2021-02-08 20:00:27 +00:00
Hector
542b853309 Merge branch 'build/compile-docker-version-of-tool' into 'main'
Build/compile docker version of tool

See merge request hectorjsmith/fail2ban-prometheus-exporter!10
2021-02-08 19:54:02 +00:00
Hector
b63f641bfd build: compile tool during docker build
Update the project Dockerfile to compile the tool during the docker build
instead of assuming the goreleaser tool was run previously. This allows
for custom data to be set in the compiled tool (e.g. compiled by docker)
and removes the dependency on another build step.
Update the Makefile to include a new command to build the tool for docker
which sets the version data correctly. Rename the docker commands to follow
the `docker/build-...` format to avoid confusion with the build commands.
2021-02-08 19:48:55 +00:00
Hector
50c969014f Merge branch 'chore/create-new-src-folder' into 'main'
Chore/create new src folder

See merge request hectorjsmith/fail2ban-prometheus-exporter!9
2021-02-08 18:53:00 +00:00
Hector
9bf3195743 chore: move all source files to new folder
Update the project structure to move all golang files to a new `src/`
folder. This keeps all the code located in the same place and easier to
work with.
Update the Makefile and goreleaser config to continue to work with the new
folder structure.
2021-02-08 18:49:48 +00:00
Hector
b1c70da101 Merge branch '2-build-docker-image' into 'main'
Resolve "Build docker image"

Closes #2

See merge request hectorjsmith/fail2ban-prometheus-exporter!7
2021-02-07 13:11:16 +00:00
Hector
9dc8dd862f build: add project dockerfile (#2)
Add a project Dockerfile to allow deploying the application in a docker
container. Add a `run.sh` script to start the application in the container.
Add Makefile commands to build the docker image based on the Dockerfile.
Fix possible nil reference error in the `db` package.
2021-02-07 13:09:02 +00:00
Hector
f452100a75 Merge branch 'fix/compile-without-cgo-enabled' into 'main'
Fix/compile without cgo enabled

See merge request hectorjsmith/fail2ban-prometheus-exporter!8
2021-02-07 12:59:01 +00:00
Hector
0842419136 fix: compile tool without cgo_enabled flag
Remove the `CGO_ENABLED=0` flag from the `goreleaser` configuration. This
was causing the compiled binary to throw segmentation errors when
collecting metrics.
2021-02-07 11:43:07 +00:00
Hector
e94143e81c Merge branch '5-setup-project-changelog' into 'main'
Resolve "Setup project changelog"

Closes #5

See merge request hectorjsmith/fail2ban-prometheus-exporter!6
2021-02-07 11:20:56 +00:00
Hector
eaec4db47c docs: generate changelog file (#5) 2021-02-07 11:16:29 +00:00
Hector
50e1d4b8c8 build: add tool to auto-generate changelog (#5)
Add the `git-chglog` tool to handle auto-generating the project changelog
based on the commit history. Add a custom configuration and file template.
Update the Makefile to include a command to generate the changelog.
2021-02-07 11:15:41 +00:00
Hector
3cb7c71b17 Merge branch '6-setup-goreleaser-to-compile-tool' into 'main'
Resolve "Setup goreleaser to compile tool"

Closes #6

See merge request hectorjsmith/fail2ban-prometheus-exporter!5
2021-02-07 11:03:13 +00:00
Hector
acc42d8079 ci: restrict build step to main branch and tags (#6) 2021-02-07 11:00:13 +00:00
Hector
98c6da4796 Merge branch '8-fail-on-startup-if-database-file-does-not-exist' into 'main'
Resolve "Fail on startup if database file does not exist"

Closes #8

See merge request hectorjsmith/fail2ban-prometheus-exporter!4
2021-02-07 10:52:14 +00:00
Hector
88be0f358e ci: add build stage to gitlab ci/cd (#6)
Update the Gitlab CI/CD process to include a build stage that uses
`goreleaser` to build and package the application. The output of the build
is stored as an artifact for 1 day.
2021-02-07 10:51:43 +00:00
Hector
570c162c13 build: add goreleaser to build tool (#6)
Add the `goreleaser` tool to the repository to handle building and
publishing the application. Add a simple configuration file to build the
application for all major OS versions.
Update the Makefile to include commands to build release and snapshot
versions of the tool.
Add a placeholder CHANGELOG file to be included in the package files.
2021-02-07 10:46:25 +00:00
Hector
6355c9e8e1 feat: fail on startup if database file does not exist (#8)
Add a check when connecting to the sqlite3 database to ensure that the file
exists before connecting. If the file does not exist, the connection fails.
2021-02-07 10:36:08 +00:00
Hector
188626198f Merge branch '4-configure-tool-using-cli-parameters' into 'main'
Resolve "Configure tool using CLI parameters"

Closes #4

See merge request hectorjsmith/fail2ban-prometheus-exporter!3
2021-02-06 15:22:07 +00:00
Hector
4f18bf35a8 feat: add cli parameters for db path and metrics port (#4)
Add support for configuring CLI parameters in the application using a new
`cfg` package. The `cfg` package exports an `AppSettings` struct that
contains the settings the application was run with.
Update the application to use the new CLI parameters to set the db to open
and the port to use for the metrics server.
Add support for setting the app version during build. The app includes a
`-version` flag to print the stored version data.
2021-02-06 15:17:35 +00:00
Hector
5e81a98162 Merge branch 'feat/export-metrics-from-fail2ban-db' into 'main'
Feat/export metrics from fail2ban db

See merge request hectorjsmith/fail2ban-prometheus-exporter!2
2021-02-06 12:29:47 +00:00
Hector
91cba8080c feat: export number of banned ips
Export the number of banned IPs stored in the fail2ban database as well
as the number of bad IPs.
Update the queries used to collect data to better handle cases where the
database table for bad/banned IPs is empty. The new query always lists all
jails, even when the count is zero.
2021-02-06 12:24:31 +00:00
Hector
4b965017d2 feat: export bad ip count per jail
Update exported metrics to spit the number of bad IPs per jail using metric
value labels. This includes a change to the database code to use a
different query that groups the count by the `jail` column.
2021-02-06 12:14:39 +00:00