Skip to content

Commit

Permalink
add feishu bot
Browse files Browse the repository at this point in the history
  • Loading branch information
ry4nnnn committed Aug 7, 2024
1 parent 03eba46 commit a231a1b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ notify:
access_token:
secret:

#https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot#9fe10f9b
feishu:
enable: false
webhook:
secret:

#邮箱配置,在每天6点会推送前一天的漏洞汇总,注意password为授权码
email:
smtp_server:
Expand Down
30 changes: 30 additions & 0 deletions notifications/feishu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import hashlib
import base64
import hmac
import requests
import time


def gen_sign(timestamp, secret):
string_to_sign = '{}\n{}'.format(timestamp, secret)
hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest()
sign = base64.b64encode(hmac_code).decode('utf-8')
return sign


def feishu_notification(webhook, secret, content):
webhook_url = 'https://open.feishu.cn/open-apis/bot/v2/hook/' + webhook
timestamp = str(int(time.time()))
sign = gen_sign(timestamp, secret)
headers = {
"Content-Type": "application/json"
}
data = {
"timestamp": timestamp,
"sign": sign,
"msg_type": "text",
"content": {
"text": content
}
}
requests.post(webhook_url, json=data, headers=headers)
3 changes: 3 additions & 0 deletions notifications/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from notifications.mail import email_notification
from notifications.dingtalk import dingtalk_notification
from notifications.wxwork import wxwork_notification
from notifications.feishu import feishu_notification


def send_realtime_notifications(content):
Expand All @@ -11,6 +12,8 @@ def send_realtime_notifications(content):
wxwork_notification(notify['wxwork']['key'], content)
if notify['dingtalk']['enable']:
dingtalk_notification(notify['dingtalk']['access_token'], notify['dingtalk']['secret'], content)
if notify['feishu']['enable']:
feishu_notification(notify['feishu']['webhook'], notify['feishu']['secret'], content)


def send_daily_notifications(date):
Expand Down

0 comments on commit a231a1b

Please sign in to comment.