Bash script errors out with a code of 127
Posted: Thu Sep 26, 2019 5:13 pm
I created a bash script to use wget and grep for 302 and make sure app is up and alive.
(server.cfg)
define service {
use local-service
host_name server
service_description App Status
check_command check_remote_app
notifications_enabled 1
}
(commands.cfg)
define command {
command_name check_remote_app
command_line $USER$/check_app_status.sh $HOSTADDRESS$
}
(check_app_status.sh)
#!/bin/bash
HOSTNAME=$1
wget -o /usr/local/nagios/var/$HOSTNAME.txt $HOSTNAME
if grep -q '302' /usr/local/nagios/var/$HOSTNAME.txt; then
echo "OK: $HOSTNAME is responding correctly for HTTPS"
exit 0
else
echo "CRITICAL: $HOSTNAME HTTPS is down!"
exit 2
fi
---------------------------------
Both the bash script and the .txt files have permissions of root:nagios
I can run the script as nagios user in command line, but as soon as nagios does the check through web ui it fails. (Return code of 127 is out of bounds. Check if plugin exists)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -- this passes and no issues with my config files. I have other plugins working correctly. Please help! Thank you!
(server.cfg)
define service {
use local-service
host_name server
service_description App Status
check_command check_remote_app
notifications_enabled 1
}
(commands.cfg)
define command {
command_name check_remote_app
command_line $USER$/check_app_status.sh $HOSTADDRESS$
}
(check_app_status.sh)
#!/bin/bash
HOSTNAME=$1
wget -o /usr/local/nagios/var/$HOSTNAME.txt $HOSTNAME
if grep -q '302' /usr/local/nagios/var/$HOSTNAME.txt; then
echo "OK: $HOSTNAME is responding correctly for HTTPS"
exit 0
else
echo "CRITICAL: $HOSTNAME HTTPS is down!"
exit 2
fi
---------------------------------
Both the bash script and the .txt files have permissions of root:nagios
I can run the script as nagios user in command line, but as soon as nagios does the check through web ui it fails. (Return code of 127 is out of bounds. Check if plugin exists)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg -- this passes and no issues with my config files. I have other plugins working correctly. Please help! Thank you!