From 84b9d020681052210647ee8847f6c9b88f1cdffe Mon Sep 17 00:00:00 2001 From: Hector Date: Sat, 25 Sep 2021 21:23:28 +0000 Subject: [PATCH] feat: render basic html page at root url Add a new request handler for the root URL (`/`) to render a simple HTML page with a link to the metrics page. This follows the convention of other metric exporters. --- src/exporter.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/exporter.go b/src/exporter.go index 6cc8793..b06ca2c 100644 --- a/src/exporter.go +++ b/src/exporter.go @@ -28,6 +28,21 @@ func printAppVersion() { fmt.Printf(" build date: %s\r\n commit hash: %s\r\n built by: %s\r\n", date, commit, builtBy) } +func rootHtmlHandler(w http.ResponseWriter, r *http.Request) { + _, err := w.Write([]byte( + ` + Fail2Ban Exporter + +

Fail2Ban Exporter

+

Metrics

+ + `)) + if err != nil { + log.Printf("error handling root url: %v", err) + w.WriteHeader(http.StatusInternalServerError) + } +} + func main() { appSettings := cfg.Parse() if appSettings.VersionMode { @@ -40,6 +55,7 @@ func main() { exporter := export.NewExporter(appSettings, version) prometheus.MustRegister(exporter) + http.HandleFunc("/", rootHtmlHandler) http.Handle(metricsPath, promhttp.Handler()) log.Printf("metrics available at '%s'", metricsPath)