zabbix-server 192.168.1.33
1、安装python、pip、模块
# yum install -y python python-devel python-setuptools epel-release
# yum clean
# yum -y install python-pip
# pip search smtplib
aiosmtplib (1.0.2) - asyncio SMTP client
easyemail (0.4.0) - Simple lib abstracting email sending with smtplib.
mailclient (0.2.0) - Simplified use of smtplib for Python. Easy email sending.
micropython-smtplib (0.0.1) - Dummy smtplib module for MicroPython
personal (0.1.1) - Easy, secure self notification via email and sms, using smtplib and twilio
PyEmail (0.0.1) - Python library to send emails using SMTPLIB library
secure-smtplib (0.1.1) - Secure SMTP subclasses for Python 2
smtplibaio (2.1.1) - An async version of smtplib
smtpssllib.py (2.4.4.1) - Modified version of smtplib supporting SSL
xsmtplib (1.0.0.dev1) - An extension of standard smtplib, which supports proxy tunneling
# pip install PyEmail
Collecting PyEmail
Downloading PyEmail-0.0.1.zip
Installing collected packages: PyEmail
Running setup.py install for PyEmail ... done
Successfully installed PyEmail-0.0.1
2、sendmail脚本
# vim /usr/lib/zabbix/alertscripts/python_mail.py
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_host = 'mail.163.com'
mail_user = 'user@163.com'
mail_pass = 'passwd'
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'] = 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__":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])
# chmod +x /usr/lib/zabbix/alertscripts/python_mail.py
验证脚本是否可以正常发送邮件
# ./usr/lib/zabbix/alertscripts/python_mail.py xxx@139.com hello testmail
注:三个参数分别是:收件人邮箱、邮箱主题、邮箱内容
3、配置zabbix
登录zabbix主机,查看配置zabbix_server.conf ,找到AlertScriptsPath,查看路径位置,如被注释,将注释打开,把send.py 文件保存到该目录下。
如有修改配置,需重启zabbix-server服务。
在zabbix管理中添加报警媒介类型,注意parameter中的值一定要写入,注意script name中的脚本文件名字,要和刚刚编写的Python文件名一致
新增参数:{ALERT.SENDTO}{ALERT.SUBJECT}{ALERT.MESSAGE},分别依次加入。然后更新保存。
以下内容摘自:http://blog.csdn.net/xiegh2014/article/details/73436503
添加三个参数
{ALERT.SENDTO}收件人地址
{ALERT.SUBJECT}主题
{ALERT.MESSAGE}详细内容
2、创建报警用户
3、配置报警媒介
4、配置权限
现在测试环境所以配置超级管理的权限,如果是生产环境建议使用用户权限
四、配置报警动作
1、创建新的触发动作
2、配置动作
3、配置操作
故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障!
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
4、配置恢复操作
恢复{TRIGGER.STATUS}, 服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
5、邮件告警测试结果
阅读(2867) | 评论(0) | 转发(0) |