zabbix系統郵件警示Python指令碼

來源:互聯網
上載者:User

標籤:

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指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.