1、Zabbix添加處理方法:管理——處理方法——create media type
650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131228/122H0C46-0.png" border="0" alt="" />
zabbix會傳給指令碼三個參數:接收使用者,郵件主題,郵件內容
zabbix_sendmail.py
- #!/usr/bin/python
- #coding:utf-8
-
-
- import smtplib
- from email.mime.text import MIMEText
- import sys
-
- mail_host = 'smtp.163.com'
- mail_user = 'username'
- mail_pass = 'password'
- 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])
2、添加觸發設定:系統配置——操作——create action
650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131228/122H062Y-1.png" border="0" alt="" />
650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131228/122H0C53-2.png" border="0" alt="" />
650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131228/122H04193-3.png" border="0" alt="" />
3、zabbix_server添加指令碼配置:
mkdir -p /usr/local/zabbix/scripts
把指令碼上傳到該目錄
修改zabbix_server.conf配置:
AlertScriptsPath=/usr/local/zabbix/scripts
然後重啟服務
配置完成,很簡單!~
本文出自 “營運筆記” 部落格,請務必保留此出處http://lihuipeng.blog.51cto.com/3064864/1066915