Wrong response when reading output from nagios nrpe

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
jmasquelet
Posts: 15
Joined: Wed Mar 04, 2015 6:37 am

Wrong response when reading output from nagios nrpe

Post 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!
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Wrong response when reading output from nagios nrpe

Post 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.
jmasquelet
Posts: 15
Joined: Wed Mar 04, 2015 6:37 am

Re: Wrong response when reading output from nagios nrpe

Post 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)
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Wrong response when reading output from nagios nrpe

Post by tmcdonald »

Is everything working for you now?
Former Nagios employee
jmasquelet
Posts: 15
Joined: Wed Mar 04, 2015 6:37 am

Re: Wrong response when reading output from nagios nrpe

Post by jmasquelet »

tmcdonald wrote:Is everything working for you now?

yes!
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Wrong response when reading output from nagios nrpe

Post by tmcdonald »

Great! I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked