https://github.com/kubesphere/notification-manager/tree/release-1.4

    1. cat <<EOF | kubectl apply -f -
    2. apiVersion: notification.kubesphere.io/v2beta1
    3. kind: Config
    4. metadata:
    5. labels:
    6. app: notification-manager
    7. type: tenant
    8. user: quanyang
    9. name: quanyang-email-config
    10. spec:
    11. email:
    12. authPassword:
    13. key: password
    14. name: global-email-config-secret
    15. authUsername: zabbixmonitor
    16. from: zabbixmonitor@ur.com.cn
    17. requireTLS: false
    18. smartHost:
    19. host: smtp.exmail.qq.com
    20. port: 25
    21. ---
    22. apiVersion: notification.kubesphere.io/v2beta1
    23. kind: Receiver
    24. metadata:
    25. labels:
    26. app: notification-manager
    27. type: tenant
    28. user: quanyang
    29. name: quanyang-email-receiver
    30. spec:
    31. email:
    32. # This emailConfigSelector could be omitted in which case a defalut EmailConfig should be configured
    33. emailConfigSelector:
    34. matchLabels:
    35. type: tenant
    36. user: quanyang
    37. to:
    38. - quan.yang@ur.com.cn
    39. EOF
    1. [root@ur-scm-master01 ~]# kubectl get receiver
    2. NAME AGE
    3. global-email-receiver 286d
    4. global-wechat-receiver 230d
    5. liweiming-email-receiver 3m21s
    6. quanyang-email-receiver 6s
    7. [root@ur-scm-master01 ~]# kubectl get config
    8. NAME AGE
    9. default-email-config 286d
    10. default-wechat-config 230d
    11. liweiming-email-config 3m26s
    12. quanyang-email-config 11s
    13. [root@ur-scm-master01 ~]#

    批量设置不发送某一级别的告警
    获取所有receiver

    1. ------
    2. kubectl get nr
    3. ------
    4. 编辑所有receiver,添加alertSelector
    5. ------
    6. kubectl edit nr xxxx-xxx-receiver
    7. ------
    8. 添加
    9. ----
    10. spec:
    11. slack:
    12. alertSelectorL
    13. matchExpressions:
    14. -key:severity
    15. operator:In
    16. values:
    17. - xx
    18. - xx
    19. ----

    详细的api文档可以参考
    https://github.com/kubesphere/notification-manager/tree/release-1.0/pkg/apis/v2beta1

    Q:设置租户级别的告警通知

    A:在ks中创建用户,也可以使用已存在的用户,邀请用户到相应的项目下,例如用户user1需要接收项目test1下的通知,则需邀请user1到项目test1下。同一用户可以同时接收多个项目的通知。
    创建receiver和config,以邮件通知为例

    apiVersion: notification.kubesphere.io/v2beta1
    kind: Config
    metadata:
    labels:
    type: tenant # 红色部分
    user: user1 # 红色部分
    name: user1-email-config
    spec:
    email:
    authPassword:
    key: password
    name: default-email-secret
    authUsername: sender1
    from: sender1@xyz.com
    requireTLS: true
    smartHost:
    host: imap.xyz.com
    port: 25

    apiVersion: notification.kubesphere.io/v2beta1
    kind: Receiver
    metadata:
    labels:
    type: tenant # 红色部分
    user: user1 # 红色部分
    name: user1-email-receiver
    spec:
    email:
    enabled: true
    emailConfigSelector:
    matchLabels:
    type: tenant
    user: user1
    to:

    PS: 红色部分为必填项,不同的用户需要对应修改user字段。
    PS:emailConfigSelector为可选项,如果emailConfigSelector未配置,则receiver会使用全局的邮件配置(default-email-config)来发送邮件
    PS:default-email-secret是存储email账户密码的密钥,需要手动创建。

    apiVersion: v1
    data:
    password: dGVzdA==
    kind: Secret
    metadata:
    name: default-email-secret
    namespace: kubesphere-monitoring-federated
    type: Opaque

    默认情况下密钥需要创建在kubesphere-monitoring-federated下,如果需要创建在其他的项目下,需修改config,在authPassword下增加namespace字段,指定密钥所在项目。

    spec:
    email:
    authPassword:
    key: password
    name: default-email-secret
    namespace: ns

    PS:其他通知渠道的配置可以参考
    https://github.com/kubesphere/notification-manager#quickstart

    PS:项目下产生的通知会有一个名为为namespace的标签,这个标签的值是产生通知的项目。通知模块会根据这个标签获取项目名称,并获取此项目下的所有用户,receiver会通过标签user与用户绑定,据此,通知模块就会获得所有需要通知的receiver,并发送通知。