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.