check_sap.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. ################################################################################
  3. #
  4. # CHECK_SAP plugin for Nagios
  5. #
  6. # Originally Written by Karel Salavec (karel.salavec@ct.cz)
  7. #
  8. # Last Modified: 26 May 2003 by Tom De Blende (tom.deblende@village.uunet.be)
  9. #
  10. # Version 1.1 (Tom De Blende)
  11. # - Added output to feed to Nagios instead of just an exit code.
  12. # - Changed info on where to get the SAP client tools for Linux.
  13. #
  14. # Version 1.0 (Karel Salavec)
  15. #
  16. # Command line: check_sap.sh <typ_of_check> <param1> <param2> [<param3>]
  17. #
  18. # Description:
  19. # This plugin will attempt to open an SAP connection with the message
  20. # server or application server.
  21. # It need the sapinfo program installed on your server (see Notes).
  22. #
  23. # Notes:
  24. # - This plugin requires that the sapinfo program is installed.
  25. # - Sapinfo is part of a client package that can be found
  26. # at ftp://ftp.sap.com/pub/linuxlab/contrib/.
  27. #
  28. #
  29. # Parameters:
  30. # $1 - type of checking - valid values: "ms" = message server
  31. # "as" = application server
  32. # $2 - SAP server identification - can be IP address, DNS name or SAP
  33. # connect string (for example: /H/saprouter/S/sapdp01/H/sapserv3)
  34. # $3 - for $1="ms" - SAP system name (for example: DEV, TST, ... )
  35. # for $1="as" - SAP system number - note: central instance have sysnr=00
  36. # $4 - valid only for $1="ms" - logon group name - default: PUBLIC
  37. #
  38. # Example of command definitions for nagios:
  39. #
  40. # command[check_sap_ms]=/usr/local/nagios/libexec/check_sap ms $HOSTADDRESS$ $ARG1$ $ARG2$
  41. # command[check_sap_as]=/usr/local/nagios/libexec/check_sap as $HOSTADDRESS$ $ARG1$
  42. # command[check_sap_ex]=/usr/local/nagios/libexec/check_sap as $ARG1$ $ARG2$
  43. # (for ARG1 see SAP OOS1 transaction)
  44. #
  45. ##############################################################################
  46. sapinfocmd='/usr/sap/rfcsdk/bin/sapinfo'
  47. grepcmd=`which grep`
  48. wccmd=`which wc`
  49. cutcmd=`which cut`
  50. awkcmd=`which awk`
  51. ##############################################################################
  52. if [ $# -lt 3 ]; then
  53. echo "Usage: $0 <typ_of_check> <param1> <param2> [<param3>]"
  54. exit 2
  55. fi
  56. case "$1"
  57. in
  58. ms)
  59. if [ $4 ]
  60. then
  61. params="r3name=$3 mshost=$2 group=$4"
  62. else
  63. params="r3name=$3 mshost=$2"
  64. fi
  65. ;;
  66. as)
  67. params="ashost=$2 sysnr=$3"
  68. ;;
  69. *)
  70. echo "The first parameter must be ms (message server) or as (application server)!"
  71. exit 2
  72. ;;
  73. esac
  74. output="$($sapinfocmd $params)"
  75. error="$(echo "$output" | $grepcmd ERROR | $wccmd -l)"
  76. if [ "$error" -gt "0" ]; then
  77. output="$(echo "$output" | $grepcmd Key | $cutcmd -dy -f2)"
  78. echo "CRITICAL - SAP server not ready: " $output.
  79. exit 2
  80. else
  81. output="$(echo "$output" | $grepcmd Destination | $awkcmd '{ print $2 }')"
  82. echo "OK - SAP server $output available."
  83. exit 0
  84. fi