alertmanager
alertmanager copied to clipboard
Fix wechat secret may contain newlines
Because the secret key contains a newline symbol, an error is reported.
SETP1:
apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
annotations:
labels:
kind: wechat
name: cert-manager
namespace: cert-manager
spec:
receivers:
- name: wechat
wechatConfigs:
- agentID: "1000002"
apiSecret:
key: apiSecret
name: wechat-config
apiURL: https://qyapi.weixin.qq.com/cgi-bin/
corpID: xxxxxxxxxxxxx
message: |
{{ range .Alerts }}
## {{ .Labels.alertname }}
> {{ .Annotations.message_zh }}
{{ end }}
messageType: markdown
toUser: '@all'
route:
groupBy:
- job
groupInterval: 30s
groupWait: 5s
receiver: wechat
repeatInterval: 30s
---
apiVersion: v1
data:
apiSecret: base64-key
kind: Secret
metadata:
name: wechat-config
namespace: cert-manager
STEP2: got alertmanager error
ts=2022-07-25T04:38:20.733Z caller=dispatch.go:354 level=error component=dispatcher msg="Notify for alerts failed" num_alerts=1 err="cert-manager/cert-manager/wechat/wechat[0]: notify retry canceled due to unrecoverable error after 1 attempts: invalid APISecret for CorpID: ww3d7aec086c171405"
ping @roidelapluie
ping @simonpasquier
@juliusv ping
Thanks for the PR. Can you add a unit test? I'm also wondering whether
corpidwould need the same treatment?
I'll add the test later, but corp id won't, because he didn't add it from secret.