I am using a command to throw a specific exit status when error count in one of my log files exceed a certain limit. Command is as follows:
cd /home/serveradmin/logs/ | ls -trc | grep gateway | tail -1 | xargs cat | grep error | wc -l | awk '{if($1 >= "35000"){print "Critical: ",$1;exit 2} else if ($1 >= "25000") {print "Warning: ",$1;exit 1} else {exit 0} }'
After executing the command, I have verified the exit status (my command returns exit code 1, because error count in my file is greater than 25000) with the following command:
echo $?
The above command returns 1 as output.
In my nrpe.cfg file I have defined the same command as follows:
command[Error_Count]=cd /home/serveradmin/logs/ | ls -trc | grep gateway | tail -1 | xargs cat | grep error | wc -l | awk '{if($1 >= "35000"){exit 2} else if ($1 >= "25000") {exit 1} else {exit 0} }'
I have defined the service in nagios core as follows:
define service {
host_name test_vm
service_description Error_Count
check_command check_nrpe!Error_Count
use generic-service
check_interval 1
}
After defining the service, nagios core is unable to read the exit status from the defined command in the nrpe.cfg file at client's end.
The error in my nagios dashboard returns an unknown status:
Asked by Faisal Nawaz
(1 rep)
Nov 16, 2021, 06:57 AM
Last activity: Nov 16, 2021, 02:44 PM
Last activity: Nov 16, 2021, 02:44 PM