Zabbix monitoring sends email alerts to multiple users at the same time
Zabbix is a monitoring software, and alarm is essential. This article mainly introduces the configuration process of zabbix alarm to multiple people by email.
Instructions on zabbix mail alarm Configuration:
1. Prepare a script for sending emails.
2. Modify the script path specified in the zabbix configuration file.
3. Associated Script Name
4. Set the email address and alarm time.
5. Configure an alarm trigger
6. add multiple users and send emails to multiple users at the same time
7. Mail Acceptance Test
1. Prepare a script for sending emails.
There are many ways to send emails. If you write scripts by yourself, you only need to follow the zabbix parameter passing format.
The format of parameters for zabbix sending:./sendmail. py recipient title email content
The python mail sending script is as follows:
Cat/usr/local/zabbix/share/zabbix/alertscripts/sendmail_qs.py
#! /Usr/bin/python #-*-coding: UTF-8-*-importsmtplibimportsysfromemail. mime. textimportMIMETextimporttime # reload (sys) # sys. setdefaultencoding ('utf8') current_time = time. strftime ('% Y-% m-% d % H: % m', time. localtime (time. time () mail_host = 'smtp .exmail.qq.com 'mail _ user = 'angrong @ qssec.com' mail _ pwd = '****** 'defsend _ email (content, mailto, get_sub): # msg = MIMEText (content. encode ('utf8'), _ subtype = 'html', _ charset = 'utf8') msg = MIMEText (content, _ subtype = 'plain ', _ charset = 'gb2312') msg ['from'] = mail_usermsg ['subobject'] = get_submsg ['to'] = ",". join (mailto) try: s = smtplib. SMTP_SSL (mail_host, 465) s. login (mail_user, mail_pwd) s. sendmail (mail_user, mailto, msg. as_string () s. close () condition texceptionase: print 'exception: ', etitle = sys. argv [2] cont = "" ----------------------------------- Abstract: % s --------------------------------- time: % s hour "% (sys. argv [3], current_time) to_list = ['% s' % (sys. argv [1]),] withopen ('/tmp/sendmail_qs.log', 'AB') asf: f. write ('% sReceiveaddress: % sTitle: % s \ n' % (current_time, sys. argv [1], title) send_email (cont, to_list, title)
# The python script finally records the sent mail logs to/tmp/sendmail. log.
# Modify mail_host, mail_user, and mail_pwd at the top of the page.
2. Modify the script path specified in the zabbix configuration file.
Echo 'alertscriptspath =/usr/local/zabbix/share/zabbix/alertscripts '>/usr/local/zabbix/etc/zabbix_server.conf
/Etc/init. d/zabbix_serverrestart
In this example, the installation directory of zabbix is in/usr/local/zabbix. You can manually modify it in different paths.
3. Associated Script Name
[Zabbix main panel, management, alert media, and media creation]
Enter the script name and the name in/usr/local/zabbix/share/zabbix/alertscripts.
4. Set the email address and alarm time.
[Zabbix main panel, management, user, click User]
Configure the user's email address
5. Configure an alarm trigger
[Zabbix main panel à configuration à Action à create action] configure alarm information
Configure alarm trigger conditions
Recipient after setting the trigger Condition
6. add multiple users and send emails to multiple users at the same time
First, create a common user in manage.
Then, promote normal users to super administrators. Normal users do not have the permission to send emails if they are not promoted to a super administrator!
Add a new receiving user in configuration à action.
7. Mail Acceptance Test
Down the zabbix_agentd process of the client node. Wait for an email alert. By default, the agent sends an email for 5 minutes. That is, if no data is obtained for five times, an alert is triggered.
According to the test, zabbix does not send emails to multiple users by means of parallel mail. Instead of having multiple recipients at a time, execute two mail sending scripts.
Therefore, if the number of recipients is large, you can directly write all the recipients to the above python email script, that is, do not call the recipients sent from zabbix. The disadvantage is that you need to manually modify the python script when the recipient changes, instead of modifying the zabbix user configuration.
The alarm configuration for zabbix multiplayer emails has been completed.