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