A-A+
python邮件告警脚本
[root@localhost alertscripts]# pwd /usr/local/zabbix/share/zabbix/alertscripts [root@localhost alertscripts]# ls sendmail.py sendmail.sh.bak [root@localhost alertscripts]#sendmail.py [root@localhost alertscripts]# ./sendmail.py ‘收件人’ ‘主题’ ‘内容’-------------------------------------------------------------------------------------------
#!/usr/bin/env python #coding:utf-8 import smtplib from email.mime.text import MIMEText import sys #邮件服务器地址 mail_host = 'mail.139.com' #用户名 mail_user = '150xxxxxxxx' #用户密码 mail_pass = 'xxxxxxxx' mail_postfix = '139.com' def send_mail(to_list,subject,content): me = mail_user+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content) msg['Subject'] = subject msg['From'] = me msg['to'] = to_list try: s = smtplib.SMTP() s.connect(mail_host) s.login(mail_user,mail_pass) s.sendmail(me,to_list,msg.as_string()) s.close() return True except Exception,e: print str(e) return False if __name__ == "__main__": send_mail(sys.argv[1], sys.argv[2], sys.argv[3])