Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use python script to send alarm email to zabbix

Shulou Source: shulou.com Published: 2022-05-31 11:24:22 09月15日 Update

This article mainly introduces zabbix how to use python script to send alarm email related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this zabbix how to use python script to send alarm email article will have a harvest, let's take a look.

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, and 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 delivery 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 python scripts

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

4. Zabbix web 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 realize email alarm configuration-> actions-> create action

5. Zabbix test to send email

Find a zabbix_agentd,kill on test to see if you have received an alarm email. Then restore it to see if you have received the restored message. If everything goes as expected, the alarm email for zabbix using the python script is now complete. If not as expected.

Tips:

If you use zabbix3.0, please note that the configuration of administration-> media types-> create media type is as follows:

This is the end of the article on "how zabbix uses python scripts to send alarm emails". Thank you for reading! I believe you all have a certain understanding of "how zabbix uses python scripts to send alarm emails". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Email scripts alarms parameters knowledge content thoughts files articles paths tests configuration value easy to operate articles easy to understand more permissions steps users Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei MySQL Shulou Technology Microsoft