alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Fix wechat secret may contain newlines

Open lou-lan opened this issue 3 years ago • 4 comments

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"

lou-lan avatar Jul 14 '22 03:07 lou-lan

ping @roidelapluie

lou-lan avatar Jul 25 '22 02:07 lou-lan

ping @simonpasquier

lou-lan avatar Jul 25 '22 04:07 lou-lan

@juliusv ping

lou-lan avatar Jul 26 '22 11:07 lou-lan

Thanks for the PR. Can you add a unit test? I'm also wondering whether corpid would need the same treatment?

I'll add the test later, but corp id won't, because he didn't add it from secret.

lou-lan avatar Aug 06 '22 05:08 lou-lan