(Return code of 127 is out of bounds - plugin may be missing

An open discussion forum for obtaining help with Nagios Core. Nagios Core users of all experience levels are welcome here. Subforum have been created for the discussion of Nagios Core and Nagios Plugin development.

NOTE: The SourceForge.net mailing lists have been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby scottwilkerson » Mon Nov 18, 2019 7:06 am

kmartin2007 wrote:ozadmin@dalsrvitmon03:~$ su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'
Password:
su: Authentication failure
ozadmin@dalsrvitmon03:~$ su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'
Password:
su: Authentication failure
ozadmin@dalsrvitmon03:~$


You need to be root before running these
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17024
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby kmartin2007 » Mon Nov 18, 2019 12:25 pm

scottwilkerson wrote:
kmartin2007 wrote:ozadmin@dalsrvitmon03:~$ su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'
Password:
su: Authentication failure
ozadmin@dalsrvitmon03:~$ su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'
Password:
su: Authentication failure
ozadmin@dalsrvitmon03:~$


You need to be root before running these





root@dalsrvitmon03:~# su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'
sh: 1: cannot create tmp_res1: Permission denied
UNKNOWN: /usr/bin/wget --output-document=tmp_html --no-check-certificate -S returns no result!255
kmartin2007
 
Posts: 62
Joined: Thu Nov 14, 2019 3:31 pm

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby vho » Mon Nov 18, 2019 12:48 pm

When I run the command as root, this is the error message that I get.

root@dalsrvitmon03:~# su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'
sh: 1: cannot create tmp_res1: Permission denied
UNKNOWN: /usr/bin/wget --output-document=tmp_html --no-check-certificate -S returns no result!255
vho
 
Posts: 11
Joined: Thu Nov 14, 2019 4:13 pm

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby lmiltchev » Mon Nov 18, 2019 2:34 pm

I believe, the "tmp_res1" file is creating in the "current" directory (the one in are in), so try switching to "/tmp":
Code: Select all
cd /tmp

and rerun your check:
Code: Select all
su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'

Did it work now?
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
lmiltchev
QA Manager
 
Posts: 12681
Joined: Mon May 23, 2011 12:15 pm

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby kmartin2007 » Mon Nov 18, 2019 5:44 pm

lmiltchev wrote:I believe, the "tmp_res1" file is creating in the "current" directory (the one in are in), so try switching to "/tmp":
Code: Select all
cd /tmp

and rerun your check:
Code: Select all
su nagios -c '/usr/local/nagios/libexec/check_url.pl http://www.espdata.org.au/index.asp; echo $?'

Did it work now?




Yes it does


root@dalsrvitmon03:~# cd /tmp
root@dalsrvitmon03:/tmp# su nagios -c '/usr/local/nagios/libexec/check_url.pl ht tp://www.espdata.org.au/index.asp; echo $?'
OK: 200 OK
0
root@dalsrvitmon03:/tmp#
kmartin2007
 
Posts: 62
Joined: Thu Nov 14, 2019 3:31 pm

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby scottwilkerson » Tue Nov 19, 2019 7:43 am

Looking over the code there is no directory set for the temp files and there is a modification in the reviews I'd like you to try

Please replace check_url.pl with the following
Code: Select all
#!/usr/bin/perl
# (C) Unknown author at https://exchange.nagios.org/directory/Plugins/Websites%2C-Forms-and-Transactions/check_url/details
#
# Changes:
# 2016-01-07: Stephan Ferraro
# Added PID number for temporary files, that the script can run in parallel with multiple processes.
# Added a check if one arguments is defined at script startup. -- Stephan Ferraro

use strict;

if ($#ARGV == -1)
{
print STDERR "usage: check_url.pl URL\n";
exit 1;
}

my $wget = '/usr/bin/wget --output-document=/tmp/tmp_'.$$.'.html --no-check-certificate -S';
my ($url) = @ARGV;
my @OK = ("200");
my @WARN = ("400", "401", "403", "404", "408");
my @CRITICAL = ("500", "501", "502", "503", "504");

my $TIMEOUT = 20;

my %ERRORS = ('UNKNOWN' , '-1',
'OK' , '0',
'WARNING', '1',
'CRITICAL', '2');

my $state = "UNKNOWN";
my $answer = "";

$SIG{'ALRM'} = sub {
print ("ERROR: check_url Time-Out $TIMEOUT s \n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);

system ("$wget $url 2>/tmp/tmp_".$$.".res1");

if (! open STAT1, "/tmp/tmp_".$$.".res1") {
print ("$state: $wget returns no result!");
exit $ERRORS{$state};
}
close STAT1;

`cat /tmp/tmp_$$.res1|grep 'HTTP/1'|tail -n 1 >/tmp/tmp_$$.res`;
open (STAT, "/tmp/tmp_".$$.".res");
my @lines = <STAT>;
close STAT;

if ($lines[0]=~/HTTP\/1\.\d+ (\d+)( .*)/) {
my $errcode = $1;
my $errmesg = $2;

$answer = $answer . "$errcode $errmesg";

if ('1' eq &chkerrwarn($errcode) ) {
$state = 'WARNING';
} elsif ('2' eq &chkerrcritical($errcode)) {
$state = 'CRITICAL';
} elsif ('0' eq &chkerrok($errcode)) {
$state = 'OK';
}
}

sub chkerrcritical {
my $err = $1;
foreach (@CRITICAL){
if ($_ eq $err) {
return 2;
}
}
return -1;
}


sub chkerrwarn {
my $err = $1;
foreach (@WARN){
if ($_ eq $err) {
return 1;
}
}
return -1;
}

sub chkerrok {
my $err = $1;
foreach (@OK){
if ($_ eq $err) {
return 0;
}
}
return -1;
}

`rm /tmp/tmp_$$.html /tmp/tmp_$$.res /tmp/tmp_$$.res1`;

print ("$state: $answer\n");
exit $ERRORS{$state};
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17024
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby kmartin2007 » Tue Nov 19, 2019 9:26 am

scottwilkerson wrote:Looking over the code there is no directory set for the temp files and there is a modification in the reviews I'd like you to try

Please replace check_url.pl with the following
Code: Select all
#!/usr/bin/perl
# (C) Unknown author at https://exchange.nagios.org/directory/Plugins/Websites%2C-Forms-and-Transactions/check_url/details
#
# Changes:
# 2016-01-07: Stephan Ferraro
# Added PID number for temporary files, that the script can run in parallel with multiple processes.
# Added a check if one arguments is defined at script startup. -- Stephan Ferraro

use strict;

if ($#ARGV == -1)
{
print STDERR "usage: check_url.pl URL\n";
exit 1;
}

my $wget = '/usr/bin/wget --output-document=/tmp/tmp_'.$$.'.html --no-check-certificate -S';
my ($url) = @ARGV;
my @OK = ("200");
my @WARN = ("400", "401", "403", "404", "408");
my @CRITICAL = ("500", "501", "502", "503", "504");

my $TIMEOUT = 20;

my %ERRORS = ('UNKNOWN' , '-1',
'OK' , '0',
'WARNING', '1',
'CRITICAL', '2');

my $state = "UNKNOWN";
my $answer = "";

$SIG{'ALRM'} = sub {
print ("ERROR: check_url Time-Out $TIMEOUT s \n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);

system ("$wget $url 2>/tmp/tmp_".$$.".res1");

if (! open STAT1, "/tmp/tmp_".$$.".res1") {
print ("$state: $wget returns no result!");
exit $ERRORS{$state};
}
close STAT1;

`cat /tmp/tmp_$$.res1|grep 'HTTP/1'|tail -n 1 >/tmp/tmp_$$.res`;
open (STAT, "/tmp/tmp_".$$.".res");
my @lines = <STAT>;
close STAT;

if ($lines[0]=~/HTTP\/1\.\d+ (\d+)( .*)/) {
my $errcode = $1;
my $errmesg = $2;

$answer = $answer . "$errcode $errmesg";

if ('1' eq &chkerrwarn($errcode) ) {
$state = 'WARNING';
} elsif ('2' eq &chkerrcritical($errcode)) {
$state = 'CRITICAL';
} elsif ('0' eq &chkerrok($errcode)) {
$state = 'OK';
}
}

sub chkerrcritical {
my $err = $1;
foreach (@CRITICAL){
if ($_ eq $err) {
return 2;
}
}
return -1;
}


sub chkerrwarn {
my $err = $1;
foreach (@WARN){
if ($_ eq $err) {
return 1;
}
}
return -1;
}

sub chkerrok {
my $err = $1;
foreach (@OK){
if ($_ eq $err) {
return 0;
}
}
return -1;
}

`rm /tmp/tmp_$$.html /tmp/tmp_$$.res /tmp/tmp_$$.res1`;

print ("$state: $answer\n");
exit $ERRORS{$state};



Just to be clear you want me to replace the entire script (below) with this right?


#!/usr/bin/perl

use strict;

my $wget = '/usr/bin/wget --output-document=tmp_html --no-check-certificate -S';
my ($url) = @ARGV;
my @OK = ("200");
my @WARN = ("400", "401", "403", "404", "408");
my @CRITICAL = ("500", "501", "502", "503", "504");

my $TIMEOUT = 20;

my %ERRORS = ('UNKNOWN' , '-1',
'OK' , '0',
'WARNING', '1',
'CRITICAL', '2');

my $state = "UNKNOWN";
my $answer = "";

$SIG{'ALRM'} = sub {
print ("ERROR: check_url Time-Out $TIMEOUT s \n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);

system ("$wget $url 2>tmp_res1");
for (1..1000){
}

if (! open STAT1, "tmp_res1") {
print ("$state: $wget returns no result!");
exit $ERRORS{$state};
}
close STAT1;

`cat tmp_res1|grep 'HTTP/1'|tail -n 1 >tmp_res`;
open (STAT, "tmp_res");
my @lines = <STAT>;
close STAT;

if ($lines[0]=~/HTTP\/1\.\d+ (\d+)( .*)/) {
my $errcode = $1;
my $errmesg = $2;

$answer = $answer . "$errcode $errmesg";

if ('1' eq &chkerrwarn($errcode) ) {
$state = 'WARNING';
} elsif ('2' eq &chkerrcritical($errcode)) {
$state = 'CRITICAL';
} elsif ('0' eq &chkerrok($errcode)) {
$state = 'OK';
}
}

sub chkerrcritical {
my $err = $1;
foreach (@CRITICAL){
if ($_ eq $err) {
return 2;
}
}
return -1;
}


sub chkerrwarn {
my $err = $1;
foreach (@WARN){
if ($_ eq $err) {
return 1;
}
}
return -1;
}

sub chkerrok {
my $err = $1;
foreach (@OK){
if ($_ eq $err) {
return 0;
}
}
return -1;
}

`rm tmp_html tmp_res tmp_res1`;

print ("$state: $answer\n");
exit $ERRORS{$state};
kmartin2007
 
Posts: 62
Joined: Thu Nov 14, 2019 3:31 pm

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby scottwilkerson » Tue Nov 19, 2019 9:27 am

yes
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17024
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby kmartin2007 » Tue Nov 19, 2019 9:35 am

scottwilkerson wrote:Looking over the code there is no directory set for the temp files and there is a modification in the reviews I'd like you to try

Please replace check_url.pl with the following
Code: Select all
#!/usr/bin/perl
# (C) Unknown author at https://exchange.nagios.org/directory/Plugins/Websites%2C-Forms-and-Transactions/check_url/details
#
# Changes:
# 2016-01-07: Stephan Ferraro
# Added PID number for temporary files, that the script can run in parallel with multiple processes.
# Added a check if one arguments is defined at script startup. -- Stephan Ferraro

use strict;

if ($#ARGV == -1)
{
print STDERR "usage: check_url.pl URL\n";
exit 1;
}

my $wget = '/usr/bin/wget --output-document=/tmp/tmp_'.$$.'.html --no-check-certificate -S';
my ($url) = @ARGV;
my @OK = ("200");
my @WARN = ("400", "401", "403", "404", "408");
my @CRITICAL = ("500", "501", "502", "503", "504");

my $TIMEOUT = 20;

my %ERRORS = ('UNKNOWN' , '-1',
'OK' , '0',
'WARNING', '1',
'CRITICAL', '2');

my $state = "UNKNOWN";
my $answer = "";

$SIG{'ALRM'} = sub {
print ("ERROR: check_url Time-Out $TIMEOUT s \n");
exit $ERRORS{"UNKNOWN"};
};
alarm($TIMEOUT);

system ("$wget $url 2>/tmp/tmp_".$$.".res1");

if (! open STAT1, "/tmp/tmp_".$$.".res1") {
print ("$state: $wget returns no result!");
exit $ERRORS{$state};
}
close STAT1;

`cat /tmp/tmp_$$.res1|grep 'HTTP/1'|tail -n 1 >/tmp/tmp_$$.res`;
open (STAT, "/tmp/tmp_".$$.".res");
my @lines = <STAT>;
close STAT;

if ($lines[0]=~/HTTP\/1\.\d+ (\d+)( .*)/) {
my $errcode = $1;
my $errmesg = $2;

$answer = $answer . "$errcode $errmesg";

if ('1' eq &chkerrwarn($errcode) ) {
$state = 'WARNING';
} elsif ('2' eq &chkerrcritical($errcode)) {
$state = 'CRITICAL';
} elsif ('0' eq &chkerrok($errcode)) {
$state = 'OK';
}
}

sub chkerrcritical {
my $err = $1;
foreach (@CRITICAL){
if ($_ eq $err) {
return 2;
}
}
return -1;
}


sub chkerrwarn {
my $err = $1;
foreach (@WARN){
if ($_ eq $err) {
return 1;
}
}
return -1;
}

sub chkerrok {
my $err = $1;
foreach (@OK){
if ($_ eq $err) {
return 0;
}
}
return -1;
}

`rm /tmp/tmp_$$.html /tmp/tmp_$$.res /tmp/tmp_$$.res1`;

print ("$state: $answer\n");
exit $ERRORS{$state};






I replaced it and looks like the website checks are now working!!!


ESPDATA.ORG.AU
Perform Extra Service Actions
OK 2019-11-19 14:32:50 0d 0h 2m 22s 1/2 OK: 200 OK
kmartin2007
 
Posts: 62
Joined: Thu Nov 14, 2019 3:31 pm

Re: (Return code of 127 is out of bounds - plugin may be mis

Postby scottwilkerson » Tue Nov 19, 2019 9:42 am

kmartin2007 wrote:I replaced it and looks like the website checks are now working!!!


ESPDATA.ORG.AU
Perform Extra Service Actions
OK 2019-11-19 14:32:50 0d 0h 2m 22s 1/2 OK: 200 OK


Awesome!

Locking thread
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17024
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Previous

Return to Nagios Core

Who is online

Users browsing this forum: No registered users and 18 guests