Edit .GeneratorURL

188 views
Skip to first unread message

Julio Leal

unread,
May 16, 2023, 9:08:07 AM5/16/23
to Prometheus Users
Hi folks, how are you?
We need to manipulate the .GeneratorURL.
For example:
.GeneratorURL: https://<prometheus_url>/graph?g0.expr=(sum(up))%20and%20on()%20(is_metrics_platform_up%20%3D%3D%201)&g0.tab=1&g0.stacked=0&g0.show_exemplars=0&g0.range_input=1h

I need to remove: %20and%20on()%20(is_metrics_platform_up%20%3D%3D%201)

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 "url" -}}
{{if and (eq .GroupLabels.env "prod") (contains (index .Alerts 0).GeneratorURL "is_metrics_platform_up") }}
{{js (index .Alerts 0).GeneratorURL | reReplaceAll "%20and%20on()%20(is_metrics_platform_up%20%3D%3D%201)" "" }}
{{ else }}
{{ (index .Alerts 0).GeneratorURL }}{{ end }}{{ end }}

Is there a way to do this more elegant?


Tomáš

unread,
Jan 2, 2025, 10:16:08 AM1/2/25
to Prometheus Users
I'm not sure, but this looks more elegant. What do you think?

{{ define "sanitizeURL" }}
  {{- $url := . -}}
  {{- if contains $url "is_metrics_platform_up" -}}
    {{ reReplaceAll "%20and%20on()%20(is_metrics_platform_up%20%3D%3D%201)" "" $url }}
  {{- else -}}
    {{ $url }}
  {{- end -}}
{{ end }}


{{ define "url" }}
  {{- if and (eq .GroupLabels.env "prod") }}
    {{ template "sanitizeURL" (index .Alerts 0).GeneratorURL }}
  {{- else -}}
    {{ (index .Alerts 0).GeneratorURL }}
  {{- end -}}
{{ end }}

Reply all
Reply to author
Forward
0 new messages