Merge branch 'main' into 'main'

feat: Add listen address parameter

See merge request hectorjsmith/fail2ban-prometheus-exporter!47
This commit is contained in:
Hector 2021-12-18 06:45:37 +00:00
commit 6bbdd7a0a6
3 changed files with 5 additions and 1 deletions

View File

@ -33,6 +33,8 @@ See the [releases page](https://gitlab.com/hectorjsmith/fail2ban-prometheus-expo
``` ```
$ fail2ban-prometheus-exporter -h $ fail2ban-prometheus-exporter -h
-web.listen-address string
address to use for metrics server (default 0.0.0.0)
-port int -port int
port to use for the metrics server (default 9191) port to use for the metrics server (default 9191)
-socket string -socket string

View File

@ -13,6 +13,7 @@ const (
type AppSettings struct { type AppSettings struct {
VersionMode bool VersionMode bool
MetricsAddress string
MetricsPort int MetricsPort int
Fail2BanSocketPath string Fail2BanSocketPath string
FileCollectorPath string FileCollectorPath string
@ -22,6 +23,7 @@ type AppSettings struct {
func Parse() *AppSettings { func Parse() *AppSettings {
appSettings := &AppSettings{} appSettings := &AppSettings{}
flag.BoolVar(&appSettings.VersionMode, "version", false, "show version info and exit") 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.IntVar(&appSettings.MetricsPort, "port", 9191, "port to use for the metrics server")
flag.StringVar(&appSettings.Fail2BanSocketPath, "socket", "", "path to the fail2ban server socket") flag.StringVar(&appSettings.Fail2BanSocketPath, "socket", "", "path to the fail2ban server socket")
flag.BoolVar(&appSettings.FileCollectorEnabled, "collector.textfile", false, "enable the textfile collector") flag.BoolVar(&appSettings.FileCollectorEnabled, "collector.textfile", false, "enable the textfile collector")

View File

@ -53,7 +53,7 @@ func main() {
if appSettings.VersionMode { if appSettings.VersionMode {
printAppVersion() printAppVersion()
} else { } 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) log.Printf("starting fail2ban exporter at %s", addr)