Skip to content

Commit

Permalink
bugfix: support target parameter for prometheus (#1)
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
cngJo committed Aug 2, 2022
1 parent e0b1fa0 commit 27b5046
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 27b5046

Please sign in to comment.