阿里云邮件推送服务
阿里云 -> 管理控制台 -> 产品与服务 -> 云通信 -> 邮件推送
立即开通 -> 发信域名 -> 新建域名 -> 点击配置
dnspod -> TXT记录/MX记录/CNAME
验证
发信地址 -> 新建发信地址 -> 域名/账号/发信类型(触发) -> 设置smtp密码
SMTP服务地址: smtpdm.aliyun.com ,SMTP服务端口号:25或80或465(SSL加密)
创建发邮件python脚本
vi mail.py #内容
#!/usr/bin/python
#coding:utf-8
import smtplib
from email.mime.text import MIMEText
import sys
mail_user = 'aming@ishiming.net'
mail_pass = 'xxxxxxxx'
def send_mail(to_list,subject,content):
me = "zabbix 监控告警平台"+"<"+mail_user+">"
msg = MIMEText(content, 'plain', 'utf-8')
msg['Subject'] = subject
msg['From'] = me
msg['to'] = to_list
try:
s = smtplib.SMTP("smtpdm.aliyun.com", 25)
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])
测试: python mail.py aming_test@163.com "测试邮件" "cececececece"
设置zabbix_server配置文件
vim /etc/zabbix/zabbix_server.conf
找到:AlertScriptsPath=/usr/lib/zabbix/alertscripts
cd /usr/lib/zabbix/alertscripts
把mail.py 挪到这个目录下来
给它一个755权限 chmod 755 mail.py
设置zabbixWEB UI
1) 设置报警媒介
Administration -> Media types -> 右上角(Create Media type)
Name: baojing
Type: Script
Script name: mail.py
Script parameters -> Add {ALERT.SENDTO}/ Add {ALERT.SUBJECT}/Add {ALERT.MESSAGE}
Add
2)设置接收邮件地址
Administration -> Users -> Admin(或者新建用户)
Media -> Add
Type: baojing
Send to: 邮箱地址,如 aming_test@163.com
Add
Update
3)配置动作
Configuration -> Actions -> Create action
Name: 发邮件
Operations
New
Send to Users -> Admin
Send only to -> baojing
Conditions -> new -> Add
Add
Recovery operations
New
Send to Users -> Admin
Send only to -> baojing
Add
Add
测试报警
Configuration -> Hosts -> Triggers
故意调整一个trigger
Monitoring -> Problems