测开之路六十七:监控平台之附加功能准备

时间:2022-06-15 09:25:40

 

实现效果,选择时间段和ip,展示所选时间段下该ip的资源使用情况

测开之路六十七:监控平台之附加功能准备

 

MongoDB里面增加一个获取表名的方法,后面用被监控的机器的ip做表名

测开之路六十七:监控平台之附加功能准备

def get_all_collections(self, database):
""" 获取所有表名,database:数据库名"""
_database = self.connect.get_database(database)
return _database.collection_names()

 

common里面增加发邮件的功能,用于监控触发预设值后发邮件报警

测开之路六十七:监控平台之附加功能准备

def smtp_service(sender, password, receiver, message):
""" 定义发送邮件,sender:发件人,receiver:收件人,message:要发送的信息 """
server = 'smtp.qq.com'
try:
smtp = smtplib.SMTP()
smtp.connect(server)
smtp.login(sender, password)
smtp.sendmail(sender, receiver, message.as_string())
print("发送邮件给{0}成功!!!".format(receiver))
except smtplib.SMTPException as error:
print(error)
print("发送邮件给{0}失败!!!".format(receiver))
finally:
smtp.quit()


def send_email(receiver, template):
""" receiver: 接收者、template: 触发报警时的发送内容模板 """
sender = '907728701@qq.com'
password = "xxxxxxx" # smtp密码
title = '测试平台报警邮件!'
message = MIMEText(template, 'html', 'utf-8')
message['From'] = sender
message['To'] = receiver
message['Subject'] = Header(title, 'utf-8')
smtp_service(sender, password, receiver, message)

 

准备好一个选时间的控件,这里使用bootstrap的

测开之路六十七:监控平台之附加功能准备