Simple wrapper plugin gets "return code of 127" error

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.
cylindric
Posts: 40
Joined: Wed May 29, 2013 9:50 am

Simple wrapper plugin gets "return code of 127" error

Post by cylindric »

Hi, folks.

I have a very simple script that wraps up the check_http command, as I'm having all sorts of problems with any non-trivial URLs or check values. (The UI is escaping stuff, then it's escaped again differently before hitting the cmd, so garbage ensues)

In the libexec directory, the permissions are:

Code: Select all

-rwxr-xr-x 1 nagios nagios 528 Oct  7 11:17 check_user_lockout
If I execute it from the command line, I get:

Code: Select all

HTTP OK - HTTP/1.1 302 Found - 0.300 second response time |time=0.299939s;10.000000;30.000000;0.000000 size=960B;;;0
And if I check the exit code, it is 0.

If I execute it from the "test check command" button in CCM, I get:

Code: Select all

COMMAND: /usr/local/nagios/libexec/check_user_lockout -w 10 -c 30
OUTPUT: 
Here's the check_user_lockout script:

Code: Select all

#!/bin/bash
hostname=www.hardcoded.hostname.com
uri=/path.to.file.html?parameter1=value1\&parameter2=value2\&parameter3=value3
warn=10
crit=30

while getopts "w:c:" opt; do
	case $opt in
		w)
			warn=$OPTARG
			;;
		c)
			crit=$OPTARG
	esac
done

./check_http -H $hostname -u $uri -r "\!(This account has been locked out)" -w $warn -c $crit
Here's some debug output I found:

Code: Select all

[1412677140.287574] [2048.1] [pid=1471] Processing: '$USER1$/check_user_lockout-w 10 -c 30'
[1412677140.287651] [2048.1] [pid=1471]   Done.  Final output: '/usr/local/nagios/libexec/check_user_lockout -w 10 -c 30'
[1412677149.326262] [2048.1] [pid=1471]   Done.  Final output: 'DATATYPE::SERVICEPERFDATA       TIMET::1412677149       HOSTNAME::TestHost  SERVICEDESC::User account locked       SERVICEPERFDATA::       SERVICECHECKCOMMAND::check_user_lockout!!!!!!!!        HOSTSTATE::UP   HOSTSTATETYPE::HARD     SERVICESTATE::CRITICAL  SERVICESTATETYPE::HARD      SERVICEOUTPUT::(Return code of 127 is out of bounds - plugin may be missing)'

This is all from Nagios Core VM 3.5.0.
Last edited by cylindric on Tue Oct 07, 2014 10:51 am, edited 1 time in total.
Cyl
Nagios Core 4.3.4 on Ubuntu 16.04.3
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by tmcdonald »

The Test Check Command does have some quirks that need to be considered. For the most part, they are related to escaping input to be safe on the backend, sanitizing output for safe display in a browser, and permissions (particularly for network-based checks). The true test for if something is going to work is to create the check, let it run, and view the results in the browser when it completes.
Former Nagios employee
cylindric
Posts: 40
Joined: Wed May 29, 2013 9:50 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by cylindric »

Sorry, in my excitement at writing so much detail, I forgot the key bit which is that when it actually runs "live", I get an error in the Status Information.

Code: Select all

(Return code of 127 is out of bounds - plugin may be missing)
Cyl
Nagios Core 4.3.4 on Ubuntu 16.04.3
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by tmcdonald »

What are the permissions on the wrapper and the plugin it runs?
Former Nagios employee
cylindric
Posts: 40
Joined: Wed May 29, 2013 9:50 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by cylindric »

All the files in the libexec directory are root:root and permissions are -rwxr-xr-x. I have also tried nagios:nagios, as a couple of other scripts that work are owned that way. All files have a+x though, so shouldn't be a problem.

Where does that return code come from? The script doesn't return 127, but something must be.
Cyl
Nagios Core 4.3.4 on Ubuntu 16.04.3
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by tmcdonald »

That return code is likely from bash or whatever shell you have running it. Let's see if the nagios user can run the plugin from the CLI:

Code: Select all

su - nagios
cd /usr/local/nagios/libexec
./check_user_lockout -w 10 -c 30
Former Nagios employee
cylindric
Posts: 40
Joined: Wed May 29, 2013 9:50 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by cylindric »

Looks okay:

Code: Select all

[root@localhost libexec]# su - nagios
[nagios@localhost ~]$ cd /usr/local/nagios/libexec/
[nagios@localhost libexec]$ ./check_user_lockout -w 10 -c 30
HTTP OK - HTTP/1.1 302 Found - 9.697 second response time |time=9.696582s;10.000000;30.000000;0.000000 size=960B;;;0
[nagios@localhost libexec]$ echo $?
0
[nagios@localhost libexec]$ 
Cyl
Nagios Core 4.3.4 on Ubuntu 16.04.3
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Simple wrapper plugin gets "return code of 127" error

Post by sreinhardt »

That all looks correct, I would agree. Have you saved and applied config, and seen how the actual core interface responds? My honest guess is its a bug with test command button, but only letting nagios actually run and check will tell us.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
cylindric
Posts: 40
Joined: Wed May 29, 2013 9:50 am

Re: Simple wrapper plugin gets "return code of 127" error

Post by cylindric »

I did mention it was an error from an actual 'live' alert.

The CCM write and verify all report no warnings or errors.
Cyl
Nagios Core 4.3.4 on Ubuntu 16.04.3
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Simple wrapper plugin gets "return code of 127" error

Post by sreinhardt »

I wonder if by not capturing the output of check_http, if its set to a different terminals stdout. Let's try changing the end of your script to:

Code: Select all

output="$(./check_http -H $hostname -u $uri -r "\!(This account has been locked out)" -w $warn -c $crit)"
exitcode=$?
echo "$output"
exit $exitcode
You really shouldn't have to do this, but I also can't say I've never captured output from a plugin or executable when wrapping it.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked