https://github.com/kubesphere/notification-manager/tree/release-1.4
cat <<EOF | kubectl apply -f -
apiVersion: notification.kubesphere.io/v2beta1
kind: Config
metadata:
labels:
app: notification-manager
type: tenant
user: quanyang
name: quanyang-email-config
spec:
email:
authPassword:
key: password
name: global-email-config-secret
authUsername: zabbixmonitor
from: zabbixmonitor@ur.com.cn
requireTLS: false
smartHost:
host: smtp.exmail.qq.com
port: 25
---
apiVersion: notification.kubesphere.io/v2beta1
kind: Receiver
metadata:
labels:
app: notification-manager
type: tenant
user: quanyang
name: quanyang-email-receiver
spec:
email:
# This emailConfigSelector could be omitted in which case a defalut EmailConfig should be configured
emailConfigSelector:
matchLabels:
type: tenant
user: quanyang
to:
- quan.yang@ur.com.cn
EOF
[root@ur-scm-master01 ~]# kubectl get receiver
NAME AGE
global-email-receiver 286d
global-wechat-receiver 230d
liweiming-email-receiver 3m21s
quanyang-email-receiver 6s
[root@ur-scm-master01 ~]# kubectl get config
NAME AGE
default-email-config 286d
default-wechat-config 230d
liweiming-email-config 3m26s
quanyang-email-config 11s
[root@ur-scm-master01 ~]#
批量设置不发送某一级别的告警
获取所有receiver
------
kubectl get nr
------
编辑所有receiver,添加alertSelector
------
kubectl edit nr xxxx-xxx-receiver
------
添加
----
spec:
slack:
alertSelectorL
matchExpressions:
-key:severity
operator:In
values:
- xx
- xx
----
详细的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,并发送通知。