Skip to content

Commit

Permalink
接入企业微信报警
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris-code committed Apr 16, 2021
1 parent 69e5f0b commit ee28d8a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions feapder/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ def send_msg(self, msg, level="debug", message_prefix=""):
msg, message_prefix=message_prefix, title=self._spider_name
)

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

def spider_begin(self):
"""
@summary: start_monitor_task 方式启动,此函数与spider_end不在同一进程内,变量不可共享
Expand Down
2 changes: 1 addition & 1 deletion feapder/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
ITEM_FILTER_ENABLE = False # item 去重
REQUEST_FILTER_ENABLE = False # request 去重

# 报警 支持钉钉及邮件,二选一即可
# 报警 支持钉钉、企业微信、邮件
# 钉钉报警
DINGDING_WARNING_URL = "" # 钉钉机器人api
DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个
Expand Down
2 changes: 1 addition & 1 deletion feapder/templates/project_template/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
# ITEM_FILTER_ENABLE = False # item 去重
# REQUEST_FILTER_ENABLE = False # request 去重
#
# # 报警 支持钉钉及邮件,二选一即可
# 报警 支持钉钉、企业微信、邮件
# # 钉钉报警
# DINGDING_WARNING_URL = "" # 钉钉机器人api
# DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个
Expand Down
9 changes: 3 additions & 6 deletions feapder/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ def wechat_warning(
"""企业微信报警"""
if isinstance(user_phone, str):
user_phone = [user_phone] if user_phone else []

if all_users is True or not user_phone:
user_phone = ["@all"]

Expand All @@ -2314,13 +2314,10 @@ def wechat_warning(
if is_in_rate_limit(rate_limit, url, user_phone, message_prefix or message):
log.info("报警时间间隔过短,此次报警忽略。 内容 {}".format(message))
return

data = {
"msgtype": "text",
"text": {
"content": message,
"mentioned_mobile_list": user_phone
}
"text": {"content": message, "mentioned_mobile_list": user_phone},
}

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

0 comments on commit ee28d8a

Please # to comment.