- 网上找到一个脚本sendmail.py
#!/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 =‘[email protected]‘ 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
时间: 2024-11-18 12:01:18