3reef 发表于 2014-4-22 21:17:26

zabbix企业应用之解决大量的nodata报警通知

研究与使用zabbix快1年了,其他功能都很多,最令我头痛的是如果机房的网络出现波动或者代理服务器出现问题,那么就会出现大量的服务器nodata报警,由于我采用邮件发送报警,邮件开通短信接收功能,基本出现大量nodata的报警就会造成手机死机(米3手机),为了解决这个问题测试过各自办法、1、设置trigger的依赖,如果使用多个zabbix对应多个proxy的话,配置很麻烦,不容易修改,所以放弃;2、使用自定义脚本报警,然后脚本里进行分析与处理,目前采用此方法。下面是使用第2种方法后,出现nodata问题的报警截图:下面是使用第2种方法后,nodata问题恢复后报警截图:如何实现:
一、服务端(zabbix web地址)1、是自定义脚本发送报警选择“管理”==》“示警媒体类型”==》“创建示警媒体类型”其中“脚本名称”里是使用的发送脚本名称,这个脚本的路径可以在客户端的zabbix_server.conf里定义,具体如何定义参考下面客户端设置。2、在动作(action)里做设置选择“配置”==》“动作”==》“创建动作”,”事件源“选择”触发器“。然后再选择”操作“==》“仅送到”==“E-mail”,这个E-mail是刚才“示警媒体”里定义的名字。二、客户端操作1、修改zabbix_server.conf1AlertScriptsPath=/usr/local/zabbix/bin修改脚本的路径2、把脚本放到/usr/local/zabbix/bin目录,并起名为zabbix_send_mail.sh,给与755权限,授予zabbix组与用户权限。

# cat /usr/local/zabbix/bin/zabbix_send_mail.sh#!/bin/bash. /etc/profileproblem_cmd="^PROBLEM.*system time out"recovery_cmd="^RECOVERY.*system time out"#echo "$3"|/bin/mail -s "$2" $1if [ `echo "$2"|egrep -E "$problem_cmd"|wc -l` -gt 0 ];thenecho "echo \"$3\"|/bin/mail -s \"$2\" $1" >>/tmp/zabbix_problem_mail.shelif [ `echo "$2"|egrep -E "$recovery_cmd"|wc -l` -gt 0 ];thenecho "echo \"$3\"|/bin/mail -s \"$2\" $1" >>/tmp/zabbix_recovery_mail.shelseecho "$3"|/bin/mail -s "$2" $1fi目前我这里设置如果发送的信息里有包含system time out内容的就重新定向给tmp目录的一个文件里(我这里的time out其实就是nodata,我这里规定nodate信息为system time out)3、设置nodata报警发送

# cat /usr/local/zabbix/bin/cront_send_mail.sh#!/bin/bash. /etc/profileproblem_file='/tmp/zabbix_problem_mail.sh'recovery_file='/tmp/zabbix_recovery_mail.sh'if [ ! -e $problem_file ];then    touch $problem_file    chown zabbix:zabbix $problem_filefiif [ ! -e $recovery_file ];then    touch $recovery_file    chown zabbix:zabbix $recovery_filefialert_value=15problem_value=`grep -c echo $problem_file`recovery_value=`grep -c echo $recovery_file`time=`date +%Y-%m-%d_%T`contact='244979152@qq.com'if [ $problem_value -lt $alert_value ];then    /bin/bash $problem_file    rm -rf $problem_file    rm -rf $problem_file-$alert_valueelif [ $problem_value -gt $alert_value ] && [ ! -e $problem_file-$alert_value ];then    echo "时间:$time 超时次数:$problem_value!"|/bin/mail -s "问题:灾难报警!机房出现大量超时报警!!!" $contact    rm -rf $problem_file    touch $problem_file-$alert_valueelif [ $problem_value -gt $alert_value ] && [ -e $problem_file-$alert_value ];then    rm -rf $problem_file    rm -rf $problem_file-$alert_valuefiif [ `grep -c echo $recovery_file` -lt $alert_value ];then    /bin/bash $recovery_file    rm -rf $recovery_file    rm -rf $recovery_file-$alert_value    rm -rf $problem_file-$alert_valueelif [ `grep -c echo $recovery_file` -gt $alert_value ] && [ ! -e $recovery_file-$alert_value ];then    echo "时间:$time 超时次数:$recovery_value!"|/bin/mail -s "恢复:灾难报警!机房出现大量超时报警!!!" $contact    rm -rf $recovery_file    rm -rf $problem_file-$alert_value    touch $recovery_file-$alert_valueelif [ `grep -c echo $recovery_file` -gt $alert_value ] && [ -e $recovery_file-$alert_value ];then    rm -rf $recovery_file    rm -rf $recovery_file-$alert_value    rm -rf $problem_file-$alert_valuefi我这里定义如果超过15次的system time out邮件,就只发送给我设置的244979152@qq.com,而且仅发送一封。4、crontab设置1*/2 * * * * /bin/bash /usr/local/zabbix/bin/cront_send_mail.sh这样就实现了以下需求:1、如果有大量的nodata报警,仅发送一封邮件;2、如果nodata报警回复,则也只发送一封邮件;3、设置简单,不需要修改trigger与action、模板。目前我这里测试的如果一个proxy挂了,出现大量proxy的主机nodata报警,也仅发送一封给我设置的报警邮箱,其他action里设置报警联系人不会受到。
页: [1]
查看完整版本: zabbix企业应用之解决大量的nodata报警通知