1.使用python的脚本,发送邮件。代码如下:
点击查看代码
[root@ZabbixServerMasterNode ~]# cd /etc/zabbix/alertscripts/
[root@ZabbixServerMasterNode alertscripts]# cat sendmail.py
#!/bin/env python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
from sys import argv
mailto_list=[]
mail_host="xxx.xxx.cn"
mail_user="xxx.cn"
mail_pass="xxxx"
debug_level=0
def send_mail(to_list,sub,content):
me=mail_user
msg = MIMEText(content,_subtype='plain',_charset='utf-8')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
server = smtplib.SMTP_SSL(mail_host, 465)
server.connect(mail_host)
server.login(mail_user,mail_pass)
server.sendmail(me,to_list,msg.as_string())
server.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
mailto_list=argv[1].split(';')
sub=argv[2]
content=argv[3]
send_mail(mailto_list,sub,content)
通过调用上述代码,发现特别的慢。
后面查看是主机定义的新的hostname,但是hosname没有配置。
通过配置/etc/hosts
解决邮件发送慢的问题。