nagios script returns wrong information in nagios

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
karim buzdar
Posts: 5
Joined: Fri Dec 13, 2013 12:09 pm

nagios script returns wrong information in nagios

Post by karim buzdar »

Code: Select all

script written by: karim buzdar
purpose: nagios check for kannel stuck
Date : dec 8, 2013

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $3 }' > kannel_temp_1.txt

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $7 }' > kannel_temp_2.txt

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $3 }' > kannel_temp_3.txt

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $7 }' > kannel_temp_4.txt

recvsms1=$(cat kannel_temp_2.txt) 
sentsms2=$(cat kannel_temp_3.txt) 
recvsms2=$(cat kannel_temp_4.txt)

if [ $sentsms1 == $sentsms2 ] && [ $recvsms1 == $recvsms2 ];

then 
exitcode=0 
statustxt=ok 

else 
exitcode=2 
statustxt=critical 
fi

echo "$exitcode - $statustxt"
my script works fine on client machine but returns wrong information (always critical) in nagios.

please help me out.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: nagios script returns wrong information in nagios

Post by slansing »

Please use code wraps when you are placing code in your messages. We also need to know what output nagios is giving you with the critical state return. It sounds like this is a permissions issue, likely the plugin requires root access and NRPE is executing it as nagios.
karim buzdar
Posts: 5
Joined: Fri Dec 13, 2013 12:09 pm

Re: nagios script returns wrong information in nagios

Post by karim buzdar »

output returned is 2 - critical
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: nagios script returns wrong information in nagios

Post by scottwilkerson »

Your script should end with something like

Code: Select all

exit $exitcode
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
karim buzdar
Posts: 5
Joined: Fri Dec 13, 2013 12:09 pm

Re: nagios script returns wrong information in nagios

Post by karim buzdar »

still same output
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: nagios script returns wrong information in nagios

Post by slansing »

What did you change it to?
karim buzdar
Posts: 5
Joined: Fri Dec 13, 2013 12:09 pm

Re: nagios script returns wrong information in nagios

Post by karim buzdar »

i put exit $exitcode at the end of the code.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: nagios script returns wrong information in nagios

Post by scottwilkerson »

Can you post the full contents of the script. Also, can you post what txt is returned when you run from the command line, like so:

Code: Select all

su nagios -c '/usr/local/nagiosxi/libexec/YOURSCRIPT.sh;echo $?'
Thanks
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
karim buzdar
Posts: 5
Joined: Fri Dec 13, 2013 12:09 pm

Re: nagios script returns wrong information in nagios

Post by karim buzdar »

Code: Select all

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $3 }' > kannel_temp_1.txt

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $7 }' > kannel_temp_2.txt

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $3 }' > kannel_temp_3.txt

/etc/init.d/kannel status | grep -i -E "SMS: received" | awk '{ print $7 }' > kannel_temp_4.txt

recvsms1=$(cat kannel_temp_2.txt)
sentsms2=$(cat kannel_temp_3.txt)
recvsms2=$(cat kannel_temp_4.txt)

if [ $sentsms1 == $sentsms2 ] && [ $recvsms1 == $recvsms2 ];

then
exitcode=0
statustxt=ok

else
exitcode=2
statustxt=critical
fi

echo "$exitcode - $statustxt"

output returtned:

/usr/local/groundwork/nagios/libexec/check_nrpe -t 60 -H 192.168.5.78 -c check_kannel_status

2 - critical

Command returned exit status 0
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: nagios script returns wrong information in nagios

Post by tmcdonald »

Please when you post code wrap it in code tags so it is easier to read. I have made the change for you this time.

As for your issue, you don't want to echo "$exitcode", you want do to as scottwilkerson said and put

Code: Select all

exit $exitcode
at the end of your code.

And can you please respond to scottwilkerson's other question?
scottwilkerson wrote:[...] Also, can you post what txt is returned when you run from the command line, like so:

Code: Select all

su nagios -c '/usr/local/nagiosxi/libexec/YOURSCRIPT.sh;echo $?'
Thanks
Former Nagios employee
Locked