Return code of 141 is out of bounds

Thomas Guyot-Sionnest dermoth at aei.ca
Thu Dec 18 12:58:32 CET 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 17/12/08 12:38 PM, Jack Sprat wrote:
> Problem: Trying to read a pipe delimited file to retrieve status and
> port number is resulting in an "Return code of 141 is out of
> bounds" error.
> 
> Sample file being read, in this example, assume you want to collect
> servera and a status of "running" or "stopped". If the status
> is "running", then the status should appear as ok in Nagios. If the
> status is "stopped", then an email should go out indicating
> the port is down.
> File being read has this (note: those are spaces before and after the pipes)
> -------------------------
> servera | 123 | Running   <---would show as "Port 123 is okay" in Nagios
> if working properly
> servera | 321 | Stopped   <---would show as "Port 321 is down" in Nagios
> if working properly
> servera | 456 | Running
> serverb | 123 | Stopped
> serverb | 321 | Running
> serverb | 456 | Running
> Here is the script residing in libexec called app_port_monitoring.sh
> ---------------------------------------------------------------------
> #!/bin/ksh
> #
> GREPCMD=/usr/bin/grep
> SSHCMD=/usr/local/bin/ssh
> ECHOCMD=/usr/bin/echo
> NAGIOSDIR=/apps/nagios
> STATE_OK=0
> STATE_WARNING=1
> STATE_CRITICAL=2
> STATE_UNKNOWN=3
> STATE_DEPENDENT=4
> while getopts :u:s:p:h: OPT
> do
> case $OPT in
>         u|+u ) export USER=$OPTARG ;;
>         s|+s ) export SERVERNAME=$OPTARG ;;
>         p|+p ) export PORT=$OPTARG ;;
>         : ) $ECHO "$OPTARG requires an argument"; exit $STATE_UNKNOWN;;
>         \? ) $ECHO "$OPTARG: bad option, use -h for help"; exit
> $STATE_UNKNOWN;;
>         h|+h ) $ECHO "Usage: `basename $0` -u USER -s SERVERNAME -p
> PORT" ; exit $STATE_UNKNOWN;;
> esac
> done
> 
> if [ -z "$SERVERNAME" ]; then
> echo "No SERVER specified"
>  exit $STATE_UNKNOWN
> fi
> SSH_STATUS=`$SSHCMD -l ${USER} ${SERVERNAME} "pwd" >/dev/null; echo $?`
>         if [ $SSH_STATUS -ne 0 ]; then
>                 echo "Cannot ssh to $SERVER"
>                 exit $STATE_UNKNOWN
>         fi
> 
> /usr/bin/ksh 'ssh -n -o BatchMode=yes -o StrictHostKeyChecking=no -l
> ${USER} ${SERVERNAME} "export SHELL=bash; cd EEM; . ./ldap
> -bash-traversal; . ./healthcheck; export
> LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:/opt/app/${USER}/servers/lib\";
> export PATH=\"\$PA
> TH:/usr/local/bin:/bin\"; ldaphealth; . ./proxy_healthcheck"' |egrep -i
> 'stopped|running' | grep $USER | grep $PORT
>>/tmp/foo_output 2>&1
> 
> # File doesn't exist or doesn't have size greater than zero
> if [[ -f /tmp/foo_output ]]; then
>  echo "file exists"
> else
>  echo "file not found"
>  exit $STATE_UNKNOWN
> fi
> while read LINE; do
> echo ${LINE}
>  STATUS=$(echo ${LINE} | awk {'print $5'})
>  PORT=$(echo ${LINE} | awk {'print $3'})
>        if [ -z "$STATUS" ]; then
>                 echo "Service check problem"
>                 EXITSTATUS=$STATE_UNKNOWN
>         elif [ "$STATUS" = Stopped ]; then
>         echo "${PORT} is down"
>                EXITSTATUS=$STATE_CRITICAL
>         elif [ "$STATUS" = Running ]; then
>         echo "${PORT} is okay"
>                 EXITSTATUS=$STATE_OK
>        else
>                 EXITSTATUS=$STATE_UNKNOWN
>        fi
> 
> done < /tmp/foo_output
> 
> rm -f /tmp/foo_output
> exit $EXITSTATUS
> ---------------------------------
> I can place a set -x at the top of the script above and run it....below
> is the pertinent output
> + read LINE
> + echo servera | 123 | Running
> servera | 123 | Running
> + + awk {print $5}
> + echo servera | 123 | Running
> STATUS=Running
> + + awk {print $3}
> + echo servera | 123 | Running
> PORT=123
> + [ -z Running ]
> + [ Running = Stopped ]        <---- problem ??
> + [ Running = Running ]        <---- problem ??
> + echo 123 is okay
> 123 is okay
> + EXITSTATUS=0
> + read LINE
> + exit 0            <--- exiting normally
> 
> Please let me know if additional information (like the service file
> info) is needed.  Thanks much for any input in getting this
> resolved.

When you run your plugin for testing, are you running it as the nagios
user? Also try adding the "-T" switch to ssh as you won't have any tty
when run from Nagios.

- --
Thomas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFJSjro6dZ+Kt5BchYRAl+gAJ9xz/SOojOzdQX09l5/3sKpMqXvKwCgqthv
VXvt5FS7gkagOsoW8lgy22w=
=ZHMw
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list