python邮件短信告警通知

Zabbix常常需要实现故障的告警通知,及时处理系统异常,可以用邮件和短信实现异常告警.

#! /usr/bin/env python2
# encoding:utf-8

import smtplib
import string

HOST = "smtp.qq.com"   
SUBJECT = "Test email from Python"
TO = "test@qq.com"   #自己发给自己
FROM = "test@qq.com"
text = "Python rules them all!"
BODY = string.join((
        "From: %s" % FROM,
        "To: %s" % TO,
        "Subject: %s" % SUBJECT ,
        "",
        text
        ), "\r\n")
server = smtplib.SMTP()
server.connect(HOST,"587")   #启用ssl连接端口为587
server.starttls()
server.login("test@qq.com","password")
server.sendmail(FROM, [TO], BODY)
server.quit()

短信的实现可参考腾讯云的短信API

通过向短信网关发起请求实现短信通知,需要确保网络通信正常
https://github.com/qcloudsms/qcloudsms_py

效果如下


Leave a Reply

Your email address will not be published. Required fields are marked *