Goldengate for nrpe監控指令碼

urgel_babay發表於2016-05-11
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章