This support forum board is for support questions relating to
Nagios XI , our flagship commercial network monitoring solution.
karim buzdar
Posts: 5 Joined: Fri Dec 13, 2013 12:09 pm
Post
by karim buzdar » Fri Dec 13, 2013 12:28 pm
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...
Post
by slansing » Fri Dec 13, 2013 12:38 pm
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.
scottwilkerson
DevOps Engineer
Posts: 19396 Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:
Post
by scottwilkerson » Mon Dec 16, 2013 10:02 am
Your script should end with something like
slansing
Posts: 7698 Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...
Post
by slansing » Mon Dec 16, 2013 4:13 pm
What did you change it to?
karim buzdar
Posts: 5 Joined: Fri Dec 13, 2013 12:09 pm
Post
by karim buzdar » Mon Dec 16, 2013 8:44 pm
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:
Post
by scottwilkerson » Mon Dec 16, 2013 8:49 pm
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
karim buzdar
Posts: 5 Joined: Fri Dec 13, 2013 12:09 pm
Post
by karim buzdar » Thu Dec 19, 2013 7:19 am
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
Post
by tmcdonald » Thu Dec 19, 2013 3:49 pm
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
Former Nagios employee