Correctly encode query strings in notifiers (#1516)

In moving from a plain string to url.URL, we
incorrectly were setting the query string via the
path. The `?` signaling the start of the query
string would then be escaped when the URL was
turned into a string.

Signed-off-by: Stuart Nelson <stuartnelson3@gmail.com>
This commit is contained in:
stuart nelson 2018-08-13 13:33:51 +02:00 committed by Max Leonard Inden
parent b3c62aa459
commit 1f3d7572cb
No known key found for this signature in database
GPG Key ID: 5403C5464810BC26
1 changed files with 12 additions and 3 deletions

View File

@ -805,7 +805,10 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
roomid = tmplText(n.conf.RoomID) roomid = tmplText(n.conf.RoomID)
apiURL = n.conf.APIURL.Copy() apiURL = n.conf.APIURL.Copy()
) )
apiURL.Path += fmt.Sprintf("v2/room/%s/notification?auth_token=%s", roomid, n.conf.AuthToken) apiURL.Path += fmt.Sprintf("v2/room/%s/notification", roomid)
q := apiURL.Query()
q.Set("auth_token", fmt.Sprintf("%s", n.conf.AuthToken))
apiURL.RawQuery = q.Encode()
if n.conf.MessageFormat == "html" { if n.conf.MessageFormat == "html" {
msg = tmplHTML(n.conf.Message) msg = tmplHTML(n.conf.Message)
@ -976,7 +979,10 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
} }
postMessageURL := n.conf.APIURL.Copy() postMessageURL := n.conf.APIURL.Copy()
postMessageURL.Path += "message/send?access_token=" + n.accessToken postMessageURL.Path += "message/send"
q := postMessageURL.Query()
q.Set("access_token", n.accessToken)
postMessageURL.RawQuery = q.Encode()
req, err := http.NewRequest(http.MethodPost, postMessageURL.String(), &buf) req, err := http.NewRequest(http.MethodPost, postMessageURL.String(), &buf)
if err != nil { if err != nil {
@ -1106,7 +1112,10 @@ func (n *OpsGenie) createRequest(ctx context.Context, as ...*types.Alert) (*http
) )
switch alerts.Status() { switch alerts.Status() {
case model.AlertResolved: case model.AlertResolved:
apiURL.Path += fmt.Sprintf("v2/alerts/%s/close?identifierType=alias", alias) apiURL.Path += fmt.Sprintf("v2/alerts/%s/close", alias)
q := apiURL.Query()
q.Set("identifierType", "alias")
apiURL.RawQuery = q.Encode()
msg = &opsGenieCloseMessage{Source: tmpl(n.conf.Source)} msg = &opsGenieCloseMessage{Source: tmpl(n.conf.Source)}
default: default:
message := tmpl(n.conf.Message) message := tmpl(n.conf.Message)