Page 5 of 5

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

Posted: Mon Nov 18, 2019 7:06 am
by scottwilkerson
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

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

Posted: Mon Nov 18, 2019 12:25 pm
by kmartin2007
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

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

Posted: Mon Nov 18, 2019 12:48 pm
by vho
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

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

Posted: Mon Nov 18, 2019 2:34 pm
by lmiltchev
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?

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

Posted: Mon Nov 18, 2019 5:44 pm
by kmartin2007
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#

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

Posted: Tue Nov 19, 2019 7:43 am
by scottwilkerson
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};

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

Posted: Tue Nov 19, 2019 9:26 am
by kmartin2007
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};

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

Posted: Tue Nov 19, 2019 9:27 am
by scottwilkerson
yes

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

Posted: Tue Nov 19, 2019 9:35 am
by kmartin2007
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

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

Posted: Tue Nov 19, 2019 9:42 am
by scottwilkerson
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