Page 1 of 1

Wrong response when reading output from nagios nrpe

Posted: Wed Mar 18, 2015 10:07 am
by jmasquelet
Hi, i've a problem reading an output from a script when executing nrpe.

When execute de script from server like ./check_sesiones i've the correct response but when execute it from nagios like ./check_nrpe -H host -c check_sesion (which is the name configured) the response is wrong.

This is the config from nagios server:

define service{
use generic-service-linux ; Name of template to use
host_name sdd11
service_description Sesiones con Web Services
check_interval 1
check_command check_nrpe!check_sesion
}


This is my nrpe.cfg on the host:

command[check_sesion]=/usr/lib/nagios/plugins/check_sesiones

The script have the following permission:

> ls -l check_sesiones
-rwxr-xr-x 1 nagios nagios 2555 2015-03-18 11:58 check_sesiones

This is the script:

#!/bin/bash
posicion=1
declare -a nombre_pool_sesiones
declare -a cantidad_sesiones_aplicacion_leteserv
declare -a cantidad_sesiones_amadeus_disponibles
declare -a cantidad_sesiones_amadeus_uso
declare -a cantidad_sesiones_amadeus_maximas
declare -a m
let ok_amadeusSabre=5
let critical_amadeusSabre=5
let critical_appLet=5
let ok_appLet=5
nombre_pool_sesiones=$(cat archivo | cut -d',' -f 1 > archivo1)
while read line; do
nombre_pool_sesiones[$posicion]=$line;
let posicion=posicion+1;
done < archivo1

posicion=1
cantidad_sesiones_amadeus_maximas=$(cat archivo | cut -d',' -f 2 > archivo1)
while read line; do
cantidad_sesiones_amadeus_maximas[$posicion]=$line;
let posicion=posicion+1;
done < archivo1
posicion=1
cantidad_sesiones_amadeus_disponibles=$(cat archivo | cut -d',' -f 3 > archivo1)
while read line; do
cantidad_sesiones_amadeus_disponibles[$posicion]=$line;
let posicion=posicion+1;
done < archivo1

posicion=1
cantidad_sesiones_amadeus_uso=$(cat archivo | cut -d',' -f 4 > archivo1)
while read line; do
cantidad_sesiones_amadeus_uso[$posicion]=$line;
let posicion=posicion+1;
done < archivo1

posicion=1
cantidad_sesiones_aplicacion_leteserv=$(cat archivo | cut -d',' -f 5 > archivo1)
while read line; do
cantidad_sesiones_aplicacion_leteserv[$posicion]=$line;
let posicion=posicion+1;
done < archivo1

for i in 1 2 3 4 5 6
do
m=$((cantidad_sesiones_amadeus_disponibles+cantidad_sesiones_amadeus_uso))
done
for i in 1 2 3 4 5 6
do
if [ ${m} -eq ${cantidad_sesiones_amadeus_maximas} ]; then
ok_amadeusSabre=0
else
critical_amadeusSabre=2
fi
if [ ${cantidad_sesiones_aplicacion_leteserv} -le ${cantidad_sesiones_amadeus_maximas} ]; then
ok_appLet=0
else
critical_appLet=2
fi
done
if [[ "$critical_amadeusSabre" -eq "2" && $critical_appLet -eq "2" ]]; then
echo "Se superaron las sesiones de A/S maximas configuradas y las sesiones de aplicacion y leteServ superan a las de A/S maximas configuradas"
exit 2

elif [[ "$critical_appLet" -eq "2" ]]; then
echo "Las sesiones de aplicaciones y LeteServ superan a las sesiones A/S maximas configuradas"
exit 2
elif [[ "$critical_amadeusSabre" -eq "2" ]]; then
echo "Se superaron las sesiones de A/S maximas configuradas"
exit 2
elif [[ "$ok_amadeusSabre" -eq "0" || "$ok_appLet" -eq "0" ]]; then
echo "Todo OK"
exit 0
else
echo "Error desconocido"
exit 3
fi


And this is the file from where ir read de information:

> cat archivo
APROD,92,10,82,10
SRES744445,5,0,5,0
SRES744444,5,0,5,0
SRES744443,5,0,5,0
SRES744442,5,0,5,0
SRES744441,5,0,5,0


This is the response when i execute the script via sh:

nagios@sdd11:/usr/lib/nagios/plugins> ./check_sesiones
Todo OK


This is the response when i execute the script from Nagios:

> ./check_nrpe -H sdd01 -c check_sesion
Se superaron las sesiones de A/S maximas configuradas


And when execute the command from the host i get the same wrong response:

> ./check_nrpe -H localhost -c check_sesion
Se superaron las sesiones de A/S maximas configuradas


i'm running Nrpe 2.12
> ./check_nrpe -H localhost
NRPE v2.12
And my version of Nagios installed on the server is 3.0.6

Could you please tell me what i'm doing wrong?

Thanks!

Re: Wrong response when reading output from nagios nrpe

Posted: Wed Mar 18, 2015 2:32 pm
by jdalrymple
I suggest that you specify an absolute path to archivo. When it's run by nrpe you're assuming that archivo is somewhere in the nagios user's path, which is not terribly likely.

Re: Wrong response when reading output from nagios nrpe

Posted: Thu Mar 19, 2015 8:20 am
by jmasquelet
Really thanks!!!!!!!! :D

We were driving crazy with this and make run a crontab which execute the script and in the end it creates a file with the correct output. When we do that it returns an error because the absolute path where missing and correct the script but never try that way with nagios!!

Sorry for my horrible english x)

Re: Wrong response when reading output from nagios nrpe

Posted: Thu Mar 19, 2015 9:50 am
by tmcdonald
Is everything working for you now?

Re: Wrong response when reading output from nagios nrpe

Posted: Wed Mar 25, 2015 7:03 am
by jmasquelet
tmcdonald wrote:Is everything working for you now?

yes!

Re: Wrong response when reading output from nagios nrpe

Posted: Wed Mar 25, 2015 9:04 am
by tmcdonald
Great! I'll be closing this thread now, but feel free to open another if you need anything in the future!