From 27b50461dc0d629928b71ea00ec90f7c5b9364c1 Mon Sep 17 00:00:00 2001 From: Johannes Przymusinski Date: Tue, 2 Aug 2022 22:24:21 +0200 Subject: [PATCH] bugfix: support target parameter for prometheus (#1) Fixes #1 --- README.md | 2 +- main.go | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1fe8640..9b96c56 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ IMAP_PASSWORD="" ### Probe ```txt -http://127.0.0.1:9101/probe?mailbox=INBOX +http://127.0.0.1:9101/probe?target=INBOX ``` ### Provided metrics diff --git a/main.go b/main.go index 35cb16c..cd7c280 100644 --- a/main.go +++ b/main.go @@ -81,12 +81,18 @@ func main() { }) http.HandleFunc("/probe", func(w http.ResponseWriter, r *http.Request) { - mailbox := r.URL.Query().Get("mailbox") - if mailbox == "" { - http.Error(w, "Mailbox parameter is missing", http.StatusBadRequest) - return + // Maily use the target parameter, but support mailbox as a fallback. + target := r.URL.Query().Get("target") + if target == "" { + target = r.URL.Query().Get("mailbox") + if target == "" { + http.Error(w, "Mailbox parameter is missing", http.StatusBadRequest) + return + } } + mailbox := target + probeCountGauge := prometheus.NewGauge(prometheus.GaugeOpts{ Name: "probe_mailbox_count", Help: "Displays the count of mails found in the mailbox",