mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-12-29 06:12:51 +01:00
Add Path/Query Escape functions
Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
parent
c07a4e5288
commit
60b1c5eb64
@ -18,6 +18,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ func NewFormatter(config *Config) (*Formatter, error) {
|
|||||||
"ToUpper": strings.ToUpper,
|
"ToUpper": strings.ToUpper,
|
||||||
"ToLower": strings.ToLower,
|
"ToLower": strings.ToLower,
|
||||||
"Join": strings.Join,
|
"Join": strings.Join,
|
||||||
|
|
||||||
|
"QueryEscape": url.QueryEscape,
|
||||||
|
"PathEscape": url.PathEscape,
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpl, err := template.New("msg").Funcs(funcMap).Parse(config.MsgTemplate)
|
tmpl, err := template.New("msg").Funcs(funcMap).Parse(config.MsgTemplate)
|
||||||
|
@ -90,3 +90,22 @@ func TestStringsFunctions(t *testing.T) {
|
|||||||
|
|
||||||
CreateFormatterAndCheckOutput(t, &testingConfig, expectedAlertMsgs)
|
CreateFormatterAndCheckOutput(t, &testingConfig, expectedAlertMsgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUrlFunctions(t *testing.T) {
|
||||||
|
testingConfig := Config{
|
||||||
|
MsgTemplate: "{{ .Annotations.SUMMARY | PathEscape }}",
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedAlertMsgs := []AlertMsg{
|
||||||
|
AlertMsg{
|
||||||
|
Channel: "#somechannel",
|
||||||
|
Alert: "service%20%2Fprometheus%20air%20down%20on%20instance1",
|
||||||
|
},
|
||||||
|
AlertMsg{
|
||||||
|
Channel: "#somechannel",
|
||||||
|
Alert: "service%20%2Fprometheus%20air%20down%20on%20instance2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
CreateFormatterAndCheckOutput(t, &testingConfig, expectedAlertMsgs)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user