Zabbix implements email alerts

Zabbix implements email alerts

This article uses the 163 mailbox to implement the mailbox alarm of zabbix.
The prerequisite for realizing the alarm is to enable the IMAP/SMTP service of the 163 mailbox and record the authorization password. The operation is as follows:
Insert image description here

1. Install the software on zabbix-server: mailx

[root@zabbix-server ~]# yum -y install mailx

2. Configure /etc/mail.re

[root@zabbix-server ~]# vim /etc/mail.rc
Insert image description here

set from=yuzhang0304@163.com  #邮箱地址
set smtp=smtp.163.com
set smtp-auth-user=yuzhang0304@163.com  #邮箱地址
set smtp-auth-password=TKDXDXELOIKPQMCO  #邮箱地址授权密码
set smtp-auth=login
3. Test

Method 1: mailx -s "Mail title" Inbox Email < file containing the body
Method 2: cat file containing the body | mailx -s "Mail title" Inbox Email
Method 3: echo "Text content" | mailx - s "Email Title" Inbox Email
Method 4: mailx -s "Email Title" Inbox Email, press Enter and press CTRL+D to send

[root@zabbix-server ~]# mail -s "test1" [email protected] < /root/anaconda-ks.cfg
[root@zabbix-server ~]# cat /root/anaconda-ks.cfg | mail -s "tes2" [email protected]
[root@zabbix-server ~]# echo "hello" | mail -s "test3" [email protected]
Insert image description here

4. Write a script to send emails on the zabbix-server side

[root@zabbix-server ~]# cd /usr/lib/zabbix/alertscripts/
[root@zabbix-server alertscripts]# vim sentmail.sh
[root@zabbix-server alertscripts]# chmod 777 sentmail.sh
[root@zabbix-server alertscripts]# chown zabbix:zabbix sentmail.sh
Insert image description here
This script sends emails through method three. $3 represents the content of the email sent, $2 represents the email subject, and $1 represents the email address.

5. Complete the configuration of zabbix mailbox alarm on the web interface of zabbix-server

① Create alarm media

Insert image description here

Insert image description here

②Create action

Create an action to send an email and associate the action with a trigger (the trigger needs to be created in advance), that is, when the trigger is triggered, the email will be sent.
Insert image description here

Insert image description here

Insert image description here
Insert image description here

Insert image description here
Action has been created

③Create a user and let the user associate the alarm media (the default user admin is used here)
Insert image description here

Insert image description here
Insert image description here

Insert image description here

6. Simulate faults according to the monitoring items corresponding to the triggers

What I use here is a trigger created in advance to monitor the running status of nginx. Close the nginx service in zabbix-agent to simulate a fault to trigger the trigger and send an email alert.

[root@zabbix-agent ~]# systemctl stop nginx
Insert image description here
Alarm generated

Go to the mailbox to check the alarm information.
Insert image description here
Insert image description here
If you receive the alarm information, it means that zabbix has successfully implemented the mailbox alarm.

Guess you like

Origin blog.csdn.net/weixin_44178770/article/details/124743972