#1064925 RFP: fail2ban-prometheus-exporter - collect and export Prometheus metrics on Fail2Ban)

#1064925#5
Date:
2024-02-27 19:34:30 UTC
From:
To:
Reasoning: I need this! :) I could have written a mtail parser instead, but
/fail2ban.actions\s+\[\d+\]:\s+\w+\s+\[(?P<jail>)\] (?P<action>Ban|Unban)\s+/ {
    fail2ban_action_count[$jail][$action]++
/fail2ban.filter\s+\[\d+\]:\s+\w+\s+\[(?P<jail>)\] (?P<action>Found)\s+/ {
    fail2ban_filter_count[$jail][$action]++
* Package name    : fail2ban-prometheus-exporter
  Version         : 0.10.1-1
  Upstream Author : hectorjsmith
* URL             : https://gitlab.com/hectorjsmith/fail2ban-prometheus-exporter
* License         : MIT
  Programming Lang: Go
  Description     : collect and export Prometheus metrics on fail2ban

This Prometheus exporter provides Prometheus (or OpenMetrics) metrics
for the fail2ban package. It tracks the number of IPs currently
blocked, matched, how long they are tracked, and keeps track of
errors.

It parses data from the fail2ban socket and can export metrics over a
normal HTTP service or the text file collector.
----

halfway through doing that, I wondered "surely someone must have fixed that
already", and lo and behold.

A mtail equivalent might be:

# fail2ban log parser
#
# log lines:
#
# 2024-02-17 15:30:53,167 fail2ban.filter         [578]: INFO    [fraud-donation-spam] Found 185.92.25.49 - 2024-02-17 15:30:52
# 2024-02-17 15:30:53,542 fail2ban.actions        [578]: NOTICE  [fraud-donation-spam] Ban 185.92.25.49
# 2024-02-24 15:30:45,200 fail2ban.actions        [578]: NOTICE  [fraud-donation-spam] Unban 91.230.225.115

counter fail2ban_action_count by jail, action

}

}

.... but is not quite as accurate, because it tracks bans/unbans
independently, and doesn't reflect the actual state of the system
properly.
Autocrypt: addr=anarcat@debian.org; prefer-encrypt=nopreference; keydata=xjMEZHZPzhYJKwYBBAHaRw8BAQdAWdVzOFRW6FYVpeVaDo3sC4aJ2kUW4ukdEZ36UJLAHd7NJUFudG9pbmUgQmVhdXByw6kgPGFuYXJjYXRAZGViaWFuLm9yZz7ClgQTFggAPhYhBLu2zUyY104TWKdSpgIpOm+k5TRzBQJkdmCVAhsDBQkB4TOABQsJCAcDBRUKCQgLBRYCAwEAAh4BAheAAAoJEAIpOm+k5TRz+w8BANbRA+AMH0LN7trugVhaWe4wDpg94UVJloHPL+adJMK/AQCh39hyQXk3ivS2cK7xKZUgK0dBsbtJ2I2XBXvL9dS3Cc44BGR2UM4SCisGAQQBl1UBBQEBB0CYZha2IMY54WFXMG4S9/Smef54Pgon99LJ/hJ885p0ZAMBCAfCdwQYFggAIBYhBLu2zUyY104TWKdSpgIpOm+k5TRzBQJkdlDOAhsMAAoJEAIpOm+k5TRzBg0A+IbcsZhLx6FRIqBJCdfYMo7qovEo+vX0HZsUPRlq4HkBAIctCzmH3WyfOD/aUTeOF3tY+tIGUxxjQLGsNQZeGrQI
Date: Tue, 27 Feb 2024 14:34:11 -0500
Message-ID: <87msrl3dn0.fsf@angela.anarc.at>

#1064925#10
Date:
2024-02-27 19:56:16 UTC
From:
To:
I thought all deps were in Debian, but I was wrong, those are missing:

github.com/kisielk/og-rek
github.com/nlpodyssey/gopickle

It's not that bad! Only two! But weirdly, they both relate to
(presumably Python) "pickles" so I'm not sure why both are necessary.

