This article uses an external script python to implement the zabbix alarm mechanism. For zabbix3.0, there is a small change here. it takes only one day to find the cause. Next let's take a look at the detailed introduction. if you need it, you can refer to it for reference. Preface
Zabbix is a very powerful monitoring tool that can monitor server data in linux and windows, or expand default monitoring metrics through custom keys, however, the information provided by the built-in email alarm is not friendly. In this article, we want to use a custom script to send the corresponding images and url connections when sending alarm emails.
The procedure is as follows:
1. edit the zabbix_server.conf file and modify the AlertScriptsPath parameter to specify the absolute path of the external script.
vim /etc/zabbix/zabbix_server.confAlertScriptsPath=/usr/lib/zabbix/alertscripts
2. upload the new py script to the absolute path specified by the AlertScriptsPath parameter. the py file is as follows:
#! /Usr/bin/env python # coding: UTF-8 ''' [INFORMATION] Zabbix Send Email With PythonAUTHOR: WingGitHub: https://github.com/wing324Email: wing324@126.com ''' from email import encodersfrom email. header import Headerfrom email. mime. text import MIMETextfrom email. utils import parseaddr, formataddrimport smtplibimport sysdef send_mail (_ to_email, _ subject, _ message): # define mail sending smtp_host = 'smtp. xxx. xx'from_email = 'XXX @ xxx. xx 'passwd = 'xxxxxx' msg = MIMEText (_ message, 'plain ', 'utf-8') msg ['subobject'] = _ Subject smtp_server = smtplib. SMTP (smtp_host, 25) smtp_server.login (from_email, passwd) smtp_server.sendmail (from_email, [_ to_email], msg. as_string () smtp_server.quit () if _ name _ = '_ main _': send_mail (sys. argv [1], sys. argv [2], sys. argv [3])
3. modify python script permissions
chown -R zabbix:zabbix zabbix_send_email.pychmod 755 zabbix_send_email.py
4. zabbix web configuration
Administration-> Media types-> Create media type
Summary
The above is all about this article. I hope this article will help you in your study or work. if you have any questions, please leave a message.
For more information about how zabbix uses python scripts to send alert emails, see PHP!