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!
Bash script errors out with a code of 127
-
- 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
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?
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
I just did that as follows: /usr/local/nagios/libexec/check_app_status.sh 192.168.1.5scottwilkerson 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 $?
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
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
-
- 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
I just found the error in your command (missing the 1 in the USER macro), change this
to this
Code: Select all
define command {
command_name check_remote_app
command_line $USER$/check_app_status.sh $HOSTADDRESS$
}
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
scottwilkerson wrote:I just found the error in your command (missing the 1 in the USER macro), change thisto thisCode: Select all
define command { command_name check_remote_app command_line $USER$/check_app_status.sh $HOSTADDRESS$ }
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.
-
- 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
Great!zbailey wrote:Thank you. This fixed my issue. It is always a simple issue that I miss.
Locking thread