这篇文章介绍zabbix邮件告警python脚本代码
#!/usr/bin/python# -*- coding: utf-8 -*-"""Zabbix SMTP Alert script from qq.auth:json"""import sysimport emailimport smtplibimport osfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipart#邮件发送列表,发给哪些人#mailto_list=["winson.zhou@gmail","[email protected]"]#设置服务器,用户名、密码mail_host="smtp.exmail.qq.com"mail_user="[email protected]"mail_pass="123456789"mail_postfix="qq.com"#定义send_mail函数def send_mail(to_list,sub,content): ''' to_list:发给谁 sub:主题 content:内容 send_mail("[email protected]","sub","content") ''' #if not isinstance(sub,unicode): #sub = unicode(sub) address=mail_user msg = MIMEText(content,format,'utf-8') msg["Accept-Language"]="zh-CN" msg["Accept-Charset"]="ISO-8859-1,utf-8" msg['Subject'] = sub msg['From'] = address msg['To'] =to_list try: s = smtplib.SMTP_SSL(mail_host,port=465) #s.connect(mail_host) s.login(mail_user,mail_pass) s.sendmail(address, to_list, msg.as_string()) s.close() return True except Exception, e: print str(e) return Falseif __name__<strong style="color:transparent">本文来源gaodai#ma#com搞@@代~&码网^</strong> == '__main__': send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
测试方法:
在当前脚本目录下执行
python 脚本名称 发送人邮箱 邮件标题 邮件内容
python sendemail.py [email protected] zabbix zabbixcontent
以上就是zabbix邮件告警python脚本代码的详细内容,更多请关注搞代码gaodaima其它相关文章!