Bash script errors out with a code of 127

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
zbailey
Posts: 4
Joined: Thu Sep 26, 2019 5:02 pm

Bash script errors out with a code of 127

Post 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!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bash script errors out with a code of 127

Post 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 $?
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
zbailey
Posts: 4
Joined: Thu Sep 26, 2019 5:02 pm

Re: Bash script errors out with a code of 127

Post 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
zbailey
Posts: 4
Joined: Thu Sep 26, 2019 5:02 pm

Re: Bash script errors out with a code of 127

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bash script errors out with a code of 127

Post 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$
}
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
zbailey
Posts: 4
Joined: Thu Sep 26, 2019 5:02 pm

Re: Bash script errors out with a code of 127

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Bash script errors out with a code of 127

Post by scottwilkerson »

zbailey wrote:Thank you. This fixed my issue. It is always a simple issue that I miss.
Great!

Locking thread
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked