Page 1 of 1
nagios script returns wrong information in nagios
Posted: Fri Dec 13, 2013 12:28 pm
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.
Re: nagios script returns wrong information in nagios
Posted: Fri Dec 13, 2013 12:38 pm
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.
Re: nagios script returns wrong information in nagios
Posted: Sat Dec 14, 2013 4:11 am
by karim buzdar
output returned is 2 - critical
Re: nagios script returns wrong information in nagios
Posted: Mon Dec 16, 2013 10:02 am
by scottwilkerson
Your script should end with something like
Re: nagios script returns wrong information in nagios
Posted: Mon Dec 16, 2013 3:37 pm
by karim buzdar
still same output
Re: nagios script returns wrong information in nagios
Posted: Mon Dec 16, 2013 4:13 pm
by slansing
What did you change it to?
Re: nagios script returns wrong information in nagios
Posted: Mon Dec 16, 2013 8:44 pm
by karim buzdar
i put exit $exitcode at the end of the code.
Re: nagios script returns wrong information in nagios
Posted: Mon Dec 16, 2013 8:49 pm
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
Re: nagios script returns wrong information in nagios
Posted: Thu Dec 19, 2013 7:19 am
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
Re: nagios script returns wrong information in nagios
Posted: Thu Dec 19, 2013 3:49 pm
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
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