Zabbix How to send alert messages using Python scripts

Source: Internet
Author: User
Objective

Zabbix is a very powerful monitoring tool that can monitor server data for Linux and Windows, and can also extend the default monitoring by customizing keys, but the messages provided by your own email alerts are not very friendly. In this paper, we want to send the corresponding image and URL connection at the same time by the custom script.

The steps are as follows:

1. Edit the zabbix_server.conf file and modify the Alertscriptspath parameter, which is used 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 MIM Etextfrom email.utils import parseaddr, Formataddrimport smtplibimport sysdef send_mail (_to_email,_subject,_message): # define Mail Send smtp_host = ' smtp.xxx.xx ' from_email = ' xxx@xxx.xx ' passwd = ' xxxxxx ' msg = Mimetext (_message, ' plain ', ' utf-8 ') ms g[' Subject ' = _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 the permissions of the Python script

Chown-r Zabbix:zabbix zabbix_send_email.pychmod 755 zabbix_send_email.py

4. Zabbix Web-side configuration

Administration–> Media types–> Create Media type

Create a test user administration–> users–> Create user

Specify media:administration–> users–> Create user–> Media for the newly created user

Create action to implement mail alerts configuration–> actions–> Create action

5. Zabbix Test Send mail

Find a test zabbix_agentd,kill off to see if you receive an alert message. Then restore it to see if the recovered message was received. If everything is expected, then this completes the Zabbix alert message using the Python script. If not as expected.

TIPS:

If you are using the zabbix3.0, please note that the administration–> media types–> Create Media type is configured as follows:

Summarize

The above is the entire content of this article, I hope that the content of this article on everyone's study or work can bring certain help, if there is doubt you can message exchange.

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.