5.19-zabbix郵件告警
阿里雲郵件推送服務
阿里雲 -> 管理控制檯 -> 產品與服務 -> 雲通訊 -> 郵件推送 立即開通 -> 發信域名 -> 新建域名 -> 點選配置 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 = '[email protected]' 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 [email protected] "測試郵件" "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
- 設定報警媒介 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: 郵箱地址,如 [email protected] 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 Moni