Edit GeneratorURL

24 views
Skip to first unread message

Julio Leal

unread,
May 17, 2023, 5:08:30 PM5/17/23
to Prometheus Developers
Hi folks, how are you?
We need to manipulate the .GeneratorURL.
For example:
.GeneratorURL: https://<prometheus_url>/graph?g0.expr=count%28up%29+%3E+0+and+on+%28%29+%28is_metrics_platform_up+%3D%3D+1%29&g0.tab=1

I need to remove: +and+on+%28%29+%28is_metrics_platform_up+%3D%3D+1%29

In the real world, I could get each parameter, decode it, remove the suffix and encode again to generate a new GeneratorURL, but in the alertmanager template I do not know how to do this.
The only way to that I found, is 

{{ define "prometheus.url" -}}
{{if eq .GroupLabels.env "prod" }}
{{ (index .Alerts 0).GeneratorURL | reReplaceAll "\\+and\\+on\\+%28%29\\+%28is_metrics_platform_up\\+%3D%3D\\+1%29" "" }}
{{ else }}
{{ (index .Alerts 0).GeneratorURL }}{{ end }}{{ end }}

{"caller":"dispatch.go:354","component":"dispatcher","err":"ream_slack/slack[0]: notify retry canceled due to unrecoverable error after 1 attempts: template: service.tmpl:13:4: executing \"prometheus.url\" at <index .Alerts 0>: error calling index: index of untyped nil","level":"error","msg":"Notify for alerts failed","num_alerts":1,"ts":"2023-05-17T21:00:09.541Z"}


I do not know how to remove this part of the URL, someone can help me?
Reply all
Reply to author
Forward
0 new messages