Merge pull request #1436 from simonpasquier/fix-wechat-templ
notify: catch templating errors for Wechat
This commit is contained in:
commit
a736a90dd0
|
@ -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 {
|
||||
|
|
|
@ -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
Loading…
Reference in New Issue