Fix memory leak in check_http for large pages (Jimmy Bergman - #2957455)
[monitoring-plugins.git] / contrib / check_sap.sh
blob726d750244251e9eed7de48c24d3765d59713e03
1 #!/bin/sh
2 ################################################################################
3 #
4 # CHECK_SAP plugin for Nagios
5 #
6 # Originally Written by Karel Salavec (karel.salavec@ct.cz)
8 # Last Modified: 26 May 2003 by Tom De Blende (tom.deblende@village.uunet.be)
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.
14 # Version 1.0 (Karel Salavec)
16 # Command line: check_sap.sh <typ_of_check> <param1> <param2> [<param3>]
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).
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/.
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
38 # Example of command definitions for nagios:
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)
45 ##############################################################################
47 sapinfocmd='/usr/sap/rfcsdk/bin/sapinfo'
48 grepcmd=`which grep`
49 wccmd=`which wc`
50 cutcmd=`which cut`
51 awkcmd=`which awk`
53 ##############################################################################
55 if [ $# -lt 3 ]; then
56 echo "Usage: $0 <typ_of_check> <param1> <param2> [<param3>]"
57 exit 2
60 case "$1"
62 ms)
63 if [ $4 ]
64 then
65 params="r3name=$3 mshost=$2 group=$4"
66 else
67 params="r3name=$3 mshost=$2"
70 as)
71 params="ashost=$2 sysnr=$3"
74 echo "The first parameter must be ms (message server) or as (application server)!"
75 exit 2
77 esac
79 output="$($sapinfocmd $params)"
80 error="$(echo "$output" | $grepcmd ERROR | $wccmd -l)"
81 if [ "$error" -gt "0" ]; then
82 output="$(echo "$output" | $grepcmd Key | $cutcmd -dy -f2)"
83 echo "CRITICAL - SAP server not ready: " $output.
84 exit 2
85 else
86 output="$(echo "$output" | $grepcmd Destination | $awkcmd '{ print $2 }')"
87 echo "OK - SAP server $output available."
88 exit 0