Merge branch 'feat/print-fail2ban-version-on-startup' into 'main'
feat: print fail2ban version on startup See merge request hectorjsmith/fail2ban-prometheus-exporter!96
This commit is contained in:
commit
5f879e1921
1 changed files with 19 additions and 3 deletions
|
@ -1,11 +1,12 @@
|
||||||
package f2b
|
package f2b
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg"
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/cfg"
|
||||||
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket"
|
"gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/socket"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
|
@ -18,7 +19,8 @@ type Collector struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collector {
|
func NewExporter(appSettings *cfg.AppSettings, exporterVersion string) *Collector {
|
||||||
log.Printf("reading metrics from fail2ban socket: %s", appSettings.Fail2BanSocketPath)
|
log.Printf("reading fail2ban metrics from socket file: %s", appSettings.Fail2BanSocketPath)
|
||||||
|
printFail2BanServerVersion(appSettings.Fail2BanSocketPath)
|
||||||
return &Collector{
|
return &Collector{
|
||||||
socketPath: appSettings.Fail2BanSocketPath,
|
socketPath: appSettings.Fail2BanSocketPath,
|
||||||
exporterVersion: exporterVersion,
|
exporterVersion: exporterVersion,
|
||||||
|
@ -58,3 +60,17 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||||
}
|
}
|
||||||
c.collectErrorCountMetric(ch)
|
c.collectErrorCountMetric(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printFail2BanServerVersion(socketPath string) {
|
||||||
|
s, err := socket.ConnectToSocket(socketPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error connecting to socket: %v", err)
|
||||||
|
} else {
|
||||||
|
version, err := s.GetServerVersion()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error interacting with socket: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Printf("successfully connected to fail2ban socket! fail2ban version: %s", version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue