zabbix監控tengine upstream狀態
阿新 • • 發佈:2018-04-28
mar weight RM trigger -i 刪除 聯通 don orm
zabbix監控tengine upstream狀態
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等tenginx_upstream.sh4 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
2、zabbix server
腳本發送值可以在lastst data裏面查看到
添加Items
Type:Zabbix trapper
key:tengine.status #之前腳本裏面發送過來的 是以tengine.status這個key發送過來的
添加Triggers
Name:tengine_upstream 主機down {ITEM.VALUE} #ITEM.VALUE為變量值
Expression:{Zabbix server:tengine.status.count(#3,"OK","ne")}=3 #取3次值,當取到的3次值都不等於OK時,觸發報警
zabbix監控tengine upstream狀態