Page 1 of 3

Custom plugin that works in Nagios core 3.4 but not 4.0.1

Posted: Wed Dec 04, 2013 2:48 pm
by heebs
Ok, I have been seaching the forums and smashing my face off of this simple script for quite a while and I wonder if I am just missing something that someone else has come across. Here is the script with important stuff stripped, of course:

Code: Select all

#!/bin/sh

# Gracefully fail if stack number not specified on command line
if [ -z "$1" ]
then
        echo "Usage: sbapp_callattempts.sh <stack_number>"
        exit 3
else
        STACK=$1
fi

DB_NAME=`/usr/local/nagios/scripts/set_db_name.sh $STACK`


CALLATTEMPTS=`sqlplus -S nagios_adm/xxxxxx@$DB_NAME << EOF
set head off
set pagesize 0
<some sql stuff here> 
/
EOF`

CALLATTEMPTS=`echo $CALLATTEMPTS |awk '{print $1}' | sed -e 's/^[ \t] *//'`


case $CALLATTEMPTS in
'no')
        echo "OK:  CALLATTEMPTS 0 | call_attempts=0"
        exit 0
        ;;
''|*[!0-9]*)
        echo "UNKNOWN: Could not get valid number for call attempts"
        exit 3
        ;;
*)
        echo "OK:  CALLATTEMPTS $CALLATTEMPTS | call_attempts=$CALLATTEMPTS"
        exit 0
;;
esac
When I run this as a check in 4.0.1, I consistently get the matches for our UNKNOWN case but I can run it at the same time as nagios and get correct results, while at the same time my old nagios instance is also returning correctly. This should not matter but it should be mentioned, we are moving from centos 5.4 32bit running 3.4 to centos 6.4 64bit running 4.0.1.

Any help will be greatly appreciated.

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Wed Dec 04, 2013 2:58 pm
by tmcdonald
/usr/local/nagios/scripts/set_db_name.sh has never existed in our core install. It must have been from an agent of some kind.

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Wed Dec 04, 2013 3:03 pm
by heebs
That is correct. Sorry. That is a custom script we have installed to setup a framework for connecting to our databases as we have many.

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Wed Dec 04, 2013 3:31 pm
by tmcdonald
What happens when you run this from the command line?

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Wed Dec 04, 2013 3:43 pm
by heebs

Code: Select all

/home/nagios>bash -x /usr/local/nagios/scripts/sbapp_callattempts.sh 6
+ '[' -z 6 ']'
+ STACK=6
++ /usr/local/nagios/scripts/set_db_name.sh 6
+ DB_NAME=xxxxxx
++ sqlplus -S nagios_adm/xxxxx@xxxxxx
+ CALLATTEMPTS='          91984
          38731'
++ echo 91984 38731
++ awk '{print $1}'
++ sed -e 's/^[ \t] *//'
+ CALLATTEMPTS=91984
+ case $CALLATTEMPTS in
+ echo 'OK.  CALLATTEMPTS:91984 | call_attempts=91984'
OK.  CALLATTEMPTS:91984 | call_attempts=91984
+ exit 0

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Wed Dec 04, 2013 4:20 pm
by tmcdonald
Can you post your service and command definitions for this?

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Thu Dec 05, 2013 9:15 am
by heebs
define command {
command_name check_call_attempts
command_line /usr/local/nagios/scripts/sbapp_callattempts.sh $ARG1$
}

define service {
name generic-service
active_checks_enabled 1
passive_checks_enabled 1
check_freshness 1
event_handler_enabled 1
flap_detection_enabled 1 ;maybe we want to specify flap options too?
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
check_period 24x7
notifications_enabled 1
notification_interval 5
notification_period 24x7
notification_options u,c,r,f,s
contact_groups operations,operations-pager
register 0 ;this is just a template, the default is 1 for on
use srv-pnp
}

define service{
host_name service6.soundbite.com
use generic-service
service_description Stack 6 Hourly Call Attempts
contact_groups operations
check_command check_call_attempts!6
max_check_attempts 2
}

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Thu Dec 05, 2013 12:03 pm
by abrist
Can you echo $CALLATTEMPTS to a file or at least to stdout right before the bash case statement?

Code: Select all

#!/bin/sh

# Gracefully fail if stack number not specified on command line
if [ -z "$1" ]
then
        echo "Usage: sbapp_callattempts.sh <stack_number>"
        exit 3
else
        STACK=$1
fi

DB_NAME=`/usr/local/nagios/scripts/set_db_name.sh $STACK`


CALLATTEMPTS=`sqlplus -S nagios_adm/xxxxxx@$DB_NAME << EOF
set head off
set pagesize 0
<some sql stuff here>
/
EOF`

echo $CALLATTEMPTS > /tmp/call_attempts_test.txt

CALLATTEMPTS=`echo $CALLATTEMPTS |awk '{print $1}' | sed -e 's/^[ \t] *//'`

echo $CALLATTEMPTS >> /tmp/call_attempts_test.txt

case $CALLATTEMPTS in
'no')
        echo "OK:  CALLATTEMPTS 0 | call_attempts=0"
        exit 0
        ;;
''|*[!0-9]*)
        echo "UNKNOWN: Could not get valid number for call attempts"
        exit 3
        ;;
*)
        echo "OK:  CALLATTEMPTS $CALLATTEMPTS | call_attempts=$CALLATTEMPTS"
        exit 0
;;
esac

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Thu Dec 05, 2013 1:50 pm
by heebs
So this is interesting... It has clearly run a few times but that blank sure tells me why it is failing.

Code: Select all

root@monitorbos02|/root>cat /tmp/call_attempts_test.txt 









root@monitorbos02|/root>
This is what I have after one manual run:
nagios@monitorbos02|/home/nagios>cat /tmp/call_attempts_test.txt 
















37389
nagios@monitorbos02|/home/nagios>
Edited out my extra copy and paste from the output of catting the file

Re: Custom plugin that works in Nagios core 3.4 but not 4.0.

Posted: Thu Dec 05, 2013 2:30 pm
by abrist
CALLATTEMPTS is empty. I bet there is an issue with:

Code: Select all

CALLATTEMPTS=`sqlplus -S nagios_adm/xxxxxx@$DB_NAME << EOF
set head off
set pagesize 0
<some sql stuff here>
/
EOF`