2021-02-05 23:49:47 +01:00
|
|
|
package main
|
|
|
|
|
2021-02-06 00:01:00 +01:00
|
|
|
import (
|
2021-02-06 16:17:35 +01:00
|
|
|
"fail2ban-prometheus-exporter/cfg"
|
2021-09-13 21:25:54 +02:00
|
|
|
"fail2ban-prometheus-exporter/export"
|
2021-02-06 16:17:35 +01:00
|
|
|
"fmt"
|
2021-08-29 13:50:53 +02:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2021-02-06 12:45:46 +01:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2021-02-06 00:01:00 +01:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
)
|
|
|
|
|
2021-02-06 12:45:46 +01:00
|
|
|
var (
|
2021-02-06 16:17:35 +01:00
|
|
|
version = "dev"
|
|
|
|
commit = "none"
|
|
|
|
date = "unknown"
|
|
|
|
builtBy = "unknown"
|
2021-02-06 00:01:00 +01:00
|
|
|
)
|
|
|
|
|
2021-02-06 16:17:35 +01:00
|
|
|
func printAppVersion() {
|
|
|
|
fmt.Println(version)
|
|
|
|
fmt.Printf(" build date: %s\r\n commit hash: %s\r\n built by: %s\r\n", date, commit, builtBy)
|
|
|
|
}
|
|
|
|
|
2021-02-05 23:49:47 +01:00
|
|
|
func main() {
|
2021-02-06 16:17:35 +01:00
|
|
|
appSettings := cfg.Parse()
|
|
|
|
if appSettings.VersionMode {
|
|
|
|
printAppVersion()
|
|
|
|
} else {
|
|
|
|
log.Print("starting fail2ban exporter")
|
2021-02-06 00:01:00 +01:00
|
|
|
|
2021-09-13 21:25:54 +02:00
|
|
|
exporter := export.NewExporter(appSettings, version)
|
2021-02-06 16:17:35 +01:00
|
|
|
prometheus.MustRegister(exporter)
|
2021-02-06 00:01:00 +01:00
|
|
|
|
2021-02-06 16:17:35 +01:00
|
|
|
http.Handle("/metrics", promhttp.Handler())
|
|
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appSettings.MetricsPort), nil))
|
|
|
|
}
|
2021-02-05 23:49:47 +01:00
|
|
|
}
|