Page 1 of 1

Bash script errors out with a code of 127

Posted: Thu Sep 26, 2019 5:13 pm
by zbailey
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!

Re: Bash script errors out with a code of 127

Posted: Fri Sep 27, 2019 6:57 am
by scottwilkerson
So you are passing the $HOSTADDRESS$ to this script

Did you test the script from the command line to see if you gt the expected results?

Code: Select all

/usr/local/nagios/libexec/check_app_status.sh 192.168.0.1
echo $?

Re: Bash script errors out with a code of 127

Posted: Fri Sep 27, 2019 9:41 am
by zbailey
scottwilkerson wrote:So you are passing the $HOSTADDRESS$ to this script

Did you test the script from the command line to see if you gt the expected results?

Code: Select all

/usr/local/nagios/libexec/check_app_status.sh 192.168.0.1
echo $?
I just did that as follows: /usr/local/nagios/libexec/check_app_status.sh 192.168.1.5
Responded with: OK: 192.168.1.5 is responding correctly for HTTPS
Then I ran: echo $?
Responded with: 0

Re: Bash script errors out with a code of 127

Posted: Fri Sep 27, 2019 10:24 am
by zbailey
scottwilkerson wrote:So you are passing the $HOSTADDRESS$ to this script

Did you test the script from the command line to see if you gt the expected results?

Code: Select all

/usr/local/nagios/libexec/check_app_status.sh 192.168.0.1
echo $?

Code: Select all

[root@nagtst]# cd /usr/local/nagios/
[root@nagtst nagios]# libexec/check_app_status.sh 192.168.1.5
OK: 192.168.1.5 is responding correctly for HTTPS
[root@nagtst nagios]# echo $?
0

Re: Bash script errors out with a code of 127

Posted: Fri Sep 27, 2019 10:35 am
by scottwilkerson
I just found the error in your command (missing the 1 in the USER macro), change this

Code: Select all

define command {
command_name check_remote_app
command_line $USER$/check_app_status.sh $HOSTADDRESS$
}
to this

Code: Select all

define command {
command_name check_remote_app
command_line $USER1$/check_app_status.sh $HOSTADDRESS$
}

Re: Bash script errors out with a code of 127

Posted: Fri Sep 27, 2019 11:57 am
by zbailey
scottwilkerson wrote:I just found the error in your command (missing the 1 in the USER macro), change this

Code: Select all

define command {
command_name check_remote_app
command_line $USER$/check_app_status.sh $HOSTADDRESS$
}
to this

Code: Select all

define command {
command_name check_remote_app
command_line $USER1$/check_app_status.sh $HOSTADDRESS$
}

Thank you. This fixed my issue. It is always a simple issue that I miss.

Re: Bash script errors out with a code of 127

Posted: Fri Sep 27, 2019 12:23 pm
by scottwilkerson
zbailey wrote:Thank you. This fixed my issue. It is always a simple issue that I miss.
Great!

Locking thread