Zabbix邮件报警脚本
对于目前的运营商来说,25端口基本上被禁用了,只能使用ssl/tls加密协议来发收邮件,对于zabbix来说邮件报警还是比较常用的,下面为报警脚本,亲测时可以正常收到邮件的,可以先进行测试是否能正常收到邮件在正式配置到zabbix上。以163邮件为例:
[root@localhost ~]# cat zabbix_mail.py #!/usr/bin/python# coding=utf-8#zabiix 邮件报警脚本#测试方法:python zabbix_mail.py XXXXXXX@163.com test test#能正常发送邮件说明成功 import smtplibimport sysfrom email.mime.text import MIMEText class send_mail(): mail_host="smtp.163.com" mail_user="XXXXXXXXXX@163.com"#注:此地方的密码为POP3/SMTP/IMAP客户端授权的授权码,不是邮箱的登录密码 mail_pass="XXXXXXXXXX" mail_postfix="163.com" def __init__(self,sub,content): self.me="Zabbix-Alter"+"<"+self.mail_user+"@"+self.mail_postfix+">" self.msg = MIMEText(content,_subtype='html',_charset='utf-8') self.msg['From'] = self.me self.msg['Subject'] = sub def sendMessage(self,user): self.msg['To'] = ";".join(user) try: s = smtplib.SMTP_SSL(host=self.mail_host,port=465) s.login(self.mail_user,self.mail_pass) s.sendmail(self.me, user, self.msg.as_string()) #发送邮件 s.close() except Exception, e: print str(e) if __name__ == '__main__': mailto_list=[] mailto_list.append(sys.argv[1]) s = send_mail(sys.argv[2],sys.argv[3]) s.sendMessage(mailto_list)