12 Zabbix4.4.1系统sendEmail邮件报警优化

点击返回:自学Zabbix之路

点击返回:自学Zabbix4.0之路

点击返回:自学zabbix集锦

12 Zabbix4.4.1系统sendEmail邮件报警优化

接上一章节  Zabbix4.4.0系统教你实现sendEmail邮件报警

1. 测试时告警的脚本

#!/bin/bash
to=$1        
subject=$2   
message=$3   
#url=$4
/usr/local/bin/sendEmail -f zabbix_yk@163.com -t "$to" -s smtp.163.com -u "$subject" -o message-content-type=html -o message-charset=utf8 -xu zabbix_yk@163.com -xp ************ -m "$message" 

 测试发现告警邮件的内容造成运维人员极度不适。

2. 优化后告警的脚本

 参数赋值后,告警按行输出。

#!/bin/bash

SMTP_server='smtp.163.com'
username='zabbix_yk@163.com'
password='**********'
from_email_address='zabbix_yk@163.com'
to_email_address="$1"
message_subject_utf8="$2"
message_body_utf8="$3"

message_subject_gb2312=`iconv -t GB2312 -f UTF-8 << EOF
$message_subject_utf8
EOF`
[ $? -eq 0 ] && message_subject="$message_subject_gb2312" || message_subject="$message_subject_utf8"

message_body_gb2312=`iconv -t GB2312 -f UTF-8 << EOF
$message_body_utf8
EOF`
[ $? -eq 0 ] && message_body="$message_body_gb2312" || message_body="$message_body_utf8"

sendEmail='/usr/local/bin/sendEmail'
set -x
$sendEmail -s "$SMTP_server" -xu "$username" -xp "$password" -f "$from_email_address" -t "$to_email_address" -u "$message_subject" -m "$message_body" -o message-content-type=text -o message-charset=gb2312 

优化后邮件告警内容排版:

 

 

 ......

posted on 2019-11-08 15:50  CARLOS_CHIANG  阅读(516)  评论(0编辑  收藏

导航