由于手上的zabbix服务器有几个,有时会没注意报警短信,又懒得登陆上去看看zabbix,所以用Python利用zabbix的API获取有问题的机器每天早上发到我邮箱,foxmail又是我天天都用的东西,这样我就可以方便地看到所有有问题的机器了
zabbix_sendmail.py
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
#mail_to_list = ['lihuipeng@xxx.com',]
mail_host = 'smtp.163.com'
mail_user = 'testest' #发件人邮箱帐号
mail_pass = '123456' #发件人邮箱密码
mail_postfix = '163.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'] = ";".join(to_list)
#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__":
print sys.argv[1]
print sys.argv[2]
print sys.argv[3]
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
这个是我用来发邮件的脚本,原理就是连接到163邮箱发送邮件,这里我是注册了一个帐号专门用来发邮件的。
ZABBIX 的详细介绍:请点这里
ZABBIX 的下载地址:请点这里
相关阅读:
CentOS 6.3下Zabbix安装部署
CentOS 6.3下Zabbix监控apache server-status
CentOS 6.3下Zabbix监控MySQL数据库参数