-
Notifications
You must be signed in to change notification settings - Fork 149
Description
Currently, Promxy generates hardcoded Prometheus-style GeneratorURLs for alerts, limiting integration with third-party alert UIs and workflows.
What's Missing with the Current Behavior?
-
Integration with Alerting UIs
- Users might want to land on pages of other alert presentation and management software such as grafana alerting dashboards, alerts, other solutions
- URLs cannot be customized based on context (labels like severity, team, or annotations).
-
Hardcoded Implementation Limitations
- GeneratorURL is hardcoded in
sendAlertsfunction - No configuration options available
- GeneratorURL is hardcoded in
Proposed Solution
Enable configurable Go templates for generatorURL: Support templates via CLI, config file, or external directory/file, and choose templates via alert labels/annotations.
Use Cases
-
Grafana Integration
Direct users to specific alert in Grafana alerting interface
https://grafana.example.com/alerting/groups?queryString=alertname%3D"{{.AlertName}}"%20cluster%3D"{{.Labels.cluster}}" -
Incident Management Integration
Route critical alerts directly to IRM systems
https://company.pagerduty.com/incidents/new?alert={{.AlertName}}&severity={{.Labels.severity}} https://grafana.example.com/d/cpu-dashboard?var-instance={{.Labels.instance}}
-
Multi-Tenant Environments
Route alerts to tenant-specific dashboards
# URL includes tenant context https://{{.Labels.tenant}}.grafana.company.com/alerting/groups?alert={{.AlertName}}
Implementation Details
Configuration Structure (example)
promxy:
alert_templates:
# Default template used when no rules match
default: "{{.ExternalURL}}/graph?g0.expr={{.Expr|urlquery}}&g0.tab=1"
# Directory containing template files (*.tmpl)
directory: "/etc/promxy/templates"
# Named inline templates
named:
grafana: "https://grafana.example.com/d/alerts?alertname={{.AlertName|urlquery}}&severity={{.Labels.severity|urlquery}}"
pagerduty: "https://pagerduty.example.com/incidents/new?title={{.AlertName|urlquery}}&description={{.Annotations.summary|urlquery}}"
custom_dashboard: "https://monitoring.example.com/alerts/{{.AlertName}}?instance={{.Labels.instance|urlpath}}"
# Template selection rules (evaluated top-to-bottom)
rules:
# Critical alerts go to PagerDuty
- match_labels:
severity: "critical"
template: "pagerduty"
# Frontend team alerts go to Grafana
- match_labels:
team: "frontend"
template: "grafana"
# Infrastructure alerts use custom dashboard
- match_labels:
component: "infrastructure"
template: "custom_dashboard"
# Inline template for specific alert
- match_labels:
alertname: "DatabaseDown"
template: "https://db-dashboard.example.com/status?db={{.Labels.database|urlquery}}"
CLI Override Support
promxy --rules.alert.generator-url-template='https://grafana.example.com/alerting/groups?queryString=alertname%3D"{{.AlertName | urlquery}}"'Template Directory
promxy --rules.alert.template-dir=/etc/promxy/templatesTemplate File Support
Templates can be loaded from a directory (template_directory) or specified inline under templates:.
Template selection logic can be driven by alert labels or annotations (template_rules).
Template Variables
type TemplateData struct {
ExternalURL string // Promxy's external URL
Expr string // The PromQL expression that triggered the alert
Labels map[string]string // Alert labels (alertname, instance, etc.)
Annotations map[string]string // Alert annotations (summary, description, etc.)
AlertName string
}Template Functions
- urlquery: URL-encode for query params
- urlpath: URL-encode for path segments
- Standard Go template funcs.
- importing or implementing helpers from Prometheus/VictoriaMetrics (humanize, toUpper, etc.)
Backward Compatibility
If no template is supplied, Promxy continues using the current Prometheus-style GeneratorURL logic.