From c208c8e97d26efdb849441ab22a0e02aa1fa1dba Mon Sep 17 00:00:00 2001 From: Private Creator <10456533-private-creator@users.noreply.gitlab.com> Date: Sat, 18 Dec 2021 06:45:37 +0000 Subject: [PATCH] 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. --- README.md | 2 ++ src/cfg/cfg.go | 2 ++ src/exporter.go | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cd99bc..eba535a 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ See the [releases page](https://gitlab.com/hectorjsmith/fail2ban-prometheus-expo ``` $ fail2ban-prometheus-exporter -h + -web.listen-address string + address to use for metrics server (default 0.0.0.0) -port int port to use for the metrics server (default 9191) -socket string diff --git a/src/cfg/cfg.go b/src/cfg/cfg.go index f087211..59da318 100644 --- a/src/cfg/cfg.go +++ b/src/cfg/cfg.go @@ -13,6 +13,7 @@ const ( type AppSettings struct { VersionMode bool + MetricsAddress string MetricsPort int Fail2BanSocketPath string FileCollectorPath string @@ -22,6 +23,7 @@ type AppSettings struct { func Parse() *AppSettings { appSettings := &AppSettings{} flag.BoolVar(&appSettings.VersionMode, "version", false, "show version info and exit") + flag.StringVar(&appSettings.MetricsAddress, "web.listen-address", "0.0.0.0", "address to use for the metrics server") flag.IntVar(&appSettings.MetricsPort, "port", 9191, "port to use for the metrics server") flag.StringVar(&appSettings.Fail2BanSocketPath, "socket", "", "path to the fail2ban server socket") flag.BoolVar(&appSettings.FileCollectorEnabled, "collector.textfile", false, "enable the textfile collector") diff --git a/src/exporter.go b/src/exporter.go index 8adc057..a62271c 100644 --- a/src/exporter.go +++ b/src/exporter.go @@ -53,7 +53,7 @@ func main() { if appSettings.VersionMode { printAppVersion() } else { - addr := fmt.Sprintf("0.0.0.0:%d", appSettings.MetricsPort) + addr := fmt.Sprintf("%s:%d", appSettings.MetricsAddress, appSettings.MetricsPort) log.Printf("starting fail2ban exporter at %s", addr)