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 database optimization: index implementation principle and usage analysis

This article uses examples to illustrate the prin...

Study notes to write the first program of Vue

Table of contents 1. Write an HTML, the first Vue...

Linux disk sequential writing and random writing methods

1. Introduction ● Random writing will cause the h...

MySQL 5.7.21 winx64 installation and configuration method graphic tutorial

This article summarizes the notes for installing ...

my.cnf parameter configuration to optimize InnoDB engine performance

I have read countless my.cnf configurations on th...

Analyze the compilation and burning of Linux kernel and device tree

Table of contents 1. Prepare materials 2. Downloa...

Design reference WordPress website building success case

Each of these 16 sites is worth reading carefully,...

Native js to implement drop-down menu

Drop-down menus are also very common in real life...

Vue implements start time and end time range query

This article shares with you how to query the sta...

Detailed explanation of how MySQL (InnoDB) handles deadlocks

1. What is deadlock? The official definition is a...

js to call the network camera and handle common errors

Recently, due to business reasons, I need to acce...

Docker installs mysql and solves the Chinese garbled problem

Table of contents 1. Pull the mysql image 2. Chec...

CentOS7.5 installation tutorial of MySQL

1. First check whether the system has mysql insta...

Explore the truth behind the reload process in Nginx

Today's article mainly introduces the reload ...

HTML sample code for implementing tab switching

Tab switching is also a common technology in proj...