1. Zabbix报警设置
zabbix报警设置步骤是比较复杂的,需要设置报警媒介、报警动作、报警内容
1. 设置报警媒介
2. 设置报警动作
3. 设置报警内容
[{EVENT.DATE} {EVENT.TIME}] # 时间
[{TRIGGER.NAME}] # 报警内容
[{ITEM.VALUE}] # Item当前值
4. 导出IP和报警人的对应关系(每个人名下的机器不同)
[@bjsjs_115_94 scripts]# cat machine_contact_dump.sh
#!/bin/bash
DBHOST="10.139.26.124"
USER="platform"
PASSWD="2017Platform"
DBNAME="op"
TABLE="machine"
MYSQL="mysql -u$USER -p$PASSWD -h$DBHOST -D$DBNAME"
tmp_file="tmp_contact_list.txt"
zabbix_file="zabbix_contact_list.txt"
$MYSQL -e "select ip,nagios_contact,password from machine" > ${tmp_file}
if [ $? -eq 0 -a -s ${tmp_file} ];then
rsync -aP ${tmp_file} ${zabbix_file}
else
/opt/monitor/sendsms.sh "zabbix Connection to the platform database(machine) failed" "song"
exit
fi
[@bjsjs_115_94 scripts]#
5. 发送报警
[@bjsjs_115_94 alertscripts]# cat /search/zabbix/alertscripts/sendsms.sh
#!/bin/bash
set -x
exec >> /tmp/exec_zabbix 2>&1
ZBX_DIS="zabbix_disable.sh"
PREFIX="/search/zabbix/alertscripts"
CONTACT_FILE="/search/zabbix/scripts/zabbix_contact_list.txt"
SENDSMS="/opt/monitor/sendsms.sh"
ALTER=$(echo $*|sed 's/\r//g')
UNREACH="is unreachable for 30 minutes"
IP=$(echo $ALTER|awk '{split($2,host,":");print host[2]}')
RECEIVER="$(awk '$1 ~ /'$IP'/{print $2}' $CONTACT_FILE)"
cd $PREFIX
if [[ "$ALTER" =~ "$UNREACH" ]];then
echo "$IP"
sudo -u root sh -x "$ZBX_DIS" "$IP">> disable_host.log 2>&1
fi
if [[ "x$RECEIVER" != "x" && "$RECEIVER" != "NULL" ]];then
$SENDSMS "$ALTER" "$RECEIVER"
fi
[@bjsjs_115_94 alertscripts]#