Page 1 of 1
Null output on the Nagios GUI,but command line check works
Posted: Mon Jun 18, 2012 8:17 am
by Shivaramakrishnan
Hello
I have a plugin which is a bash script that is working fine on the command line ,It gives the required output.
See the below for the command line output for the two hosts.
/usr/lib/nagios/plugins/check_pxy_RPS pxsA01_sin1
pxsA01_sin1:0 :0 :0 :0 | pxsA01_sin1=0;=0;=0;=0
/usr/lib/nagios/plugins/check_pxy_RPS pxsA01_orf1
pxsA01_orf1:0 :0 :0 :0 | pxsA01_orf1=0;=0;=0;=0
But the problem is I am getting a
Current Status: WARNING
Status Information: null
in the nagios GUI for one of the hosts (pxsA01_orf1).
Below is my service definition for both the hosts
define service {
use service-pnp,pw-general-service
hosts pxs01.orf1
service_description Proxy RPS
check_command check_pxy_RPS!pxsA01_orf1
}
define service {
use service-pnp,pw-general-service
hosts pxs01.sin1
service_description Proxy RPS
check_command check_pxy_RPS!pxsA01_sin1
}
I tried executing the plugin as the nagios user as well from the command line and I am able to get right output.
su nagios -s /bin/bash -c /usr/lib/nagios/plugins/check_pxy_RPS pxsA01_sin1
pxsA01_sin1:0 :0 :0 :0 | pxsA01_sin1=0;=0;=0;=0
su nagios -s /bin/bash -c /usr/lib/nagios/plugins/check_pxy_RPS pxsA01_orf1
pxsA01_orf1:0 :0 :0 :0 | pxsA01_orf1=0;=0;=0;=0
What might be the issue here?I am running out of ideas here.Can anyone help me on this?
Thanks
Shiva
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 18, 2012 11:59 am
by agriffin
Would it be possible to post the plugin's source?
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 18, 2012 12:23 pm
by Shivaramakrishnan
Code: Select all
#!/bin/bash
#set -x
pxA=$1
pxB=$2
pxC=$3
pxD=$4
A_last_RPS_file=/var/cache/nagios3/RPS_$pxA.txt
B_last_RPS_file=/var/cache/nagios3/RPS_$pxB.txt
C_last_RPS_file=/var/cache/nagios3/RPS_$pxC.txt
D_last_RPS_file=/var/cache/nagios3/RPS_$pxD.txt
if [ ! -f $A_last_RPS_file ] ; then
echo 0 > $A_last_RPS_file
chmod 666 $A_last_RPS_file
fi
if [ ! -f $B_last_RPS_file ] ; then
echo 0 > $B_last_RPS_file
chmod 666 $B_last_RPS_file
fi
if [ ! -f $C_last_RPS_file ] ; then
echo 0 > $C_last_RPS_file
chmod 666 $C_last_RPS_file
fi
if [ ! -f $D_last_RPS_file ] ; then
echo 0 > $D_last_RPS_file
chmod 666 $D_last_RPS_file
fi
A_LAST_RPS=$(cat $A_last_RPS_file)
B_LAST_RPS=$(cat $B_last_RPS_file)
C_LAST_RPS=$(cat $C_last_RPS_file)
D_LAST_RPS=$(cat $D_last_RPS_file)
A_Last_RPS_file_time=$(date -d "- `date +%s -r $A_last_RPS_file` seconds" "+%s")
B_Last_RPS_file_time=$(date -d "- `date +%s -r $B_last_RPS_file` seconds" "+%s")
C_Last_RPS_file_time=$(date -d "- `date +%s -r $C_last_RPS_file` seconds" "+%s")
D_Last_RPS_file_time=$(date -d "- `date +%s -r $D_last_RPS_file` seconds" "+%s")
for pxy in $pxA $pxB $pxC $pxD
do
for REQ in `snmpwalk -Cc -v2C -c abcdefghijklmnop $pxy:3401 -m SQUID-MIB SQUID-MIB::cacheClientHttpRequests | awk '{print $4}'`
do
REQ_CNT=$(($REQ_CNT + $REQ))
PXY_CNT=$(($PXY_CNT + $REQ))
done
if [ "$pxy" == "$pxA" ]; then
let cnt_A=$PXY_CNT
fi
if [ "$pxy" == "$pxB" ]; then
let cnt_B=$PXY_CNT
fi
if [ "$pxy" == "$pxC" ]; then
let cnt_C=$PXY_CNT
fi
if [ "$pxy" == "$pxD" ]; then
let cnt_D=$PXY_CNT
fi
PXY_CNT=0
done
PXA_DIFF_RES=$(($cnt_A - $A_LAST_RPS))
if [ "$PXA_DIFF_RES" -lt "0" ];then
PXA_DIFF_RES=0
PXA_RPS=0
else
PXA_RPS=$(( PXA_DIFF_RES / $A_Last_RPS_file_time))
fi
PXB_DIFF_RES=$(($cnt_B - $B_LAST_RPS))
if [ "$PXB_DIFF_RES" -lt "0" ];then
PXB_DIFF_RES=0
PXB_RPS=0
else
PXB_RPS=$(( PXB_DIFF_RES / $B_Last_RPS_file_time))
fi
PXC_DIFF_RES=$(($cnt_C - $C_LAST_RPS))
if [ "$PXC_DIFF_RES" -lt "0" ];then
PXC_DIFF_RES=0
PXC_RPS=0
else
PXC_RPS=$(( PXC_DIFF_RES / $C_Last_RPS_file_time))
fi
PXD_DIFF_RES=$(($cnt_D - $D_LAST_RPS))
if [ "$PXD_DIFF_RES" -lt "0" ];then
PXD_DIFF_RES=0
PXD_RPS=0
else
PXD_RPS=$(( PXD_DIFF_RES / $D_Last_RPS_file_time))
fi
echo $cnt_A > $A_last_RPS_file
echo $cnt_B > $B_last_RPS_file
echo $cnt_C > $C_last_RPS_file
echo $cnt_D > $D_last_RPS_file
echo "$pxA":"$PXA_RPS $pxB":"$PXB_RPS $pxC":"$PXC_RPS $pxD":"$PXD_RPS | $pxA=$PXA_RPS;$pxB=$PXB_RPS;$pxC=$PXC_RPS;$pxD=$PXD_RPS"
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 18, 2012 12:25 pm
by Shivaramakrishnan
But the problem exists in the couple of other plugins as well on the same host.
It works fine on the command line both as root and nagios user.
Can you please let me know what might be missing here?
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 18, 2012 2:10 pm
by agriffin
I don't know what could be causing this. Usually (as in 99.9% of the time) this is a permission issue, but it seems you've gone through steps to make sure that isn't the case. Does your script or any commands in it rely on environment variables. Maybe snmpwalk isn't in the default PATH and you need to specify the full filename?
Also I noticed that your perfdata is malformed. I don't think that would cause this issue, but it may prevent you from graphing your results once you get it working.
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 18, 2012 2:22 pm
by Shivaramakrishnan
The only environment variable it uses is snmpwalk and it is in the default path
/usr/bin/snmpwalk
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 18, 2012 2:23 pm
by Shivaramakrishnan
And to add the same script works fine on most of the other servers giving output even in GUI.
Re: Null output on the Nagios GUI,but command line check wor
Posted: Tue Jun 19, 2012 3:09 pm
by agriffin
Do you have any MAC systems in place on this machine (SELinux, AppArmor, Tomoyo...)?
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 25, 2012 12:26 pm
by Shivaramakrishnan
Most of these are servers running only debian/centos .
Re: Null output on the Nagios GUI,but command line check wor
Posted: Mon Jun 25, 2012 12:50 pm
by agriffin
CentOS uses SELinux for Mandatory Access Controls (abbreviated MAC, sorry for not making that clearer in my last post). Debian makes it available but not included by default, so you would probably know if you were running it on your Debian machines. Check /var/log/messages for SELinux messages that look like they may have something to do with Nagios. You could also temporarily disable it to see if that helps - the command for that is 'setenforce Permissive'.