1.申請阿里雲郵件推送
2.配置DNSPod的TXT記錄/MX記錄/CNAME
3.設置發信地址
4.建立發郵件腳本(python編寫)
5.測試腳本是否可用
在zabbix服務端設置警告郵件
1.設置zabbix配置文件,將腳本移動到指定配置文件中指定的目錄
2.設置zabbix web UI
3.測試報警
4.1在/root目錄下創建文件「mail.py」。
4.2複製如下內容至「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])
4.3 腳本內須要修改的地方 #mail_user和mail_pass,與發信地址和admin密碼一致,SMTP服務地址,端口號也需一致
4.4 修改/root/mail.py的權限:chmod 755 mail.py
python
測試:python mail.py 收件地址 "郵件主題" "郵件內容" 打開收件地址如qq郵箱,查看是否收到測試郵件
查詢zabbix_server配置文件: vim /etc/zabbix/zabbix_server.conf 找到: AlertScriptsPath=/usr/lib/zabbix/alertscripts 這一行定義了zabbix告警郵件腳本的路徑。 把mail.py文件複製到該目錄下 確保mail.py有其餘用戶的執行權限:chmod 755 mail.py
2.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.2設置接收郵件地址
Administration -> Users -> Admin(或者新建用戶)
Media -> Add
Type: baojing
Send to: 郵箱地址,如 aming_test@163.com Add
Update
2.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 Addweb
Configuration -> Hosts -> Triggers 故意調整一個trigger Monitoring -> Problems 查看問題是否出現 是否發送到指定郵箱上 #當問題解決後會發送一個解決郵件給指定郵箱