zabbix email alert

1. Install mailx

yum install mailx -y

Edit the /etc/mail.rc file and add at the end of the file

set [email protected]  # 发送的邮件地址
set smtp=smtp.qq.com:587  # 发送邮件服务器
set [email protected]  # 发件人账号
set smtp-auth-password=xxxxxxxx  # 发件人密码或者是授权码
set smtp-auth=login  # 邮件认证方式
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/

send email

The email was sent successfully, but there is an error that has not been resolved yet.

2. Write the script to send the email

vim /etc/zabbix/zabbix_server.conf (zabbix installation directory), the directory of the script

Send mail script sendMail.sh

#!/bin/bash
 
mail=$1
title=$2
message=$3
 
echo "${message}" | /usr/bin/iconv -t GB2312 -f UTF-8 | mailx -s "${title}" ${mail} >> /tmp/mailx.log 2>&1
 
exit $?

Give the script power and test the script./sendEmail.sh [email protected] "test_title" "test_content"

chown  zabbix.zabbix /tmp/mailx.log

The mail has been received, now start configuring zabbix

Add alert media type

Add user

Since I'm using a super administrator, I don't have to set permissions anymore.

Next configure the action

The content sent by the modification action is Chinese. The default is the same as recovery.

告警主机:{HOSTNAME1}
 
告警时间:{EVENT.DATE} {EVENT.TIME}
 
告警等级:{TRIGGER.SEVERITY}
 
告警信息: {TRIGGER.NAME}
 
告警项目:{TRIGGER.KEY1}
 
问题详情:{ITEM.NAME}:{ITEM.VALUE}
 
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
 
事件ID:{EVENT.ID}

click action

The template of logging in more than three people was added before, now logging in to a host with more than three connections

The email was sent, but the email content became an attachment.

You can refer to https://blog.csdn.net/fgf00/article/details/50583256

yum install dos2unix -y

Modify sendEmail.sh

#!/bin/bash

FILE=/tmp/mailtmp.txt
echo "$3" >$FILE
dos2unix -k $FILE     #解决了发送的邮件内容变成附件的问题。
/bin/mail -s "$2" $1 < $FILE

incoming mail:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324398176&siteId=291194637