Different scritp output from the NRPE
Posted: Fri Apr 12, 2019 9:04 am
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...
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...