Merge pull request #1436 from simonpasquier/fix-wechat-templ

notify: catch templating errors for Wechat
This commit is contained in:
Max Inden 2018-07-05 14:52:16 +02:00 committed by GitHub
commit a736a90dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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