Zabbix System mail Alert python script

Source: Internet
Author: User
Tags python script

Zabbix System Mail Alarm configuration There are many ways, such as the system comes with mail, and Zabbix+msmtp+mutt, but the use of Python script should be a very simple and efficient way. The main steps are as follows;

1. Set zabbix_server.conf file

Alterscript =/usr/local/zabbix/share/zabbix/alterscript

2. Set up alarm script

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, "") 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, set the alarm script permissions

sudo chmod Zabbix:zabbix sendemail.sh

sudo chown 755 sendemail.sh

4, finally only need in the Zabbix front-end to the corresponding configuration can.

Zabbix System mail Alert python script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.