Page 1 of 2

Return code of 4 is out of bounds

Posted: Fri Jul 28, 2023 8:43 am
by pintu
I know that there are many inquiries regarding :
(Return code of 4 is out of bounds : /usr/local/nagios/libexec/check_port.pl -p <port> -h <host> (-c <critical> -w <warning> -v)))
but I haven't found an answer, so I would like to ask.

In my Nagios configuration, I have set up:
define service{
use none
host_name TEST
service_description Port 80
check_command check_port.pl! -p 80 -h www.google.com '-w 1 -c 2 -v'
max_check_attempts 1
check_interval 1
retry_interval 1
}
And I'm getting a return:
(Return code of 4 is out of bounds : /usr/local/nagios/libexec/check_port.pl -p <port> -h <host> (-c <critical> -w <warning> -v)))

I am running it from the command line.
./check_port.pl -p 80 -h google.pl -w 1000.0,80% -c 2000.0,100% -v

I get:
PORT 80 OK: google.pl/80 is responding
Which ties to the following command:

Code: Select all

define command{
        command_name    check_port.pl
        command_line    $USER1$/check_port.pl -p $ARG1$ -h $HOSTADDRESS$
        }
Where is the problem?

Re: Return code of 4 is out of bounds

Posted: Mon Jul 31, 2023 2:29 am
by kg2857
From the docs the -c and -w want integer values in seconds. A return value of 4 isn't in the range of 0-3 that are valid. The output described suggests a syntax issue.

Re: Return code of 4 is out of bounds

Posted: Mon Jul 31, 2023 3:26 am
by pintu
Can you write exactly about which syntax you have in mind?
I tried:

Code: Select all

define command{
        command_name    check_port.pl
        command_line    $USER1$/check_port.pl -p $ARG1$ -h $ARG2$ -w $ARG3$ -c $ARG4$ -v
        }

Code: Select all

define command{
        command_name    check_port.pl
        command_line    $USER1$/check_port.pl -p $ARG1$ -h $HOSTADDRESS$ -w $ARG2$ -c $ARG3$ -v
        }
check_command check_port.pl! -p 80 -h www.google.com '-c 1 -w 2 -v'

Re: Return code of 4 is out of bounds

Posted: Tue Aug 01, 2023 3:09 am
by pintu
any idea? someone can help?

Re: Return code of 4 is out of bounds

Posted: Tue Aug 08, 2023 2:32 am
by pintu
Can anyone suggest anything?

Re: Return code of 4 is out of bounds

Posted: Tue Aug 08, 2023 3:25 am
by kg2857
Read the script and find out why it doesn't like the syntax you use, which we see is the issue--syntax in case it was missed...

Re: Return code of 4 is out of bounds

Posted: Tue Aug 08, 2023 11:14 pm
by dameonmills
Can you point out where you think you missed it?

Re: Return code of 4 is out of bounds

Posted: Wed Aug 09, 2023 12:08 pm
by eloyd
You say you're running from the command line, but I'll assume you're running as root. What happens if you run as Nagios user:

Code: Select all

# su - nagios
$ ./check_port.pl -p 80 -h google.pl -w 1000.0,80% -c 2000.0,100% -v

Re: Return code of 4 is out of bounds

Posted: Tue Aug 22, 2023 7:56 am
by pintu
$ ./check_port.pl -p 80 -h google.pl -w 1000.0,80% -c 2000.0,100% -v
-sh: 1: ./check_port.pl: not found
From this level, I cannot go to the location: /usr/local/nagios/libexec/ and that's why it wasn't found.

Re: Return code of 4 is out of bounds

Posted: Thu Aug 24, 2023 9:17 pm
by kg2857
The . translates to the current dir so you have to be in the dir containing the script to run it.

I'm not sure I like the quotes around some of the args in the following, but I could be full of crap...
check_command check_port.pl! -p 80 -h www.google.com '-w 1 -c 2 -v'

Naming a command after the script could cause confusion so I'd name the command check_port.