Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / contrib / check_sap.sh
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 ##############################################################################
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
58 fi
60 case "$1"
61   in
62     ms)
63         if [ $4 ]
64           then
65             params="r3name=$3 mshost=$2 group=$4"
66         else
67           params="r3name=$3 mshost=$2"
68         fi
69         ;;
70     as)
71         params="ashost=$2 sysnr=$3"
72         ;;
73     *)
74         echo "The first parameter must be ms (message server) or as (application server)!"
75         exit 2
76         ;;
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  
89 fi