Centos7 Zabbix3.4 email alarm configuration (solving the problem that the email content is xx.bin attachment)

Centos7 Zabbix3.4 email alarm configuration (solving the problem that the email content is xx.bin attachment)

1. Add monitoring Linux host

1. Configuration-Host-Create Host

2. Fill in the information

3. Add template

4. Check the status

2. Configure the mailbox

System environment:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

1. Install the mail sending tool mailx

If you have installed other email sending tools, close them first.

service sendmail stop ##Close sendmail
systemctl disable sendmail.service ##Disable sendingmail at boot
service postfix stop ##Shut down postfix
systemctl disable postfix.service ##Disable postfix startup
[root@localhost ~]# yum install mailx

2. Configure the Zabbix server external mailbox, open the file vim /etc/mail.rc. If the mail.rc file does not exist, create it manually and add the following content:

[root@localhost ~]# vim /etc/mail.rc 

set sendcharsets=iso-8859-1,utf-8
set [email protected]
set smtp=smtp.163.com #163 mailbox needs to open smtp authorization set [email protected] #Authentication user set smtp-auth-password=xxx #Authentication password

3. Test email sending

[root@localhost ~]# echo "zabbix test mail" | mail -s "zabbix" [email protected] 

4. Write a script to send emails

1) Install the dos2unix conversion tool (to solve the problem that the emails sent are in the xx.bin attachment format), (the directory name will change in 7.5.1804) If the download link here is invalid, go to Alibaba's official website to find the corresponding file

[root@localhost ~]# rpm -ivh https://mirrors.aliyun.com/centos/7.5.1804/os/x86_64/Packages/dos2unix-6.0.3-7.el7.x86_64.rpm

Get https://mirrors.aliyun.com/centos/7.5.1804/os/x86_64/Packages/dos2unix-6.0.3-7.el7.x86_64.rpm

Preparing... ################################## [100%]

Upgrading/installing...

1:dos2unix-6.0.3-7.el7 ################################### [100%]

The following email is displayed, but the text cannot be displayed

2) Modify the content of the email sending script

Why do we create this script under this path? This is configured in our zabbix_serber.conf file
AlertScriptsPath=/usr/lib/zabbix/alertscripts

So if you don't want to put the script in this directory, you need to modify the value of AlertScriptsPath in the server configuration file.

[root@localhost ~]# vim /usr/lib/zabbix/alertscripts/sendmail.sh
#!/bin/bash 

#export.UTF-8 #Solve the problem that the sent Chinese characters become garbled characters FILE=/tmp/mailtmp.txt 
echo "$3" >$FILE 
dos2unix -k $FILE #Solved the problem of the content of the sent email becoming an attachment. 

/bin/mail -s "$2" $1 < $FILE

3) Create a temporary file and authorize it. Make sure your user exists in zabbix

[root@localhost ~]# touch /tmp/mailtmp.txt
[root@localhost ~]# chown zabbix.zabbix /tmp/mailtmp.txt

4) The above three parameters are used to receive information passed from the web page:

$1: recipient’s email address;
$2: email title;
$3: Email content

5) Add permissions to the script, otherwise the email cannot be sent normally when an alarm occurs

[root@localhost ~]# chmod 755 /usr/lib/zabbix/alertscripts/sendmail.sh

5. Management - Alarm Media Type - Create Media Type

6. Fill in the content

Add the following three parameters, corresponding to the three parameters required by the sendmail.sh script: recipient address, subject, and detailed content

 {ALERT.SENDTO}
 {ALERT.SUBJECT}
 {ALERT.MESSAGE}

If you do not add these three parameters in 3.0, an error will be reported, because after 3.0, zabbix allows custom parameters, so the parameters will not be passed by default. In 2.0, three parameters will be passed by default, so if you do not write these three parameters in 3.0, an error will be reported.

7. Add alarm media to users

8. Set alarm conditions: Configure-Action-Create Action

1) Set the conditions and name

2) Fill in the recipient, the default information, the user is the recipient just filled in, MyEmail is also just created

Fault alarm:{TRIGGER.STATUS}:{TRIGGER.NAME}
Alarm host:{HOST.NAME}
Host address:{HOST.IP}
Alarm time: {EVENT.DATE} {EVENT.TIME}
Alarm level:{TRIGGER.SEVERITY}
Warning information:{TRIGGER.NAME}
Question details:{ITEM.NAME}:{ITEM.VALUE}
Event code: {EVENT.ID}

Explanation: The default step is 1-1, which means starting from 1 and ending at 1. Once a failure occurs, the sendEmail.sh script is executed to send an alarm email to the Admin user and the zabbix administrator group. If the failure lasts for 1 hour, it will only be sent once. If it is changed to 1-0, 0 means no limit. The infinite sending interval is the default duration of 60 seconds. So in one hour, 60 emails will be sent.

3) Recovery operation

Fault resolved:{TRIGGER.STATUS}: {TRIGGER.NAME}
Restore host:{HOST.NAME}
Host address:{HOST.IP}
Recovery time: {EVENT.DATE} {EVENT.TIME}
Recovery Level: {TRIGGER.SEVERITY}
Recovery information:{TRIGGER.NAME}
Question details:{ITEM.NAME}:{ITEM.VALUE}
Event code: {EVENT.ID}


At this point our email alarm configuration is complete. As long as the trigger we set is triggered, an alarm email will be automatically sent to me.

9. Test email alert

1) Turn on the trigger

2) You can change the critical value of the trigger in the monitoring of available memory in the template that comes with Zabbix to greater than 20 and enter the template list

After the change

3) Modify the update time to make it faster to detect

4) View alarms

5) Email confirmation

If there is a problem sending emails, restart the server, zabbix-server and httpd services, and restart the zabbix-agent service on the client.

You may also be interested in:
  • Centos7.4 zabbix3.4.7 source code installation method and steps
  • How to install and deploy the latest version of Zabbix 3.4 on Centos 7.3 (picture and text)
  • Python3 implementation of Zabbix alarm push DingTalk example
  • How to implement email alert in zabbix

<<:  MySQL InnoDB MRR Optimization Guide

>>:  Vue implements a scroll bar style

Recommend

MySQL 5.7.27 winx64 installation and configuration method graphic tutorial

This article shares the installation and configur...

Some tips on using the HTML title attribute correctly

If you want to hide content from users of phones, ...

How to invert the implementation of a Bezier curve in CSS

First, let’s take a look at a CSS carousel animat...

Command to view binlog file creation time in Linux

Table of contents background analyze method backg...

Why can't my tomcat start?

Table of contents Phenomenon: Port usage: Spellin...

Discussion on default margin and padding values ​​of common elements

Today we discussed the issue of what the margin v...

Several ways to backup MySql database

mysqldump tool backup Back up the entire database...

Real-time refresh of long connection on Vue+WebSocket page

Recently, the Vue project needs to refresh the da...

Linux system (Centos6.5 and above) installation jdk tutorial analysis

Article Structure 1. Preparation 2. Install Java ...

How to detect if the current browser is a headless browser with JavaScript

Table of contents What is a headless browser? Why...

How to install suPHP for PHP5 on CentOS 7 (Peng Ge)

By default, PHP on CentOS 7 runs as apache or nob...

JavaScript pre-analysis, object details

Table of contents 1. Pre-analysis 1. Variable pre...