Custom plugin that works in Nagios core 3.4 but not 4.0.1

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
heebs
Posts: 15
Joined: Tue Dec 03, 2013 9:44 am

Custom plugin that works in Nagios core 3.4 but not 4.0.1

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

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

Post 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.
Former Nagios employee
heebs
Posts: 15
Joined: Tue Dec 03, 2013 9:44 am

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

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

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

Post by tmcdonald »

What happens when you run this from the command line?
Former Nagios employee
heebs
Posts: 15
Joined: Tue Dec 03, 2013 9:44 am

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

Post 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
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

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

Post by tmcdonald »

Can you post your service and command definitions for this?
Former Nagios employee
heebs
Posts: 15
Joined: Tue Dec 03, 2013 9:44 am

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

Post 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
}
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post 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
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
heebs
Posts: 15
Joined: Tue Dec 03, 2013 9:44 am

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

Post 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
Last edited by heebs on Thu Dec 05, 2013 2:36 pm, edited 1 time in total.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post 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`
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked