mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-12-27 21:32:46 +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"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/url"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@ -34,6 +35,9 @@ func NewFormatter(config *Config) (*Formatter, error) {
|
||||
"ToUpper": strings.ToUpper,
|
||||
"ToLower": strings.ToLower,
|
||||
"Join": strings.Join,
|
||||
|
||||
"QueryEscape": url.QueryEscape,
|
||||
"PathEscape": url.PathEscape,
|
||||
}
|
||||
|
||||
tmpl, err := template.New("msg").Funcs(funcMap).Parse(config.MsgTemplate)
|
||||
|
@ -90,3 +90,22 @@ func TestStringsFunctions(t *testing.T) {
|
||||
|
||||
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