Skip to content

Commit

Permalink
钉钉报警支持提示所有人
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Jul 20, 2021
1 parent d9ebbbd commit 07f350c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion feapder/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,12 @@ def _stop_all_thread(self):
self._started.clear()

def send_msg(self, msg, level="debug", message_prefix=""):
# log.debug("发送报警 level:{} msg{}".format(level, msg))
if setting.WARNING_LEVEL == "ERROR":
if level != "error":
return

if setting.DINGDING_WARNING_PHONE:
if setting.DINGDING_WARNING_URL:
keyword = "feapder报警系统\n"
tools.dingding_warning(keyword + msg, message_prefix=message_prefix)

Expand Down
1 change: 1 addition & 0 deletions feapder/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
# 钉钉报警
DINGDING_WARNING_URL = "" # 钉钉机器人api
DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个
DINGDING_WARNING_ALL = False # 是否提示所有人, 默认为False
# 邮件报警
EMAIL_SENDER = "" # 发件人
EMAIL_PASSWORD = "" # 授权码
Expand Down
1 change: 1 addition & 0 deletions feapder/templates/project_template/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
# # 钉钉报警
# DINGDING_WARNING_URL = "" # 钉钉机器人api
# DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个
# DINGDING_WARNING_ALL = False # 是否提示所有人, 默认为False
# # 邮件报警
# EMAIL_SENDER = "" # 发件人
# EMAIL_PASSWORD = "" # 授权码
Expand Down
6 changes: 3 additions & 3 deletions feapder/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2280,20 +2280,20 @@ def dingding_warning(
url = url or setting.DINGDING_WARNING_URL
user_phone = user_phone or setting.DINGDING_WARNING_PHONE

if not all([url, user_phone, message]):
if not all([url, message]):
return

if is_in_rate_limit(rate_limit, url, user_phone, message_prefix or message):
log.info("报警时间间隔过短,此次报警忽略。 内容 {}".format(message))
return

if isinstance(user_phone, str):
user_phone = [user_phone]
user_phone = [user_phone] if user_phone else []

data = {
"msgtype": "text",
"text": {"content": message},
"at": {"atMobiles": user_phone, "isAtAll": False},
"at": {"atMobiles": user_phone, "isAtAll": setting.DINGDING_WARNING_ALL},
}

headers = {"Content-Type": "application/json"}
Expand Down

0 comments on commit 07f350c

Please sign in to comment.