notify: catch templating errors for Wechat

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2018-06-24 14:02:21 +02:00
parent 5e86f61bd7
commit d188c21fb0
3 changed files with 13 additions and 4 deletions

View File

@ -875,6 +875,9 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
parameters := url.Values{}
parameters.Add("corpsecret", tmpl(string(n.conf.APISecret)))
parameters.Add("corpid", tmpl(string(n.conf.CorpID)))
if err != nil {
return false, fmt.Errorf("templating error: %s", err)
}
apiURL := n.conf.APIURL + "gettoken"
@ -885,8 +888,6 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
u.RawQuery = parameters.Encode()
level.Debug(n.logger).Log("msg", "Sending Wechat message", "incident", key, "url", u.String())
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
if err != nil {
return true, err
@ -925,6 +926,9 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
Type: "text",
Safe: "0",
}
if err != nil {
return false, fmt.Errorf("templating error: %s", err)
}
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(msg); err != nil {

View File

@ -60,6 +60,11 @@ Alerts Resolved:
AlertmanagerUrl:
{{ template "__alertmanagerURL" . }}
{{- end }}
{{ define "wechat.default.api_secret" }}{{ end }}
{{ define "wechat.default.to_user" }}{{ end }}
{{ define "wechat.default.to_party" }}{{ end }}
{{ define "wechat.default.to_tag" }}{{ end }}
{{ define "wechat.default.agent_id" }}{{ end }}

File diff suppressed because one or more lines are too long