Check_nrpe外掛之check_uptime.sh檢測系統啟動時間

Michael_DD發表於2015-05-20
Check_nrpe外掛之check_uptime.sh檢測系統啟動時間


check_uptime.sh

點選(此處)摺疊或開啟

  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 uptime .
  9. # This script has been designed and written on Linux System.
  10. #
  11. # USAGE : ./check_uptime.sh 365 500
  12. #
  13. # Exemple: ./check_uptime.sh
  14. #
  15. #
  16. # HISTORY :
  17. # Release | Date | Authors | Description
  18. # --------------+---------------+----------------------+-----------------------------------
  19. # 1.0.0 | 2015.05.18 | dudong | 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. WARNING=
  27. CRITICAL=

  28. BRIEF=0
  29. SILENT=0

  30. #定義 nagios返回的狀態變數
  31. STATE_OK=0
  32. STATE_WARNING=1
  33. STATE_CRITICAL=2
  34. STATE_UNKNOWN=3

  35.  # 外掛描述資訊
  36. PROGNAME=\"check_uptime\"
  37. RELEASE=\"Revision 1.0.0\"
  38. AUTHOR=\"(c) 2015 dudong\"

  39. # Functions plugin usage
  40. # 外掛的使用方法函式

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

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

  63. print_help() {
  64.         print_usage
  65.         echo \"\"
  66.         echo \"This plugin will check uptime \"
  67.         echo \"\"
  68.         exit 0
  69. }


  70. # 傳遞引數

  71. # process args
  72. while [ ! -z \"$1\" ]; do
  73.     case $1 in
  74.         -b) BRIEF=1 ;;
  75.         -s) SILENT=1 ;;
  76.         -w) shift; WARNING=$1 ;;
  77.         -c) shift; CRITICAL=$1 ;;
  78.         -h) show_help; exit 1 ;;
  79.     esac
  80.     shift
  81. done

  82. #獲取啟動時間
  83. UPDATE=$( uptime | awk \'{print $3}\')


  84. #判斷
  85. if [[ $UPDATE -ge $CRITICAL ]]; then
  86.        echo \"Critical - This system have been up for $UPDATE days | days=$UPDATE\"
  87.        exit $STATE_CRITICAL

  88. elif [[ $UPDATE -ge $WARNING ]]; then
  89.   echo \"Warning - This system have been up for $UPDATE days | days=$UPDATE\"
  90.    exit $STATE_WARNING

  91. else
  92.    echo \"OK - This system have been up for $UPDATE days | days=$UPDATE\"
  93.    exit $STATE_OK
  94.   
  95. fi
  96. #
  97. #

使用示例:

[root@szadminsrv uptime]# /usr/local/nagios/libexec/check_uptime.sh -w 365 -c 600
OK - This system have been up for 302 days | days=302


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29500582/viewspace-1663250/,如需轉載,請註明出處,否則將追究法律責任。

相關文章