Get the App
SLTechnology News&Howtos  ›  Servers  › 

Zabbix4 configure email alert notification

Shulou Source: shulou.com Published: 2022-06-03 09:00:57 12月06日 Update

Environment:

OS:centos7.4

Zabbix Server:zabbix_server (Zabbix) 4.0.14

1. Mail configuration

Confirm that the mail sending tool is installed

Yum install mailx-y

Configure / etc/mail.rc, and add configuration items to the tail:

# Add mail-conf by yuhuanghuiset from=stupidking123@163.comset smtp=smtp.163.comset smtp-auth-user=123456set smtp-auth-password=password1 # authorization code set smtp-auth=loginset ssl-verify=ignore

Mail authorization

Chown-R zabbix:zabbix / etc/mail.rc

Note: the mail cannot be sent because the file is not authorized here. The action log in zabbix Web shows that it has been sent, but in fact, the mailbox has not been received.

In addition to activating the SMTP service, you also need to activate the authorization code to log in. The above configuration is no longer the login password, but the authorization code. Choose 163 mailbox to send here.

two。 Write a script for sending mail

Cd / usr/lib/zabbix/alertscripts

Vim mail-send.sh

#! / bin/bashmessages= `echo $3 | tr'\ r\ n'\ n' `subject= `echo $2 | tr'\ r\ n''\ n' `echo "${messages}" | mailx-s "${subject}" $1 > > / tmp/sendmail.log 2 > & 1

Modify permissions

Chown-R zabbix:zabbix mail-send.sh

Chomod + x mail-send.sh

Chown-R zabbix:zabbix / tmp/sendmail.log

Test delivery:

Su-zabbix switching zabbix user

Sh / usr/lib/zabbix/alertscripts/mail-send.sh abc@xxx.com "zabbix test mail"test"

Check the mailbox to receive the email, indicating that the script was sent successfully.

3. Configure web on zabbix page

Manage-> alarm Media Type-> create Media Type

Add three script parameters:

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

The script name must be the same as the script name configured with / usr/lib/zabbix/alertscripts on zabbix server.

4. Create a user

Manage-> users

Management-> users-> alarm media

5. Create an action configuration

Configure-> Action-> Action

Create email sending action and configure trigger condition: trigger warning degree is greater than or equal to warning

Configure-> Action-> Action

Default title:

Fault {TRIGGER.STATUS}, server name: {HOSTNAME1} occurred: {TRIGGER.NAME} failure!

Message content:

Alarm host: {HOSTNAME} alarm host IP address: {HOST.IP} alarm time: {EVENT.DATE} {EVENT.TIME} alarm level: {TRIGGER.SEVERITY} alarm information: {TRIGGER.NAME} alarm item: {TRIGGER.KEY1} problem details: {ITEM.NAME}: {ITEM.VALUE} current status: {TRIGGER.STATUS}: {ITEM.VALUE1} event ID: {EVENT.ID}

Configure-> Action-> restore

Default title

Restore {TRIGGER.STATUS}, server name: {HOSTNAME1}: {TRIGGER.NAME} has been restored!

Message content

Alarm host: {HOSTNAME} alarm host IP address: {HOST.IP} alarm time: {EVENT.DATE} {EVENT.TIME} alarm level: {TRIGGER.SEVERITY} alarm information: {TRIGGER.NAME} alarm item: {TRIGGER.KEY1} problem details: {ITEM.NAME}: {ITEM.VALUE} current status: {TRIGGER.STATUS}: {ITEM.VALUE1} event ID: {EVENT.ID}

Verify that the action created is enabled:

6. test

Turn off the zabbix-agnet service of the client server

Systemctl stop zabbix-agent.service shuts down the service

Wait for 5 minutes to check in the email.

Tags: Configuration actions mail services scripts hosts users media servers mailboxes management events information content name address failure time title message Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Shulou Tech Info MariaDB Shulou Information