Repository navigation
feat: Grafana alerts, Loki logs, and bearer auth for Alertmanager - #101
Merged
Merged
Conversation
Alertmanager cannot HMAC-sign webhook bodies, so with WEBHOOK_SECRET set it was always rejected with 401. /webhook/alertmanager now also accepts `Authorization: Bearer <WEBHOOK_SECRET>`, which Alertmanager sends via http_config.authorization. Add /webhook/grafana for Grafana Alerting webhook contact points (bearer or HMAC auth). Firing alerts become incidents with dashboard/panel/runbook URLs. Add Loki log retrieval through Grafana's datasource proxy (GRAFANA_LOKI_DATASOURCE_UID) or directly (LOKI_URL): - Alerts from Grafana/Alertmanager get recent error lines attached as alert_logs before diagnosis (selector from alert labels, or a `logql` annotation; window starts 15 min before the alert, capped at 24h). - New read-only query_logs tool (LogQL) counts as grounding evidence. - System prompt tells the agent to use the logs when a provider is set. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Step-by-step setup for Alertmanager and Grafana alert intake, Loki log fetching, testing with curl, how log selectors are chosen, the logql annotation, and troubleshooting. Linked from the docs nav, docs home and README. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fix: Alertmanager was always rejected when
WEBHOOK_SECRETis set./webhook/alertmanageronly accepted an HMAC signature of the request body, which Alertmanager can't produce. It can only send a fixed bearer token or basic auth. So with a secret configured, every Alertmanager delivery got a 401, and the README example only worked with auth turned off. The endpoint now also acceptsAuthorization: Bearer <WEBHOOK_SECRET>, compared in constant time like the GitLab token.New: Grafana alerts in, Loki logs to the agent.
POST /webhook/grafanareceives Grafana Alerting webhook contact points (bearer token or HMAC). Each firing alert becomes an incident that includesdashboard_url,panel_url,runbook_url,alert_valuesandstarts_at. It shares one alert-to-incident helper with the Alertmanager endpoint.GRAFANA_URL+GRAFANA_TOKEN+ newGRAFANA_LOKI_DATASOURCE_UID) or directly (LOKI_URL,LOKI_TOKEN).alert_logs. These are up to 100 error-like lines, starting 15 minutes before the alert fired, with the window capped at 24 hours. The query is built from the alert'snamespace/pod,job,apporservicelabels. Alogqlannotation on the alert rule overrides it.query_logstool (LogQL), so the agent can widen the time window or check neighbouring services. It counts as grounding evidence.alert_logsfirst and quote the log lines that support its root cause.AUTO_APPLY, approval and emergency-stop rules. Fetching logs never blocks an incident: on error, the incident proceeds without logs.Type of Change
Platform/Component
Testing
tests/test_grafana_alerts_logs.py, 34 tests)Basic401logqlannotation,X-Org-IDalert_logsattached; a log failure doesn't block the incident;query_logsdispatch; prompt hint only when configuredflake8 --select=E9,F63,F7,F82: 0;bandit -llon changed files: no issuesSetup
Grafana: Contact point → Webhook →
https://agent/webhook/grafana, Authorization HeaderBearer/WEBHOOK_SECRET. Then setGRAFANA_LOKI_DATASOURCE_UID.Breaking Changes
None. HMAC signatures still work on both endpoints.
🤖 Generated with Claude Code