Zabbix sends alarm emails using python scripts

Source: Internet
Author: User
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!

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.