1、在zabbix主机上面添加计划任务
*/1 * * * * /home/pb/tengine_upstream.sh
cat /home/pb/tengine_upstream.sh
1 #!/bin/bash 2 ##香港代理 3 domain_status=`curl -s https://hk-proxy-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2,$4}‘` #将域名和当前的upstream状态取出来 例如 www.jcici.com up,域名有重复,因为有多条线路,包括电信,联通,bgp等 4 domain=`curl -s https://hk-proxy-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2}‘ | sort -u` #将所有的域名去重取出来 5 6 for i in `echo $domain` #将域名赋值给i 7 do 8 stauts=`echo "$domain_status" | grep "$i"` 9 ##status_2=`echo "$domain_status" | grep "$i" | awk ‘{print $2}‘` 10 status1=`echo "$domain_status"| grep $i | uniq | awk ‘{print $2}‘ | wc -l` #将每个域名对应的状态取出来,并删除重复的行,取出对应的行数,1:只有一行,要么为down,要么为up;2:行数为两行以上,有的线路up,有的线路down 11 status2=`echo "$domain_status"| grep $i | uniq | awk ‘{print $2}‘` #取出域名状态,3种情况 1:up 2:down 3:up和down同时存在 12 #status3=`echo "$domain_status"| grep $i | uniq | awk ‘{print $3}‘` 13 if [ "$status1" = 1 -a "$status2" = "down" ] #在域名状态为down并且行数只有一行时 14 then 15 echo "$i" #打印出来域名 16 if [ -n "$i" ] #如果i不为空 17 then 18 # zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "proxy-ip:192.168.32.230 domain:$i" &> /dev/null 19 aaa="proxy-ip:192.168.32.230 domain:$i" #将值以proxy-ip加ip的形式赋值给aaa 20 fi 21 # else 22 # echo "ok" 23 fi 24 done 25 26 27 28 ##东莞高防电信代理 29 gfdx_domain_status=`curl -s https://gfdx-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2,$4}‘` 30 gfdx_domain=`curl -s https://gfdx-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2}‘ | sort -u` 31 32 for o in `echo $gfdx_domain` 33 do 34 gfdx_stauts=`echo "$gfdx_domain_status" | grep "$o"` 35 ##status_2=`echo "$gfdx_domain_status" | grep "$o" | awk ‘{print $2}‘` 36 gfdx_status1=`echo "$gfdx_domain_status"| grep $o | uniq | awk ‘{print $2}‘ | wc -l` 37 gfdx_status2=`echo "$gfdx_domain_status"| grep $o | uniq | awk ‘{print $2}‘` 38 #gfdx_status3=`echo "$gfdx_domain_status"| grep $o | uniq | awk ‘{print $3}‘` 39 if [ "$gfdx_status1" = 1 -a "$gfdx_status2" = "down" ] 40 then 41 echo "$o" 42 if [ -n "$o" ] 43 then 44 # zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "proxy-ip:192.168.32.231 domain:$o" &> /dev/null 45 bbb="proxy-ip:192.168.32.231 domain:$o" 46 fi 47 # else 48 # echo "ok" 49 fi 50 done 51 52 53 54 ##东莞联通高防代理 55 gflt_domain_status=`curl -s https://gflt-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2,$4}‘` 56 gflt_domain=`curl -s https://gflt-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2}‘ | sort -u` 57 58 for m in `echo $gflt_domain` 59 do 60 gflt_stauts=`echo "$gflt_domain_status" | grep "$m"` 61 ##status_2=`echo "$gflt_domain_status" | grep "$m" | awk ‘{print $2}‘` 62 gflt_status1=`echo "$gflt_domain_status"| grep $m | uniq | awk ‘{print $2}‘ | wc -l` 63 gflt_status2=`echo "$gflt_domain_status"| grep $m | uniq | awk ‘{print $2}‘` 64 #gflt_status3=`echo "$gflt_domain_status"| grep $m | uniq | awk ‘{print $3}‘` 65 if [ "$gflt_status1" = 1 -a "$gflt_status2" = "down" ] 66 then 67 echo "$m" 68 if [ -n "$m" ] 69 then 70 # zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "proxy-ip:192.168.32.232 domain:$m" &> /dev/null 71 ccc="proxy-ip:192.168.32.232 domain:$m" 72 fi 73 # else 74 # echo "ok" 75 fi 76 done 77 78 79 80 ##香港高防代理 81 gfhk_domain_status=`curl -s https://gfhk-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2,$4}‘` 82 gfhk_domain=`curl -s https://gfhk-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2}‘ | sort -u` 83 84 for n in `echo $gfhk_domain` 85 do 86 gfhk_stauts=`echo "$gfhk_domain_status" | grep "$n"` 87 ##status_2=`echo "$gfhk_domain_status" | grep "$n" | awk ‘{print $2}‘` 88 gfhk_status1=`echo "$gfhk_domain_status"| grep $n | uniq | awk ‘{print $2}‘ | wc -l` 89 gfhk_status2=`echo "$gfhk_domain_status"| grep $n | uniq | awk ‘{print $2}‘` 90 #gfhk_status3=`echo "$gfhk_domain_status"| grep $n | uniq | awk ‘{print $3}‘` 91 if [ "$gfhk_status1" = 1 -a "$gfhk_status2" = "down" ] 92 then 93 echo "$n" 94 if [ -n "$n" ] 95 then 96 # zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "proxy-ip:192.168.32.233 domain:$n" &> /dev/null 97 ddd="proxy-ip:103.197.69.64 domain:$n" 98 fi 99 # else 100 # echo "ok" 101 fi 102 done 103 104 105 ##江苏bgp高防代理 106 gfbgp_domain_status=`curl -s https://gfbgp-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2,$4}‘` 107 gfbgp_domain=`curl -s https://gfbgp-monitoring.zhiduntech.com/status?format=csv | awk -F, ‘{print $2}‘ | sort -u` 108 109 for p in `echo $gfbgp_domain` 110 do 111 gfbgp_stauts=`echo "$gfbgp_domain_status" | grep "$p"` 112 ##status_2=`echo "$gfbgp_domain_status" | grep "$p" | awk ‘{print $2}‘` 113 gfbgp_status1=`echo "$gfbgp_domain_status"| grep $p | uniq | awk ‘{print $2}‘ | wc -l` 114 gfbgp_status2=`echo "$gfbgp_domain_status"| grep $p | uniq | awk ‘{print $2}‘` 115 #gfbgp_status3=`echo "$gfbgp_domain_status"| grep $p | uniq | awk ‘{print $3}‘` 116 if [ "$gfbgp_status1" = 1 -a "$gfbgp_status2" = "down" ] 117 then 118 echo "$p" 119 if [ -n "$p" ] 120 then 121 # zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "proxy-ip:192.168.32.234 domain:$n" &> /dev/null 122 eee="proxy-ip:103.60.165.67 domain:$p" 123 fi 124 # else 125 # echo "ok" 126 fi 127 done 128 129 130 if [ -n "$aaa" -o -n "$bbb" -o -n "$ccc" -o -n "$ddd" -o -n "$eee" ] 131 then 132 zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "$aaa $bbb $ccc $ddd $eee" &> /dev/null #如果任意一个有值,就会将值发给zabbix server。 133 else 134 zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "OK" &> /dev/null #如果所有的都没值,否则就发送OK给zabbix server。 135 fi
tenginx_upstream.sh
2、zabbix server
脚本发送值可以在lastst data里面查看到
添加Items
Type:Zabbix trapper
key:tengine.status #之前脚本里面发送过来的 是以tengine.status这个key发送过来的
Type of information:Text
添加Triggers
Name:tengine_upstream 主机down {ITEM.VALUE} #ITEM.VALUE为变量值
Expression:{Zabbix server:tengine.status.count(#3,"OK","ne")}=3 #取3次值,当取到的3次值都不等于OK时,触发报警
原文地址:https://www.cnblogs.com/jcici/p/8966454.html
时间: 2024-10-11 21:05:16