脚本邮箱监控

Posted laowang-106

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了脚本邮箱监控相关的知识,希望对你有一定的参考价值。

# coding=utf-8
"""
发送邮件
"""
import smtplib
from email.mime.text import MIMEText
from email.header import Header


def send_mail(content=""):
print("send_mail")
smtphost = ‘smtp.exmail.qq.com‘ # smtp服务器
port = 465 # smtp服务器端口
sender = "xxxx@xx.com" # 发件人邮箱
pwd = "xxxxx" # 邮箱密码
receivers = [‘xxx@xx.cn‘, ‘xxx@xxxcn‘, ‘xxxxx@qq.com‘] # 收件人邮箱
subject = "幸运开学季脚本" # 主题
content = content or "***"
msg = MIMEText(content, ‘plain‘, ‘utf-8‘) # 参数分别是邮件内容、文本格式、编码
msg[‘from‘] = Header(sender) # 谁发
msg[‘to‘] = Header("lucky_2019") # 发给谁
msg[‘subject‘] = Header(subject) # 邮件主题
try:
smtpObj = smtplib.SMTP_SSL(smtphost, port) # SSL加密
smtpObj.login(sender, pwd)
smtpObj.sendmail(sender, receivers, msg.as_string())
print("send mail successfully")
except smtplib.SMTPException as e:
print(e)
return 1


def run():
print(‘开始执行‘)
while True:
try:
data_list = award_list()
action_award(data_list)
except Exception as e:
print(e)
msg = f"2019开学季-教师或学生脚本处理报错, 循环退出了 error is e"
print(msg)
mail(msg)
continue


if __name__ == "__main__":

run()




以上是关于脚本邮箱监控的主要内容,如果未能解决你的问题,请参考以下文章

添加自定义监控项目,zabbix配置告警-添加邮箱,zabbix配置告警-添加用户,测试告警

shell五一个系统监控脚本

zabbix脚本告警

开放系统监控shell脚本

系统资源监控脚本

Python磁盘监控日志分析监控脚本