阿里云邮件推送服务
阿里云 -> 管理控制台 -> 产品与服务 -> 云通信 -> 邮件推送立即开通 -> 发信域名 -> 新建域名 -> 点击配置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 smtplibfrom email.mime.text import MIMETextimport sys
mail_user = '[email protected]'mail_pass = 'xxxxxxxx'
def send_mail(to_list,subject,content):me = "zabbix 监控告警平台"+"<"+mail_user+">"msg = MIMEText(content, 'plain', 'utf-8')msg['Subject'] = subjectmsg['From'] = memsg['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 [email protected] "测试邮件" "cececececece"设置zabbix_server配置文件
vim /etc/zabbix/zabbix_server.conf找到:AlertScriptsPath=/usr/lib/zabbix/alertscriptscd /usr/lib/zabbix/alertscripts把mail.py 挪到这个目录下来给它一个755权限 chmod 755 mail.py设置zabbixWEB UI
- 设置报警媒介Administration -> Media types -> 右上角(Create Media type)Name: baojingType: ScriptScript name: mail.pyScript parameters -> Add {ALERT.SENDTO}/ Add {ALERT.SUBJECT}/Add {ALERT.MESSAGE}Add
2)设置接收邮件地址Administration -> Users -> Admin(或者新建用户)Media -> AddType: baojingSend to: 邮箱地址,如 [email protected]AddUpdate
3)配置动作Configuration -> Actions -> Create actionName: 发邮件OperationsNew
Send to Users -> AdminSend only to -> baojingConditions -> new -> AddAdd
Recovery operationsNew
Send to Users -> AdminSend only to -> baojingAdd
Add测试报警
Configuration -> Hosts -> Triggers故意调整一个triggerMonitoring -> Problems