Home > Backend Development > Python Tutorial > How zabbix uses python script to send alarm emails

How zabbix uses python script to send alarm emails

高洛峰
Release: 2017-01-17 09:59:38
Original
1425 people have browsed it

Preface

zabbix is ​​a very powerful monitoring tool that can monitor server data on Linux and Windows. You can also extend the default monitoring items through custom keys, but the information provided by the built-in email alarm is not Not very friendly. This article wants to use a custom script to send the corresponding image and URL connection at the same time as the alarm email.

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
Copy after login

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 Python
AUTHOR : Wing
GitHub : https://github.com/wing324
Email : wing324@126.com
'''
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
import sys
def send_mail(_to_email,_subject,_message):
# 定义邮件发送
 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])
Copy after login

3. Modify the permissions of the python script

chown -R zabbix:zabbix zabbix_send_email.py
chmod 755 zabbix_send_email.py
Copy after login

4. Zabbix web side configuration

Administration –> Media types –> Create media type

How zabbix uses python script to send alarm emails

##Create a test user Administration –> ; Users –> Create user

How zabbix uses python script to send alarm emails

Specify media for the newly created user:Administration –> Users –> Create user –> Media

How zabbix uses python script to send alarm emails

Create action to implement email alarmConfiguration –> Actions –> Create action

How zabbix uses python script to send alarm emails

How zabbix uses python script to send alarm emails

How zabbix uses python script to send alarm emails

5. Zabbix test sends emails


Find a test zabbix_agentd, kill it, and check whether you receive an alarm email. Restore it again and check whether you receive the restored email. If everything goes as expected, then you have completed using the python script to complete the zabbix alarm email. If it doesn't go as expected.

TIPS:


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

How zabbix uses python script to send alarm emails

Summary

The above is the entire content of this article. I hope the content of this article can bring some help to everyone's study or work. If you have any questions, you can leave a message. comminicate.

For more articles on how zabbix uses python scripts to send alarm emails, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template