标签:aqs mmc rck jsb iam ec2 发送 mrr dom
最近实施了zabbix监控,开源软件杠杠的,甩nagios 好几条街……
环境:centos6.6 + Zabbix 2.4.5 + Python 2.6.6
cd /usr/local/zabbix/share/zabbix/alertscripts #进入脚本存放目录
vi SendAlertEmail.sh #编辑,添加以下代码
#!/bin/sh
echo "$3" | mail -s "$2" $1
:wq! #保存退出
chown zabbix.zabbix /usr/local/zabbix/share/zabbix/alertscripts/SendAlertEmail.sh
#设置脚本所有者为zabbix用户
chmod +x /usr/local/zabbix/share/zabbix/alertscripts/SendAlertEmail.sh
#设置脚本执行权限
最初我使用的是mailx,也就是上面脚本中所写来发邮件,但是发送中文邮件乱码,不得已通过Python来发送中文邮件
SendAlertEmail.sh脚本内容:
cat SendAlertEmail.sh
#!/bin/bash
#date: 20160701
#author:ljb
#funciton: send alert mail use mailx
echo "******" >>/usr/local/zabbix/share/zabbix/alertscripts/sendmail.log 2>&1
echo "$1" "$2" "$3" >>/usr/local/zabbix/share/zabbix/alertscripts/sendmail.log 2>&1
/usr/bin/python /usr/local/zabbix/share/zabbix/alertscripts/send_alert_mail.py "$1" "$2" "$3" >>/usr/local/zabbix/share/zabbix/alertscripts/sendmail.log 2>&1
echo "******" >>/usr/local/zabbix/share/zabbix/alertscripts/sendmail.log 2>&1
此处注意 传参一定要用引号扩起来,不然无法完整识别参数。
send_alert_mail.py 脚本内容:
cat send_alert_mail.py
#!/usr/bin/python
#coding=utf-8
‘‘‘
@date 20160808
@author ljb
‘‘‘
import sys
import smtplib
from email.mime.text import MIMEText
mailto_list=[‘user@yourdomain.com‘]
mail_host="smtp.yourdomain.com" #设置服务器
mail_user="user" #用户名
mail_pass="password" #口令
mail_postfix="yourdomain.com" #发件箱的后缀
def send_mail(to_list,sub,content):
me="zabbix-alert-center"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_subtype=‘plain‘,_charset=‘utf-8‘)
msg[‘Subject‘] = sub
msg[‘From‘] = me
msg[‘To‘] = ";".join(to_list)
try:
server = smtplib.SMTP()
server.connect(mail_host)
server.login(mail_user+"@"+mail_postfix,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__‘:
if send_mail(mailto_list,sys.argv[2],sys.argv[3]):
print "发送成功"
else:
print "发送失败"
zabbix web页面设置:
添加发邮件类型
在zabbix监控页面添加media type
Administration-- Media types—create media type
为管理员账户设置接收报警邮件:
Administration—Users-- Zabbix administrators
添加收件人邮箱在 send to 位置
设置触发器
最后你就可以盯着你邮箱 坐等邮件到来了。
标签:aqs mmc rck jsb iam ec2 发送 mrr dom
原文地址:http://www.cnblogs.com/dmss/p/6030632.html