博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zabbix监控tengine upstream状态
阅读量:6706 次
发布时间:2019-06-25

本文共 7362 字,大约阅读时间需要 24 分钟。

zabbix监控tengine upstream状态

公司nginx代理中,每个域名都会有几条线路,现需要在几条线路同时不通的时候,会触发zabbix报警。

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 #      else100 #              echo    "ok"101         fi102 done103 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 do111 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         then118                 echo    "$p"119                         if [ -n "$p" ]120                                 then121 #                                zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "proxy-ip:192.168.32.234 domain:$n" &> /dev/null122                                  eee="proxy-ip:103.60.165.67 domain:$p"123                         fi124 #      else125 #              echo    "ok"126         fi127 done128 129 130 if      [ -n "$aaa" -o -n "$bbb" -o -n "$ccc" -o -n "$ddd" -o -n "$eee" ]131                 then132                         zabbix_sender -s "Zabbix server" -z ${zabbix_server} -k "tengine.status" -o "$aaa $bbb $ccc $ddd $eee" &> /dev/null    #如果任意一个有值,就会将值发给zabbix server。133                 else134                         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

你可能感兴趣的文章
html中ul标签的优化
查看>>
Kurento安装与入门05——One to many video call
查看>>
[deviceone开发]-cnodejs论坛移动端App
查看>>
智能指针shared_ptr(effective modern c++笔记)
查看>>
Failed to validate a newly established connection异常
查看>>
关联对象 AssociatedObject 完全解析
查看>>
POST 后台404错误
查看>>
Ubuntu 解压zip文件名乱码问题解决
查看>>
动态规划
查看>>
Hibernate的延迟加载
查看>>
IE中input标签密码框与文本框宽度不一样问题
查看>>
【系统架构师修炼之道】(10):绪论——系统架构师的定义与职业素质
查看>>
Uber 开源地理可视化工具 Ketoper.gl,加速数据处理
查看>>
NSDate格式化小例
查看>>
运维不容错过的4个关键指标!
查看>>
spring 基础
查看>>
商品详情页上拉查看详情
查看>>
Kubernetes DNS服务简介
查看>>
windbg调试堆破坏
查看>>
How to Install CMS Made Simple v2.2 on LAMP in CentOS 7.2
查看>>