So I'll step away from this package for now, I ran out of cycles. It's
much easier to just do the fail2ban hack for now. I pushed the goods to
Salsa:

https://salsa.debian.org/go-team/packages/fail2ban-prometheus-exporter

Here's the build log:

Command: dpkg-buildpackage --sanitize-env -us -uc -rfakeroot
dpkg-buildpackage: info: source package fail2ban-prometheus-exporter
dpkg-buildpackage: info: source version 0.10.1-1
dpkg-buildpackage: info: source distribution experimental
dpkg-buildpackage: info: source changed by Antoine Beaupré <anarcat@debian.org>
 dpkg-source --before-build .
dpkg-buildpackage: info: host architecture amd64
 debian/rules clean
dh clean --builddirectory=_build --buildsystem=golang --with=golang
   dh_auto_clean -O--builddirectory=_build -O--buildsystem=golang
   dh_autoreconf_clean -O--builddirectory=_build -O--buildsystem=golang
   dh_clean -O--builddirectory=_build -O--buildsystem=golang
 dpkg-source -b .
dpkg-source: info: using source format '3.0 (quilt)'
dpkg-source: info: building fail2ban-prometheus-exporter using existing ./fail2ban-prometheus-exporter_0.10.1.orig.tar.gz
dpkg-source: info: building fail2ban-prometheus-exporter in fail2ban-prometheus-exporter_0.10.1-1.debian.tar.xz
 debian/rules binary
dpkg-source: info: building fail2ban-prometheus-exporter in fail2ban-prometheus-exporter_0.10.1-1.dsc
dh binary --builddirectory=_build --buildsystem=golang --with=golang
   dh_update_autotools_config -O--builddirectory=_build -O--buildsystem=golang
   dh_autoreconf -O--builddirectory=_build -O--buildsystem=golang
   dh_auto_configure -O--builddirectory=_build -O--buildsystem=golang
   dh_auto_build -O--builddirectory=_build -O--buildsystem=golang
	cd _build && go install -trimpath -v -p 12 gitlab.com/hectorjsmith/fail2ban-prometheus-exporter gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/collector/f2b gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/collector/textfile gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/server gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket
src/gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket/fail2banSocket.go:5:2: cannot find package "github.com/kisielk/og-rek" in any of:
	/usr/lib/go-1.22/src/github.com/kisielk/og-rek (from $GOROOT)
	/<<PKGBUILDDIR>>/_build/src/github.com/kisielk/og-rek (from $GOPATH)
src/gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket/protocol.go:7:2: cannot find package "github.com/nlpodyssey/gopickle/pickle" in any of:
	/usr/lib/go-1.22/src/github.com/nlpodyssey/gopickle/pickle (from $GOROOT)
	/<<PKGBUILDDIR>>/_build/src/github.com/nlpodyssey/gopickle/pickle (from $GOPATH)
src/gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket/fail2banSocket.go:6:2: cannot find package "github.com/nlpodyssey/gopickle/types" in any of:
	/usr/lib/go-1.22/src/github.com/nlpodyssey/gopickle/types (from $GOROOT)
	/<<PKGBUILDDIR>>/_build/src/github.com/nlpodyssey/gopickle/types (from $GOPATH)
dh_auto_build: error: cd _build && go install -trimpath -v -p 12 gitlab.com/hectorjsmith/fail2ban-prometheus-exporter gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/collector/f2b gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/collector/textfile gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/server gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket returned exit code 1
make: *** [debian/rules:4: binary] Error 25
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
--------------------------------------------------------------------------------
Build finished at 2024-02-27T19:51:28Z

#1064925#19
Date:
2024-03-15 02:09:13 UTC
From:
To:
Should the package name perhaps instead be
"prometheus-fail2ban-exporter", so that it aligns with the approximately
three dozen other exporters already packaged by Debian?

In case you're wondering, there /are/ other examples where the upstream
name has been munged to conform with the "prometheus-foo-exporter"
pattern, e.g. prometheus-mqtt-exporter (upstream name mqtt2prometheus).