add feishu support
This commit is contained in:
parent
766bf9e401
commit
6c2c8f9900
|
@ -11,7 +11,8 @@ notify_channel_funcs = {
|
||||||
"sms":"sms",
|
"sms":"sms",
|
||||||
"voice":"voice",
|
"voice":"voice",
|
||||||
"dingtalk":"dingtalk",
|
"dingtalk":"dingtalk",
|
||||||
"wecom":"wecom"
|
"wecom":"wecom",
|
||||||
|
"feishu":"feishu"
|
||||||
}
|
}
|
||||||
|
|
||||||
mail_host = "smtp.163.com"
|
mail_host = "smtp.163.com"
|
||||||
|
@ -118,6 +119,45 @@ class Sender(object):
|
||||||
except urllib2.HTTPError, error:
|
except urllib2.HTTPError, error:
|
||||||
print(error)
|
print(error)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send_feishu(cls, payload):
|
||||||
|
users = payload.get('event').get("notify_users_obj")
|
||||||
|
|
||||||
|
tokens = {}
|
||||||
|
phones = {}
|
||||||
|
|
||||||
|
for u in users:
|
||||||
|
if u.get("phone"):
|
||||||
|
phones[u.get("phone")] = 1
|
||||||
|
|
||||||
|
contacts = u.get("contacts")
|
||||||
|
if contacts.get("feishu_robot_token", ""):
|
||||||
|
tokens[contacts.get("feishu_robot_token", "")] = 1
|
||||||
|
|
||||||
|
opener = urllib2.build_opener(urllib2.HTTPHandler())
|
||||||
|
method = "POST"
|
||||||
|
|
||||||
|
for t in tokens:
|
||||||
|
url = "https://open.feishu.cn/open-apis/bot/v2/hook/{}".format(t)
|
||||||
|
body = {
|
||||||
|
"msg_type": "text",
|
||||||
|
"content": {
|
||||||
|
"text": payload.get('tpls').get("feishu.tpl", "feishu.tpl not found")
|
||||||
|
},
|
||||||
|
"at": {
|
||||||
|
"atMobiles": phones.keys(),
|
||||||
|
"isAtAll": False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request = urllib2.Request(url, data=json.dumps(body))
|
||||||
|
request.add_header("Content-Type",'application/json;charset=utf-8')
|
||||||
|
request.get_method = lambda: method
|
||||||
|
try:
|
||||||
|
connection = opener.open(request)
|
||||||
|
print(connection.read())
|
||||||
|
except urllib2.HTTPError, error:
|
||||||
|
print(error)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send_sms(cls, payload):
|
def send_sms(cls, payload):
|
||||||
users = payload.get('event').get("notify_users_obj")
|
users = payload.get('event').get("notify_users_obj")
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
级别状态: S{{.Severity}} {{if .IsRecovered}}Recovered{{else}}Triggered{{end}}
|
||||||
|
规则名称: {{.RuleName}}{{if .RuleNote}}
|
||||||
|
规则备注: {{.RuleNote}}{{end}}
|
||||||
|
监控指标: {{.TagsJSON}}
|
||||||
|
触发时间: {{timeformat .TriggerTime}}
|
||||||
|
触发时值: {{.TriggerValue}}
|
|
@ -8,7 +8,7 @@ RunMode = "release"
|
||||||
AdminRole = "Admin"
|
AdminRole = "Admin"
|
||||||
|
|
||||||
# Linkage with notify.py script
|
# Linkage with notify.py script
|
||||||
NotifyChannels = [ "email", "dingtalk", "wecom" ]
|
NotifyChannels = [ "email", "dingtalk", "wecom", "feishu" ]
|
||||||
|
|
||||||
[[ContactKeys]]
|
[[ContactKeys]]
|
||||||
Label = "Wecom Robot Token"
|
Label = "Wecom Robot Token"
|
||||||
|
@ -18,6 +18,10 @@ Key = "wecom_robot_token"
|
||||||
Label = "Dingtalk Robot Token"
|
Label = "Dingtalk Robot Token"
|
||||||
Key = "dingtalk_robot_token"
|
Key = "dingtalk_robot_token"
|
||||||
|
|
||||||
|
[[ContactKeys]]
|
||||||
|
Label = "Feishu Robot Token"
|
||||||
|
Key = "feishu_robot_token"
|
||||||
|
|
||||||
[Log]
|
[Log]
|
||||||
# log write dir
|
# log write dir
|
||||||
Dir = "logs"
|
Dir = "logs"
|
||||||
|
|
Loading…
Reference in New Issue