Allow slashes in receivers (#2011)

* do not split receiver by slash

I'm not sure why this was originally done, because a slash seems to be perfectly
valid in a receiver definition. The only issue i encountered was that linking
from a fired alert was not working, because of the splitting performed here.

Signed-off-by: Tim Reddehase <tim.reddehase@xing.com>

* urlquery escape Receiver by default for URL

If Receiver is allowed to contain slashes and other special characters
we need to percent encode them properly.

Signed-off-by: Tim Reddehase <tim.reddehase@xing.com>

* rerun make asset/assets_vfsdata.go

Signed-off-by: Tim Reddehase <tim.reddehase@xing.com>
This commit is contained in:
Tim Reddehase 2019-08-28 10:01:47 +02:00 committed by Simon Pasquier
parent a1c04ee956
commit d517f786ef
3 changed files with 4 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{{ define "__alertmanager" }}AlertManager{{ end }}
{{ define "__alertmanagerURL" }}{{ .ExternalURL }}/#/alerts?receiver={{ .Receiver }}{{ end }}
{{ define "__alertmanagerURL" }}{{ .ExternalURL }}/#/alerts?receiver={{ .Receiver | urlquery }}{{ end }}
{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
{{ define "__description" }}{{ end }}

View File

@ -276,7 +276,7 @@ func (as Alerts) Resolved() []Alert {
// Data assembles data for template expansion.
func (t *Template) Data(recv string, groupLabels model.LabelSet, alerts ...*types.Alert) *Data {
data := &Data{
Receiver: regexp.QuoteMeta(strings.SplitN(recv, "/", 2)[0]),
Receiver: regexp.QuoteMeta(recv),
Status: string(types.Alerts(alerts...).Status()),
Alerts: make(Alerts, 0, len(alerts)),
GroupLabels: KV{},