Different scritp output from the NRPE

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
fraguillen
Posts: 47
Joined: Fri May 18, 2018 11:40 am

Different scritp output from the NRPE

Post by fraguillen »

Good Morning:

I have the following script:

[root@nagios02 libexec]# cat check_count_file.sh
#!/bin/sh

el_directo=$1
el_warning=$2
el_critical=$3

LS="/bin/ls"
CUT="/usr/bin/cut"
WC="/usr/bin/wc"
GREP="/bin/grep"
FIND="/usr/bin/find"

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
cantidad=0

cantidad=`$FIND $el_directo |$WC -l`
#cantidad=`$LS $el_directo |$WC -l`

dirsize=`echo $cantidad`
resultado="OK"
exitstatus=$STATE_OK

if [ "$el_warning" != "" ]; then
if [ $cantidad -ge $el_warning ]; then
resultado="WARNING"
exitstatus=$STATE_WARNING
fi
fi

if [ "$el_critical" != "" ]; then
if [ $cantidad -ge $el_critical ]; then
resultado="CRITICAL"
exitstatus=$STATE_CRITICAL
fi
fi

resultado="$resultado - Hay $cantidad archivos en la carpeta $el_directo | 'cantidad'=${dirsize};${el_warning};${el_critical}"
exitstatus=$STATE_OK

echo "$resultado"
exit $exitstatus
[root@nagios02 libexec]#

If I execute the script directly I get the following result:

[root@nagios02 libexec]# ./check_count_file.sh /tmp 2500 3000
OK - Hay 1374 archivos en la carpeta /tmp | 'cantidad'=1374;2500;3000
[root@nagios02 libexec]#


You will notice that it shows the folder, in this case, / tmp and the number of files, 1374, is according to the number of files in that folder.

But if I execute it with the NRPE it gives me other values:

[root@nagios02 libexec]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 30 -c check_count_file /tmp 2500 3000
OK - Hay 584963 archivos en la carpeta | 'cantidad'=584963;;
[root@nagios02 libexec]#

It does not show me the folder and the amount of files is not correct. This is how it is configured in the nrpe.cfg:

command[check_count_file]=/usr/local/nagios/libexec/check_count_file.sh $ARG1$ $ARG2$ $ARG3$

Could you help me? I do not understand why this happens.

Best regards...
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Different scritp output from the NRPE

Post by lmiltchev »

[root@nagios02 libexec]# ./check_count_file.sh /tmp 2500 3000
OK - Hay 1374 archivos en la carpeta /tmp | 'cantidad'=1374;2500;3000
You are running your command as root user... NRPE is run as 'nagios' user. Is the number of files the same when you run your command as nagios user?

Code: Select all

su nagios -
/usr/local/nagios/libexec/check_count_file.sh /tmp 2500 3000
Be sure to check out our Knowledgebase for helpful articles and solutions!
fraguillen
Posts: 47
Joined: Fri May 18, 2018 11:40 am

Re: Different scritp output from the NRPE

Post by fraguillen »

Even with the user nagios gives me the same result.

[root@nagios02 libexec]# su nagios
[nagios@nagios02 libexec]$ whoami
nagios
[nagios@nagios02 libexec]$

[nagios@nagios02 libexec]$ /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 30 -c check_count_file /tmp 2500 3000
OK - Hay 580117 archivos en la carpeta | 'cantidad'=580117;;

[nagios@nagios02 libexec]$ ./check_count_file.sh /tmp 2500 3000
OK - Hay 1507 archivos en la carpeta /tmp | 'cantidad'=1507;2500;3000
[nagios@nagios02 libexec]$
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Different scritp output from the NRPE

Post by lmiltchev »

Well, you are not passing the arguments... You pass arguments by '-a'.

Example:

Code: Select all

./check_nrpe -H <ip address> -c <command> -a <args>
Try:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -t 30 -c check_count_file -a '/tmp 2500 3000'
Be sure to check out our Knowledgebase for helpful articles and solutions!
fraguillen
Posts: 47
Joined: Fri May 18, 2018 11:40 am

Re: Different scritp output from the NRPE

Post by fraguillen »

Ready, with that argument, -a, it works as it should be.

Thank you very much, you can now block this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Different scritp output from the NRPE

Post by lmiltchev »

I am glad I could help! :)
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked