Objective
Zabbix is a very powerful monitoring tool that can monitor Linux and Windows Server data, and can extend the default monitor by customizing keys, but the message alerts you bring are not very friendly. In this paper, we want to make a custom script to send the corresponding image and URL connection at the same time as the alarm message.
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.conf
alertscriptspath=/usr/lib/zabbix/alertscripts
2, upload the new py script to the Alertscriptspath parameter specified by the absolute path, the py file is as follows:
#! /usr/bin/env python
# coding:utf-8
'
[information]
Zabbix Send Email with Python
author:wing
github:https://github.com/wing324
Email:wing324@126.com
' from
email import encoders from
email.header Import header
Email.mime.text import Mimetext
from email.utils import parseaddr, formataddr
import smtplib
Import sys
def 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 ')
msg[' 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.py
chmod 755 zabbix_send_email.py
4, Zabbix web-side configuration
Administration–> Media types–> Create Media type
Creates a test user administration–> users–> Create user
Specify media:administration–> users–> Create user–> Media for the newly created user
Create action implement mail alert configuration–> actions–> Create action
5, Zabbix test Send mail
Find a test Zabbix_agentd,kill and see if you receive an alert message. Then restore it to see if you receive a recovered message. If everything goes as expected, you're done with the Python script to complete the ZABBIX alert message. If you don't think as expected.
TIPS:
If you use the zabbix3.0, please note that the configuration of administration–> media types–> Create Media type is as follows:
Summarize
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.