notify: catch templating errors for Wechat
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
5e86f61bd7
commit
d188c21fb0
|
@ -875,6 +875,9 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
|
||||||
parameters := url.Values{}
|
parameters := url.Values{}
|
||||||
parameters.Add("corpsecret", tmpl(string(n.conf.APISecret)))
|
parameters.Add("corpsecret", tmpl(string(n.conf.APISecret)))
|
||||||
parameters.Add("corpid", tmpl(string(n.conf.CorpID)))
|
parameters.Add("corpid", tmpl(string(n.conf.CorpID)))
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("templating error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
apiURL := n.conf.APIURL + "gettoken"
|
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()
|
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)
|
req, err := http.NewRequest(http.MethodGet, u.String(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return true, err
|
return true, err
|
||||||
|
@ -925,6 +926,9 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
|
||||||
Type: "text",
|
Type: "text",
|
||||||
Safe: "0",
|
Safe: "0",
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("templating error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
if err := json.NewEncoder(&buf).Encode(msg); err != nil {
|
if err := json.NewEncoder(&buf).Encode(msg); err != nil {
|
||||||
|
|
|
@ -60,6 +60,11 @@ Alerts Resolved:
|
||||||
AlertmanagerUrl:
|
AlertmanagerUrl:
|
||||||
{{ template "__alertmanagerURL" . }}
|
{{ template "__alertmanagerURL" . }}
|
||||||
{{- end }}
|
{{- 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