From d81d494f19bd26fbfe3004d3a647cb4eb4c0ab9c Mon Sep 17 00:00:00 2001 From: Hector Date: Mon, 11 Oct 2021 21:04:37 +0100 Subject: [PATCH] add cli options to enable the textfile collector --- src/cfg/cfg.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cfg/cfg.go b/src/cfg/cfg.go index 1b4ce49..b9c4f3e 100644 --- a/src/cfg/cfg.go +++ b/src/cfg/cfg.go @@ -16,6 +16,8 @@ type AppSettings struct { MetricsPort int Fail2BanDbPath string Fail2BanSocketPath string + FileCollectorPath string + FileCollectorEnabled bool } func Parse() *AppSettings { @@ -24,6 +26,8 @@ func Parse() *AppSettings { flag.IntVar(&appSettings.MetricsPort, "port", 9191, "port to use for the metrics server") flag.StringVar(&appSettings.Fail2BanDbPath, "db", "", "path to the fail2ban sqlite database (deprecated)") flag.StringVar(&appSettings.Fail2BanSocketPath, "socket", "", "path to the fail2ban server socket") + flag.BoolVar(&appSettings.FileCollectorEnabled, "collector.textfile", false, "enable the textfile collector") + flag.StringVar(&appSettings.FileCollectorPath, "collector.textfile.directory", "", "directory to read text files with metrics from") flag.Parse() appSettings.validateFlags() @@ -42,6 +46,10 @@ func (settings *AppSettings) validateFlags() { minServerPort, maxServerPort, settings.MetricsPort) flagsValid = false } + if settings.FileCollectorEnabled && settings.FileCollectorPath == "" { + fmt.Printf("file collector directory must not be empty if collector enabled\n") + flagsValid = false + } } if !flagsValid { flag.Usage()