summaryrefslogtreecommitdiff
path: root/internal/prometheus.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-01-08 22:22:10 +0200
committerPaul Buetow <paul@buetow.org>2026-01-08 22:22:10 +0200
commitd9671ba9c6ba158cd4516626c4627d38d6478110 (patch)
tree715dd6c2f7a4479545ae780bf12fb2cabbea0937 /internal/prometheus.go
parenta10cbd4e27d944464cec88aaf49d8b8c354d26e1 (diff)
Add special handling for Prometheus Watchdog alert
- Treat firing Watchdog as OK status to confirm Alertmanager is working - Treat absent/non-firing Watchdog as CRITICAL to alert on Alertmanager issues - Add comprehensive tests for both scenarios
Diffstat (limited to 'internal/prometheus.go')
-rw-r--r--internal/prometheus.go36
1 files changed, 34 insertions, 2 deletions
diff --git a/internal/prometheus.go b/internal/prometheus.go
index 1c06aaf..c73f1cf 100644
--- a/internal/prometheus.go
+++ b/internal/prometheus.go
@@ -44,12 +44,33 @@ func mergePrometheusAlerts(ctx context.Context, state state, conf config) state
log.Printf("Fetched %d firing alerts from Prometheus host %s", len(alerts), host)
+ // Check if Watchdog alert is firing
+ watchdogFiring := false
+
for _, alert := range alerts {
+ alertname := alert.Labels["alertname"]
+
+ // Special handling for Prometheus Watchdog alert
+ if alertname == "Watchdog" {
+ if alert.State == "firing" {
+ watchdogFiring = true
+ // Watchdog is firing as expected, treat as OK
+ cs := checkResult{
+ name: "Prometheus: Watchdog",
+ output: "OK [none]: Alertmanager is working properly",
+ epoch: time.Now().Unix(),
+ status: nagiosOk,
+ }
+ state.update(cs)
+ }
+ continue
+ }
+
if alert.State != "firing" {
continue
}
- name := fmt.Sprintf("Prometheus: %s", alert.Labels["alertname"])
+ name := fmt.Sprintf("Prometheus: %s", alertname)
severity := alert.Labels["severity"]
description := alert.Annotations["summary"]
if description == "" {
@@ -66,13 +87,24 @@ func mergePrometheusAlerts(ctx context.Context, state state, conf config) state
cs := checkResult{
name: name,
- output: fmt.Sprintf("%s [%s]: %s", alert.Labels["alertname"], severity, description),
+ output: fmt.Sprintf("%s [%s]: %s", alertname, severity, description),
epoch: time.Now().Unix(),
status: status,
}
state.update(cs)
}
+ // If Watchdog is not firing, alert as critical
+ if !watchdogFiring {
+ cs := checkResult{
+ name: "Prometheus: Watchdog",
+ output: "CRITICAL [none]: Watchdog alert is not firing, Alertmanager may not be working",
+ epoch: time.Now().Unix(),
+ status: nagiosCritical,
+ }
+ state.update(cs)
+ }
+
return state
}