2021-02-05 22:49:47 +00:00
|
|
|
package main
|
|
|
|
|
2021-02-05 23:01:00 +00:00
|
|
|
import (
|
2021-02-06 15:17:35 +00:00
|
|
|
"fail2ban-prometheus-exporter/cfg"
|
2021-09-13 19:25:54 +00:00
|
|
|
"fail2ban-prometheus-exporter/export"
|
2021-02-06 15:17:35 +00:00
|
|
|
"fmt"
|
2021-08-29 11:50:53 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2021-02-06 11:45:46 +00:00
|
|
|
_ "github.com/mattn/go-sqlite3"
|
2021-02-05 23:01:00 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
)
|
|
|
|
|
2021-02-06 11:45:46 +00:00
|
|
|
var (
|
2021-02-06 15:17:35 +00:00
|
|
|
version = "dev"
|
|
|
|
commit = "none"
|
|
|
|
date = "unknown"
|
|
|
|
builtBy = "unknown"
|
2021-02-05 23:01:00 +00:00
|
|
|
)
|
|
|
|
|
2021-02-06 15:17:35 +00: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 22:49:47 +00:00
|
|
|
func main() {
|
2021-02-06 15:17:35 +00:00
|
|
|
appSettings := cfg.Parse()
|
|
|
|
if appSettings.VersionMode {
|
|
|
|
printAppVersion()
|
|
|
|
} else {
|
|
|
|
log.Print("starting fail2ban exporter")
|
2021-02-05 23:01:00 +00:00
|
|
|
|
2021-09-13 19:25:54 +00:00
|
|
|
exporter := export.NewExporter(appSettings, version)
|
2021-02-06 15:17:35 +00:00
|
|
|
prometheus.MustRegister(exporter)
|
2021-02-05 23:01:00 +00:00
|
|
|
|
2021-02-06 15:17:35 +00:00
|
|
|
http.Handle("/metrics", promhttp.Handler())
|
|
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", appSettings.MetricsPort), nil))
|
|
|
|
}
|
2021-02-05 22:49:47 +00:00
|
|
|
}
|