Commit Graph

32 Commits

Author SHA1 Message Date
Hector
24ee5d96bd refactor: rename project module
Rename the project module to include the full project URL instead of just
the name. This better aligns with Go best-practices.
2022-02-25 21:53:38 +00:00
Hector
f6e328a0aa feat: correctly handle shutdown signals
Add a new method to the application startup to listen for OS shutdown
signals and handle them appropriately. A shutdown signal will cause the
app to exit immediately.
Use correct syntax for the `ENTRYPOINT` field in the Dockerfile to ensure
that OS signals get passed down to the running application.
2022-02-20 08:17:06 +00:00
Hector
6e575aa0fd feat: rewrite cli flags and environment variables
Replace existing CLI flags to make them more consistent and follow a more
standard format.
Remove CLI flags and environment variables that are no longer relevant.
Add short `-v` option for version flag.
Update README with new documentation.

BREAKING CHANGE: Replace `--socket` flag with `--collector.f2b.socket`.
BREAKING CHANGE: Merge `--port` flag and `--web.listen-address` into a single flag.
BREAKING CHANGE: Remove `--collector.textfile` flag, its value is now derived from `--collector.textfile.directory`.
BREAKING CHANGE: Remove `F2B_COLLECTOR_TEXT` and `F2B_WEB_PORT` environment variables.
2022-02-19 17:01:49 +00:00
Hector
e2902b8cc2 feat: improve logging on startup
Update the exporter logging on startup to include the exporter version,
the path to the fail2ban socket, and whether basic-auth is enabled or not.
Fix code printing error messages on invalid CLI parameters to correct line
breaks and correctly print the "usage" information.
2022-02-19 11:21:58 +00:00
Hector
1f27dace2d feat: add default value for fail2ban socket path
Update the CLI param parser to include a default value for the fail2ban
socket file path. This is the default location fail2ban creates the socket
file on an ubuntu-based system.
2022-02-18 22:15:32 +00:00
Hector
93da909b0a fix: use correct flag in dockerfile (#18)
Update the Dockerfile entrypoint script to use the correct version flag
syntax. The flag now requires two dashes instead of one. The syntax for
the texfile collector has also change, and the script was updated
accordingly.
Fix incorrect order of variable assignment when parsing CLI flags.
2022-01-31 22:51:13 +00:00
Hector
b7e317edbc feat: configure tool using environment variables (#17)
Replace CLI parsing functionality with the `kingpin` library to better
support configuring the tool with environment variables.
Add new environment variables to configure the tool.

BREAKING CHANGE: CLI params now require two dashes instead of one (e.g. `--socket`)
2022-01-30 21:32:48 +00:00
Hector
6f76a03118 feat: add support for basic auth (#16)
Add new CLI parameters to enable protecting the API endpoints with basic
auth authentication.
Wrap the server endpoints in a new auth middleware that protects it using
the provided basic auth credentials (if set).
Store the provided basic auth credentials as hashed values to prevent them
from being accidentally leaked.
Add unit tests to ensure the new functionality works as expected.
2022-01-14 21:36:49 +00:00
Hector
497e2ff692 remove: references to db collector
Remove final references to the deprecated database metric collector.
Remove counter for db connection errors.

BREAKING CHANGE: Remove `-db` CLI flag.
2021-12-21 17:42:42 +00:00
Hector
4be463a7c8 Merge branch 'python2' into 'main'
fix: support python2 fail2ban

Closes #14

See merge request hectorjsmith/fail2ban-prometheus-exporter!48
2021-12-18 06:58:40 +00:00
Private Creator
7932ccbe23 fix: support python2 fail2ban
Python2 pickles use different class names for some types. Specifically,
builtins.str is __builtin__.str.
2021-12-18 06:58:40 +00:00
Private Creator
c208c8e97d feat: add listen address parameter
Add new -web.listen-address command line parameter, so that the
listening interface can be limited. This follows a similar style as
the official prometheus-node-exporter project.
Update project README with the new parameter.
2021-12-18 06:45:37 +00:00
Hector
4f2d8d9079 refactor: update imports in exporter.go
Remove unnecessary name from the textfile import.
Remove the sqlite3 dependency which is no longer required.
2021-10-18 19:32:08 +01:00
Hector
b268f8654c remove: database-based metrics
Remove all database-based metrics from the metrics endpoint.
Remove all code related to pulling metrics from the fail2ban database.
Remove all configuration variables related to the fail2ban database.
The CLI parameter for the database path was not removed to avoid breaking
compatibility.
Update docker entrypoint to remove references to the fail2ban database.
Remove all references to the old database metrics from the README.
2021-10-15 18:02:26 +00:00
Hector
56730c8774 feat: add new jail config metrics
Add new metrics around basic jail configuration. The new metrics expose the
max retries, ban time, and find time for each jail.
Update project README with the new metrics.
2021-10-14 20:52:25 +00:00
Hector
60e6365e1f refactor: create new collector folder
Create a new `collector` folder to store the code for the different
collectors. Move the existing f2b and textfile collectors to this folder.
Minor refactors to the f2b collector to better match the code style of the
newer textfile collector.
2021-10-13 21:33:49 +01:00
Hector
5a107cc547 feat: support for textfile metrics (#13)
Add support for collecting arbitrary metrics from a textfile as well as
metrics collected from fail2ban. This allows other data to be exported
along with the fail2ban metrics (e.g. instance metadata).
Update the docker image to allow mounting a folder with a collection of
metric files to be exported. Only files ending in `.prom` with be read.
Update project README with the new functionality.
2021-10-12 20:38:26 +00:00
Hector
84b9d02068 feat: render basic html page at root url
Add a new request handler for the root URL (`/`) to render a simple HTML
page with a link to the metrics page. This follows the convention of other
metric exporters.
2021-09-25 21:23:28 +00:00
Hector
22a165da3e feat: improve startup logging
Update the exporter startup to add more log messages. The server address,
port, and metrics path are now logged on startup.
A "ready" log message is printed when the server is up and running.
2021-09-21 09:34:23 +01:00
Hector
03f5084020 refactor: move exporter code to new package
Split out all the code to define exporter functions and collect data into
a new package. The new package is responsible for all exporter related
activity. This makes the code easier to read.
Split the code for collecting metrics from the database and from the socket
into different files to make the separation more obvious.
2021-09-13 20:25:54 +01:00
Hector
fba9ee2809 feat: export new version metric (#12)
Add a new `f2b_version` metric that includes the version of the fail2ban
server and the exporter.
Add a new socket command to get back the fail2ban server version.
2021-09-10 06:13:56 +00:00
Hector
5b62670e9d refactor: deprecate database metrics
Update all old database-based metrics to include the `deprecated` text.
Add a warning on startup if connecting to the fail2ban database to state
that this functionality will be removed in a future release.
Rename deprecated methods and variables.
2021-08-30 16:38:33 +00:00
Hector
4da46f3c4a feat: export metrics with socket errors
Add new metric to collect the number of errors found when connecting to the
fail2ban server socket. Errors are split into two categories: connection
errors (e.g. socket file not found), and request errors (e.g. invalid
response received from server).
Update the `up` metric to return `0` if the socket connection fails.
Improve error logging.
2021-08-30 07:19:11 +00:00
Hector
acb40a94bd fix: recover from fail2ban server restarts
Update the code collecting metrics to open a new socket connection each
time metrics are collected. This ensures that a new socket connection is
used each time and avoids errors caused by fail2ban being restarted.
2021-08-30 07:36:15 +01:00
Hector
1964dde273 feat: export metrics for failed/banned counts
Add new metric to track the total number of jails configured in fail2ban.
Add new metrics for the current and total number of filter failures for
each jail, as well as the current/total number of banned IPs per jail.
The new metrics are collected by sending the `status [jail]` command to the
fail2ban server and parsing the response data.
2021-08-29 16:54:20 +00:00
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
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
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
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
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
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
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