-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Boris
committed
Mar 26, 2021
1 parent
210076e
commit 12a2c57
Showing
10 changed files
with
261 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# 报警及监控 | ||
|
||
## 钉钉报警 | ||
|
||
条件:需要有钉钉群,需要获取钉钉机器人的Webhook地址 | ||
|
||
获取方式参考官方文档:https://developers.dingtalk.com/document/app/custom-robot-access | ||
|
||
安全设置选择自定义关键词,填入**feapder** | ||
|
||
![-w547](http://markdown-media.oss-cn-beijing.aliyuncs.com/2021/03/27/16167753030324.jpg) | ||
|
||
相关配置: | ||
|
||
```python | ||
# 钉钉报警 | ||
DINGDING_WARNING_URL = "" # 钉钉机器人api | ||
DINGDING_WARNING_PHONE = "" # 报警人 支持列表,可指定多个 | ||
``` | ||
|
||
## 邮件报警 | ||
|
||
相关配置: | ||
|
||
``` | ||
# 邮件报警 | ||
EAMIL_SENDER = "" # 发件人 | ||
EAMIL_PASSWORD = "" # 授权码 | ||
EMAIL_RECEIVER = "" # 收件人 支持列表,可指定多个 | ||
``` | ||
|
||
邮件报警目前支持163邮箱作为发送者,`EAMIL_SENDER`为邮箱账号,如`[email protected]`, `EAMIL_PASSWORD`为授权码,不是登录密码,获取授权码的流程如下: | ||
|
||
1. 设置 -> POP3/SMTP/IMAP | ||
|
||
![-w258](http://markdown-media.oss-cn-beijing.aliyuncs.com/2021/03/27/16167719328720.jpg) | ||
|
||
2. 开启SMTP服务 | ||
|
||
![-w444](http://markdown-media.oss-cn-beijing.aliyuncs.com/2021/03/27/16167719490656.jpg) | ||
|
||
开启后,会弹出授权码,该授权码即为EAMIL_PASSWORD | ||
|
||
3. 设置反垃圾规则为高级 | ||
|
||
![-w1112](http://markdown-media.oss-cn-beijing.aliyuncs.com/2021/03/27/16167719655644.jpg) | ||
|
||
## 报警间隔及报警级别 | ||
|
||
框架会对相同的报警进行过滤,防止刷屏,默认的报警时间间隔为1小时,可通过以下配置修改: | ||
|
||
```python | ||
WARNING_INTERVAL = 3600 # 相同报警的报警时间间隔,防止刷屏 | ||
WARNING_LEVEL = "DEBUG" # 报警级别, DEBUG / ERROR | ||
``` | ||
|
||
DEBUG级别的报警包含一些运行信息,ERROR级别的报警都是有问题的报警,需要及时处理 | ||
|
||
|
||
## 可视化监控 | ||
|
||
所需环境:Influxdb + Grafana | ||
|
||
未完待续,敬请期待... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.3.8-beta1 | ||
1.3.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on 2020/2/19 12:57 PM | ||
--------- | ||
@summary: | ||
--------- | ||
@author: Boris | ||
@email: [email protected] | ||
""" | ||
|
||
import os | ||
import smtplib | ||
from email.header import Header | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from email.utils import formataddr | ||
|
||
from utils.log import log | ||
|
||
|
||
class EmailSender(object): | ||
SENDER = "feapder报警系统" | ||
SMTPSERVER = "smtp.163.com" | ||
|
||
def __init__(self, username, password): | ||
self.username = username | ||
self.password = password | ||
|
||
self.smtpserver = EmailSender.SMTPSERVER | ||
self.sender = EmailSender.SENDER | ||
|
||
self.smtp_client = smtplib.SMTP_SSL() | ||
|
||
def __enter__(self): | ||
self.login() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
self.quit() | ||
|
||
def quit(self): | ||
self.smtp_client.quit() | ||
|
||
def login(self): | ||
self.smtp_client.connect(self.smtpserver) | ||
self.smtp_client.login(self.username, self.password) | ||
|
||
def send( | ||
self, | ||
receivers: list, | ||
title: str, | ||
content: str, | ||
content_type: str = "plain", | ||
filepath: str = None, | ||
): | ||
""" | ||
Args: | ||
receivers: | ||
title: | ||
content: | ||
content_type: html / plain | ||
filepath: | ||
Returns: | ||
""" | ||
# 创建一个带附件的实例 | ||
message = MIMEMultipart() | ||
message["From"] = formataddr( | ||
(self.sender, self.username) | ||
) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 | ||
message["To"] = formataddr((receivers[0], receivers[0])) # ",".join(receivers) | ||
|
||
message["Subject"] = Header(title, "utf-8") | ||
|
||
content = MIMEText(content, content_type, "utf-8") | ||
message.attach(content) | ||
|
||
# 构造附件 | ||
if filepath: | ||
attach = MIMEText(open(filepath, "rb").read(), "base64", "utf-8") | ||
attach.add_header( | ||
"content-disposition", | ||
"attachment", | ||
filename=("utf-8", "", os.path.basename(filepath)), | ||
) | ||
message.attach(attach) | ||
|
||
msg = message.as_string() | ||
# 此处直接发送多个邮箱有问题,改成一个个发送 | ||
for receiver in receivers: | ||
log.debug("发送邮件到 {}".format(receiver)) | ||
self.smtp_client.sendmail(self.username, receiver, msg) | ||
log.debug("邮件发送成功!!!") | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters