Home  >  Article  >  Operation and Maintenance  >  Zabbix implementation of email alarm example tutorial

Zabbix implementation of email alarm example tutorial

PHP中文网
PHP中文网Original
2017-06-21 11:15:032501browse

Description:

Zabbix monitoring server and client have been deployed, the monitored host has been added, and Zabiix monitoring is running normally.

Purpose:

Set an email alarm on the Zabbix server. When the monitored host goes down or reaches the trigger preset value, an alarm email will be automatically sent to Specify email address.

Specific operations:

The following operations are performed on the Zabbix monitoring server

Remarks: Zabbix monitoring server

Operating system: CentOS

Use an external email account to send alarm emails settings:

1. Close sendmail or postfix

service sendmail stop #Close

chkconfig sendmail off #Prohibit Start at boot

service postfix stop

chkconfig postfix off

Note:

When using an external email account, there is no need to start sendmail or postfix

If you use an external mailbox to send alarm emails while sendmail or postfix is ​​started, the external mailbox

configuration information will be read first.

2. Install the mail sending tool mailx

yum install mailx #Install

CentOS 5.x Compile and install mailx. The mailx version installed directly by yum is too old, use external mail There will be problems with sending.

yum remove mailx #Uninstall the old version of mailx that comes with the system

Download mailx:


tar jxvf mailx-12.4.tar.bz2 #Unzip

cd mailx-12.4 #Enter directory

make #Compile

make install UCBINSTALL=/usr/bin/install #Install

ln - s /usr/local/bin/mailx /bin/mail #Create a soft connection from mailx to mail

ln -s /etc/nail.rc /etc/mail.rc #Create a soft connection to the mailx configuration file

3. Configure Zabbix server external mailbox

vi /etc/mail.rc #Edit and add the following information

set from=xxx@163.com smtp=smtp. 163.com //Add the sender and sending server

set smtp-auth-user=xxx@163.com smtp-auth-password=123456 //Add the sending email address and login password.

set smtp-auth=login

:wq! #Save and exit

echo "zabbix test mail" |mail -s "zabbix" yyy@163.com

#Test sending an email, title zabbix, email content: zabbix test mail, email sent to: yyy@163.com

#At this time, the email yyy@163.com will receive a message from xxx Test email from @163.com

4. Configure Zabbix server email alarm

1. Open Zabbix

Management-Alert Media Type-Create Media Type

Name: Sendmail

Type: Script

Script name: sendmail.sh

Enabled: Check

Archive

2. Set Zabbix user alarm email address

Type: Sendmail

Recipient: xxx@163.com

Other defaults are acceptable, or

Set as needed

Status: Enabled

Archive

3. Set the action for Zabbix to trigger the alarm

Configuration-Action-Create Action

Name: Action-Email

Default recipient: Failure {TRIGGER.STATUS}, Server: {HOSTNAME1} Occurrence: {TRIGGER.NAME} failure !

Default information:

Alarm host: {HOSTNAME1}

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}

Restore information: check

Restore purpose: Restore {TRIGGER.STATUS}, Server: {HOSTNAME1}: {TRIGGER.NAME} has been restored !

Recovery information:

Alarm host: {HOSTNAME1}

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}

Enabled: Tick

Switch to operation option

New

Operation type: Send message

Send to user: Add

Default information: Check

Select user: Admin

Select

Send only to: Sendmail

Archive

4. Add Zabbix server email sending script

cd /usr/local/zabbix/share/zabbix/alertscripts #Enter the script storage directory

vi sendmail.sh #Edit and add the following code

#!/bin/sh

echo "$3" | mail -s "$2" $1

:wq! #Save and exit

chown -R zabbix.zabbix Add the relative path of the script to the /usr/local/zabbix/share/zabbix/alertscripts/*

zabbix_server.conf file

AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts

#Set the script owner as the zabbix user

chmod +x /usr/local/zabbix/share/zabbix/alertscripts/sendmail.sh

#Set the script execution permissions

5. Test Zabbix alarm

Close Zabbix client service

service zabbix_agentd stop

Check your xxx@163.com mailbox and you will receive an alarm email

Restart Zabbix client service

service zabbix_agentd start

Check your xxx@163.com mailbox, you will receive a recovery email

Use an external mailbox The settings for sending alarm emails to the account are completed.

At this point, the Zabbix email alarm setting is completed.

The above is the detailed content of Zabbix implementation of email alarm example tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn