ITPub博客

首页 > 应用开发 > IT综合 > Goldengate for nrpe监控脚本

Goldengate for nrpe监控脚本

IT综合 作者:urgel_babay 时间:2016-05-11 17:11:27 0 删除 编辑
Goldengate for nrpe监控脚本


/usr/bin/sudo /usr/local/nagios/libexec/check_gghealth -d ebpdb -w 60 -c 180
最新版:增加对时间判断

点击(此处)折叠或打开

  1. #!/bin/bash
  2. # ========================================================================================
  3. # goldengate health plugin for Nagios
  4. #
  5. # Written by : dudong
  6. # Release : 1.0.0
  7. # Creation date : 2015-02-11
  8. # Description : Nagios plugin (script) to check goldengate health .
  9. # This script has been designed and written on Linux System.
  10. #
  11. # USAGE : ./check_gg_health.sh [-d (disk)]
  12. #
  13. # Exemple: ./check_cpu_stats.sh
  14. #
  15. #
  16. # HISTORY :
  17. # Release | Date | Authors | Description
  18. # --------------+---------------+----------------------+-----------------------------------
  19. # 1.0.0 | 2015.02.11 | | Create the script
  20. # -----------------------------------------------------------------------------------------
  21. # NOTICE:
  22. #-----------------------------------------------------------------------------------------
  23. # You should have the root Permissions ,You can use sudo to realize .
  24. # -----------------------------------------------------------------------------------------

  25. # Nagios return codes
  26. DATABASE=
  27. WARNING=
  28. CRITICAL=

  29. BRIEF=0
  30. SILENT=0

  31. #定义 nagios返回的状态变量
  32. STATE_OK=0
  33. STATE_WARNING=1
  34. STATE_CRITICAL=2
  35. STATE_UNKNOWN=3

  36.  # 插件描述信息
  37. PROGNAME=\"check_gghealth\"
  38. RELEASE=\"Revision 1.0.0\"
  39. AUTHOR=\"(c) 2015 \"

  40. # Functions plugin usage
  41. # 插件的使用方法函数

  42. print_release() {
  43.     echo \"$RELEASE $AUTHOR\"
  44. }

  45. print_usage() {
  46.         echo \"\"
  47.         echo \"$PROGNAME $RELEASE - Goldengate health check script for Nagios\"
  48.         echo \"\"
  49.         echo \"Usage: check_gghealth\"
  50.         echo \"\"
  51.         echo \" -d database\"
  52.         echo \"\"
  53.         echo \" -w warning\"
  54.         echo \"\"
  55.         echo \" -c critical\"
  56.         echo \"\"
  57.         echo \" -h Show this page\"
  58.         echo \"\"
  59.         echo \"\"
  60.         echo \" -v check the version\"
  61.     echo \"Usage: $PROGNAME\"
  62.     echo \"Usage: $PROGNAME --help\"
  63.     echo \"\"
  64.     exit 0
  65. }

  66. print_help() {
  67.         print_usage
  68.         echo \"\"
  69.         echo \"This plugin will check gg health \"
  70.         echo \"\"
  71.         exit 0
  72. }


  73. # 传递参数

  74. # process args
  75. while [ ! -z \"$1\" ]; do
  76.     case $1 in
  77.         -b) BRIEF=1 ;;
  78.         -s) SILENT=1 ;;
  79.         -d) shift; DATABASE=$1; DATABASE=${1////!} ;;
  80.         -w) shift; WARNING=$1 ;;
  81.         -c) shift; CRITICAL=$1 ;;
  82.         -h) show_help; exit 1 ;;
  83.     esac
  84.     shift
  85. done


  86. # 生效变量文件
  87. #SIDNAME=ebpdb
  88. cd /home/oracle
  89. . ./prof_$DATABASE
  90. cd $OGG_HOME

  91. mkdir -p /tmp/ggcheck/
  92. echo \"info all\" | ./ggsci |grep -E \"MANAGER|EXTRACT|REPLICAT\" > /tmp/ggcheck/gginfo.tmp
  93. chmod 776 /tmp/ggcheck/gginfo.tmp
  94. cd /tmp
  95. filename_tmp=/tmp/ggcheck/gginfo.tmp

  96. awk -F\':|[ ]+|[ ][ ]+\' \'{sum=($4+$7)*3600+($5+$8)*60+($6+$9);print $0,sum}\' $filename_tmp > /tmp/ggcheck/gginfo.sum

  97. filename=/tmp/ggcheck/gginfo.sum

  98. #获取manage进程状态信息
  99. #head -1 $filename > /tmp/ggcheck/manage_message
  100. #manage_status=$(cat /tmp/ggcheck/manage_message | grep \"RUNNING\" | wc -l)
  101. manage_status=$( head -1 $filename | grep \"RUNNING\" | wc -l)


  102. #获取所有进程时间信息
  103. sed -i \'1d\' $filename
  104. message_ok=$(awk -F\':|[ ]+|[ ][ ]+\' \'{print $3\"=\" $10\"s\"\" \"}\' $filename)
  105. #echo $message_ok |sed \'N;s/\\n//g\' > /tmp/ggcheck/ok_msg
  106. #ok_msg=$(cat /tmp/ggcheck/ok_msg)
  107. ok_msg=$(echo $message_ok |sed \'N;s/\\n//g\')

  108. #len= sed -n \'$=\' $filename


  109. #获取时间信息
  110. #awk -F\':|[ ]+|[ ][ ]+\' \'{print $10}\' $filename > /tmp/ggcheck/time_msg


  111. #
  112. NUM1=$(cat $filename | grep \"ABENDED\" | wc -l)
  113. NUM2=$(cat $filename | grep \"STOPPED\" | wc -l)

  114. #进程挂起信息
  115. #find $filename |xargs grep -ri \"ABENDED\" > /tmp/ggcheck/abended.msg
  116. #ABENDED_MSG=$(awk \'{print $3, \"is abended, and lag time is \" $6\"!\"}\' /tmp/ggcheck/abended.msg)
  117. ABENDED_MSG=$(find $filename |xargs grep -ri \"ABENDED\" |awk \'{print $3, \"is abended, and lag time is \" $6\"!\"}\')

  118. MESSAGE2=$(find $filename |xargs grep -ri \"STOPPED\")
  119. MESSAGE3=$(find $filename |xargs grep -ri \"RUNNING\")


  120. #echo \"$WARNING\"
  121. #echo \"$CRITICAL\"
  122. #echo \"$DATABASE\"

  123. #时间文件内是否有大于warning和critical的数字
  124. #WARNING_STATUS=$( cat /tmp/ggcheck/time_msg | while read i; do if [[ \"$i\" -ge \"$WARNING\" ]]; then echo $i; fi; done | wc -l)
  125. #CRITICAL_STATUS=$( cat /tmp/ggcheck/time_msg | while read i; do if [[ \"$i\" -ge \"$CRITICAL\" ]]; then echo $i; fi; done | wc -l)
  126. WARNING_STATUS=$( awk -F\':|[ ]+|[ ][ ]+\' \'{print $10}\' $filename | while read i; do if [[ \"$i\" -ge \"$WARNING\" ]]; then echo $i; fi; done | wc -l)
  127. CRITICAL_STATUS=$( awk -F\':|[ ]+|[ ][ ]+\' \'{print $10}\' $filename | while read i; do if [[ \"$i\" -ge \"$CRITICAL\" ]]; then echo $i; fi; done | wc -l)


  128. if [ \"$manage_status\" = \"0\" ]; then
  129.        echo \"Critical - Goldengate Manage process is stopped!!\"
  130.        exit $STATE_CRITICAL

  131. elif [ \"$NUM1\" -ne \"0\" ]; then
  132.    echo \"CRITICAL - Goldengate status is critical,\" \"$ABENDED_MSG | \" \"$ok_msg\"
  133.    exit $STATE_CRITICAL

  134. else
  135. # cat /tmp/ggcheck/time_msg | while read i
  136. # for i in \'cat /tmp/ggcheck/time_msg\'
  137. # do
  138. # if [[ \"$i\" -lt \"$WARNING\" ]]; then
  139. # if [ `echo $i | awk -v bi=$WARNING \'{print($1<bi)?\"1\":\"0\"}\'` -eq \"1\" ]; then
  140. # echo \"OK - Goldengate status is ok | \" \"$ok_msg\"
  141. # exit $STATE_OK
  142. # elif [[ \"$i\" -ge \"$WARNING\" && \"$i\" -le \"$CRITICAL\" ]]; then
  143. # echo \"WARNING - Goldengate status is WARNING | \" \"$ok_msg\"
  144. # exit $STATE_WARNING
  145. # else
  146. # echo \"CRITICAL - Goldengate status is CRITICAL | \" \"$ok_msg\"
  147. # exit $STATE_CRITICAL
  148. # fi
  149. # done
  150.    if [ \"$CRITICAL_STATUS\" -ne \"0\" ]; then
  151.         echo \"CRITICAL - Goldengate status is CRITICAL | \" \"$ok_msg\"
  152.         exit $STATE_CRITICAL
  153.    
  154.    elif [ \"$WARNING_STATUS\" -ne \"0\" ]; then
  155.         echo \"WARNING - Goldengate status is WARNING | \" \"$ok_msg\"
  156.         exit $STATE_WARNING
  157.    
  158.    else
  159.         echo \"OK - Goldengate status is ok | \" \"$ok_msg\"
  160.         exit $STATE_OK

  161.    fi

  162. fi
  163. #
  164. #






来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30936525/viewspace-2097981/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2016-02-29

  • 博文量
    203
  • 访问量
    217859