check_oracle.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/bin/sh
  2. #
  3. # latigid010@yahoo.com
  4. # 01/06/2000
  5. #
  6. # This Nagios plugin was created to check remote or local TNS
  7. # status and check local Database status.
  8. #
  9. # Add the following lines to your object config file (i.e. commands.cfg)
  10. # command[check-tns]=/usr/local/nagios/libexec/check_ora 1 $ARG$
  11. # command[check-oradb]=/usr/local/nagios/libexec/check_ora 2 $ARG$
  12. #
  13. #
  14. # Usage:
  15. # To check TNS Status: ./check_ora 1 <Oracle Sid or Hostname/IP address>
  16. # To Check local database: ./check_ora 2 <ORACLE_SID>
  17. #
  18. # I have the script checking for the Oracle PMON process and
  19. # the sgadefORACLE_SID.dbf file.
  20. #
  21. #
  22. # If you have any problems check that you have the $ORACLE_HOME
  23. # enviroment variable set, have $ORACLE_HOME/bin in your PATH, and
  24. # dont forget about your tnsnames.ora file. when checking Local
  25. # Database status your ORACLE_SID is case sensitive.
  26. #
  27. PROGNAME=`basename $0`
  28. PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
  29. REVISION=`echo '$Revision$' | sed -e 's/[^0-9.]//g'`
  30. . $PROGPATH/utils.sh
  31. print_usage() {
  32. echo "Usage:"
  33. echo " $PROGNAME --tns <Oracle Sid or Hostname/IP address>"
  34. echo " $PROGNAME --db <ORACLE_SID>"
  35. echo " $PROGNAME --help"
  36. echo " $PROGNAME --version"
  37. }
  38. print_help() {
  39. print_revision $PROGNAME $REVISION
  40. echo ""
  41. print_usage
  42. echo ""
  43. echo "Check remote or local TNS status and check local Database status"
  44. echo ""
  45. echo "--tns=SID/IP Address"
  46. echo " Check remote TNS server"
  47. echo "--db=SID"
  48. echo " Check local database (search /bin/ps for PMON process and check"
  49. echo " filesystem for sgadefORACLE_SID.dbf"
  50. echo "--help"
  51. echo " Print this help screen"
  52. echo "--version"
  53. echo " Print version and license information"
  54. echo ""
  55. echo "If the plugin doesn't work, check that the $ORACLE_HOME environment"
  56. echo "variable is set, that $ORACLE_HOME/bin is in your PATH, and the"
  57. echo "tnsnames.ora file is locatable and is properly configured."
  58. echo ""
  59. echo "When checking Local Database status your ORACLE_SID is case sensitive."
  60. echo ""
  61. support
  62. }
  63. case "$1" in
  64. 1)
  65. cmd='--tns'
  66. ;;
  67. 2)
  68. cmd='--db'
  69. ;;
  70. *)
  71. cmd="$1"
  72. ;;
  73. esac
  74. case "$cmd" in
  75. --tns)
  76. export tnschk=` tnsping $2`
  77. export tnschk2=` echo $tnschk | grep -c OK`
  78. export tnschk3=` echo $tnschk | cut -d\( -f7 | sed y/\)/" "/`
  79. if [ ${tnschk2} -eq 1 ] ; then
  80. echo "OK - reply time ${tnschk3} from $2"
  81. exit 0
  82. else
  83. echo "No TNS Listener on $2"
  84. exit $STATE_CRITICAL
  85. fi
  86. ;;
  87. --db)
  88. export pmonchk=`ps -ef | grep -v grep | grep ${2} | grep -c pmon`
  89. if [ -e $ORACLE_HOME/dbs/sga*${2}* ] ; then
  90. if [ ${pmonchk} -eq 1 ] ; then
  91. export utime=`ls -la $ORACLE_HOME/dbs/sga*$2* | cut -c 43-55`
  92. echo "${2} OK - running since ${utime}"
  93. exit $STATE_OK
  94. fi
  95. else
  96. echo "${2} Database is DOWN"
  97. exit $STATE_CRITICAL
  98. fi
  99. ;;
  100. --help)
  101. print_help
  102. exit $STATE_OK
  103. ;;
  104. -h)
  105. print_help
  106. exit $STATE_OK
  107. ;;
  108. --version)
  109. print_revision $PLUGIN $REVISION
  110. exit $STATE_OK
  111. ;;
  112. -V)
  113. print_revision $PLUGIN $REVISION
  114. exit $STATE_OK
  115. ;;
  116. *)
  117. print_usage
  118. exit $STATE_UNKNOWN
  119. esac