本文共 1499 字,大约阅读时间需要 4 分钟。
网上找到一个脚本sendmail.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #!/usr/bin/python # -*- coding:utf-8 -*- import smtplib import sys from email.mime.text import MIMEText import time #reload(sys) #sys.setdefaultencoding('utf8') current_time = time.strftime( '%Y-%m-%d%H:%M' ,time.localtime(time.time())) mail_host = 'smtp.163.com' mail_user = 'xxx@163.com' mail_pwd = 'xxxxxx' def send_email( content,mailto, get_sub ): #msg = MIMEText( content.encode('utf8'),_subtype = 'html', _charset = 'utf8') msg = MIMEText(content,_subtype = 'plain' ,_charset = 'utf8' ) msg[ 'From' ] = mail_user msg[ 'Subject' ] = get_sub msg[ 'To' ] = "," .join( mailto ) try : s = smtplib.SMTP(mail_host, 25 ) s.login(mail_user, mail_pwd ) s.sendmail(mail_user, mailto,msg.as_string()) s.close() except Exception as e: print 'Exception: ' , e title = sys.argv[ 2 ] cont = """ --------------------------------- 摘要: %s --------------------------------- 时间: %s --------------------------------- """ % (sys.argv[ 3 ],current_time) to_list = [ '%s' % (sys.argv[ 1 ]), ] '''withopen('/tmp/sendmail_qs.log','ab') as f: f.write('%s Receive address: %s Title: %s \n'%(current_time,sys.argv[1],title)) ''' send_email( cont, to_list,title) |
sendmail.py脚本权限 755或者777,owner zabbix
测试 ./sendmail.py $to $subject $messages
2.添加脚本
3.设置触发条件
4.设置故障恢复后的报警时间,一般是间隔5分钟,你可以修改为60s
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1630366,如需转载请自行联系原作者