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 }}
On Tuesday, May 16, 2023 at 3:08:07 PM UTC+2 Julio Leal wrote:
> 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?
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/prometheus-users/cf08fc4e-7331-46ca-b721-9bfab1ae4ce2n%40googlegroups.com.