diff --git a/feapder/core/scheduler.py b/feapder/core/scheduler.py index e5e599a6..9b62bc51 100644 --- a/feapder/core/scheduler.py +++ b/feapder/core/scheduler.py @@ -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) diff --git a/feapder/setting.py b/feapder/setting.py index af20e745..55f1022a 100644 --- a/feapder/setting.py +++ b/feapder/setting.py @@ -115,6 +115,7 @@ # 钉钉报警 DINGDING_WARNING_URL = "" # 钉钉机器人api DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个 +DINGDING_WARNING_ALL = False # 是否提示所有人, 默认为False # 邮件报警 EMAIL_SENDER = "" # 发件人 EMAIL_PASSWORD = "" # 授权码 diff --git a/feapder/templates/project_template/setting.py b/feapder/templates/project_template/setting.py index 9eb8435e..a713c98b 100644 --- a/feapder/templates/project_template/setting.py +++ b/feapder/templates/project_template/setting.py @@ -94,6 +94,7 @@ # # 钉钉报警 # DINGDING_WARNING_URL = "" # 钉钉机器人api # DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个 +# DINGDING_WARNING_ALL = False # 是否提示所有人, 默认为False # # 邮件报警 # EMAIL_SENDER = "" # 发件人 # EMAIL_PASSWORD = "" # 授权码 diff --git a/feapder/utils/tools.py b/feapder/utils/tools.py index f21b3221..3ac0aa17 100644 --- a/feapder/utils/tools.py +++ b/feapder/utils/tools.py @@ -2280,7 +2280,7 @@ 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): @@ -2288,12 +2288,12 @@ def dingding_warning( 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"}