You've already forked prometheus-fail2ban-exporter
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.
This commit is contained in:
@ -12,9 +12,10 @@ const (
|
||||
)
|
||||
|
||||
type AppSettings struct {
|
||||
VersionMode bool
|
||||
MetricsPort int
|
||||
Fail2BanDbPath string
|
||||
VersionMode bool
|
||||
MetricsPort int
|
||||
Fail2BanDbPath string
|
||||
Fail2BanSocketPath string
|
||||
}
|
||||
|
||||
func Parse() *AppSettings {
|
||||
@ -22,6 +23,7 @@ func Parse() *AppSettings {
|
||||
flag.BoolVar(&appSettings.VersionMode, "version", false, "show version info and exit")
|
||||
flag.IntVar(&appSettings.MetricsPort, "port", 9191, "port to use for the metrics server")
|
||||
flag.StringVar(&appSettings.Fail2BanDbPath, "db", "", "path to the fail2ban sqlite database")
|
||||
flag.StringVar(&appSettings.Fail2BanSocketPath, "socket", "", "path to the fail2ban server socket")
|
||||
|
||||
flag.Parse()
|
||||
appSettings.validateFlags()
|
||||
@ -31,8 +33,8 @@ func Parse() *AppSettings {
|
||||
func (settings *AppSettings) validateFlags() {
|
||||
var flagsValid = true
|
||||
if !settings.VersionMode {
|
||||
if settings.Fail2BanDbPath == "" {
|
||||
fmt.Println("missing flag 'db'")
|
||||
if settings.Fail2BanDbPath == "" && settings.Fail2BanSocketPath == "" {
|
||||
fmt.Println("at least one of the following flags must be provided: 'db', 'socket'")
|
||||
flagsValid = false
|
||||
}
|
||||
if settings.MetricsPort < minServerPort || settings.MetricsPort > maxServerPort {
|
||||
|
Reference in New Issue
Block a user