Skip to content

Commit

Permalink
Correctly encode query strings in notifiers (prometheus#1516)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stuartnelson3 authored Aug 13, 2018
1 parent 2c00f06 commit f8b95a2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions notify/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,10 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
roomid = tmplText(n.conf.RoomID)
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" {
msg = tmplHTML(n.conf.Message)
Expand Down Expand Up @@ -976,7 +979,10 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
}

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)
if err != nil {
Expand Down Expand Up @@ -1106,7 +1112,10 @@ func (n *OpsGenie) createRequest(ctx context.Context, as ...*types.Alert) (*http
)
switch alerts.Status() {
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)}
default:
message := tmpl(n.conf.Message)
Expand Down

0 comments on commit f8b95a2

Please sign in to comment.