標籤:
zabbix系統郵件警示配置有很多方式,如系統內建的mail,還有zabbix+msmtp+mutt,但是使用Python指令碼應該來說還是一個非常簡捷有效方式。主要有如下步驟;
1、設定zabbix_server.conf檔案
AlterScript = /usr/local/zabbix/share/zabbix/alterscript
2、建立警示指令碼
cd /usr/local/zabbix/share/zabbix/alterscript/
sudo vim sendEmail.sh
#!/usr/bin/env python
#coding:utf-8
import time
import smtplib
import logging
from email.mime.text import MIMEText
import sysLOG_FILENAME="/var/log/email_python.log"mail_host = ‘mstp.163.com‘mail_user = ‘[email protected]‘mail_pass = ‘xxxxx‘mail_postfix = ‘xxxxx‘def send_mail(to_list,subject,content,format=‘html‘): try: me=mail_user+"<"+mail_user+"@"+mail_postfix+">" msg=MIMEText(content,format,‘utf-8‘) msg["Accept-Language"]="zh-CN" msg["Accept-Charset"]="ISO-8859-1,utf-8" msg[‘Subject‘]=subject msg[‘From‘]=me msg[‘to‘]=to_list s=smtplib.SMTP() s.connect(mail_host,"25") s.login(mail_user,mail_pass) s.sendmail(me,to_list,msg.as_string()) s.close() except Exception,e: logging.basicConfig(filename = LOG_FILENAME, level = logging.DEBUG) logging.error(time.strftime(‘%Y-%m-%d %H:%I:%M‘,time.localtime(time.time()))+e)if __name__ == "__main__": send_mail(sys.argv[1],sys.argv[2],sys.argv[3])
3、設定警示指令碼的許可權
sudo chmod zabbix:zabbix sendEmail.sh
sudo chown 755 sendEmail.sh
4、最後只需要在zabbix前端進行相應的配置即可。
zabbix系統郵件警示Python指令碼