From 8ba5be765c670f404235c54d0e67c9fe040897ea Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sat, 17 Oct 2026 19:19:21 +0800 Subject: [PATCH] fix(monitoring): repair alert source link and template fallback The Explore link named a datasource that does not exist, and rules without an alertgroup label rendered an empty value. Assisted-by: DeepSeek Harness (deepseek-flash) --- .../12kingdoms-youko/homelab-services/monitoring/alert.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hosts/12kingdoms-youko/homelab-services/monitoring/alert.nix b/hosts/12kingdoms-youko/homelab-services/monitoring/alert.nix index fa2c49c4..912ed747 100644 --- a/hosts/12kingdoms-youko/homelab-services/monitoring/alert.nix +++ b/hosts/12kingdoms-youko/homelab-services/monitoring/alert.nix @@ -27,8 +27,10 @@ # https://docs.victoriametrics.com/victoriametrics/vmalert/#link-to-alert-source # Set this two args to generate the correct `.GeneratorURL` "external.url" = "https://grafana.writefor.fun"; + # Grafana resolves this by UID, then by name; it must match the provisioned + # datasource name in grafana/datasources.nix. "external.alert.source" = - ''explore?left={"datasource":"{{ if eq .Type \"vlogs\" }}VictoriaLogs{{ else }}VictoriaMetrics{{ end }}","queries":[{"expr":{{ .Expr|jsonEscape|queryEscape }},"refId":"A"}],"range":{"from":"{{ .ActiveAt.UnixMilli }}","to":"now"}}''; + ''explore?left={"datasource":"victoriametrics-homelab","queries":[{"expr":{{ .Expr|jsonEscape|queryEscape }},"refId":"A"}],"range":{"from":"{{ .ActiveAt.UnixMilli }}","to":"now"}}''; }; }; @@ -141,7 +143,7 @@ 🟢 告警恢复 [{{ .CommonLabels.severity | title }}] {{ .CommonLabels.alertname }} {{- end }} - • 告警组: {{ .CommonLabels.alertgroup }} + • 告警组: {{ with .CommonLabels.alertgroup }}{{ . }}{{ else }}N/A{{ end }} • Cluster: {{ with .CommonLabels.cluster }}{{ . }}{{ else }}N/A{{ end }} • Env: {{ with .CommonLabels.env }}{{ . }}{{ else }}N/A{{ end }} • Namespace: {{ with .CommonLabels.namespace }}{{ . }}{{ else }}N/A{{ end }}