Beau Landeaux has asked for the wisdom of the Perl Monks concerning the following question:

We monitor our web servers using LWP. We monitor them from two Solaris 5.7 hosts (running Perl 5.6.1 and 5.6.2). Both hosts, on the same subnet, monitor connectivity to our servers every 10 minutes (their crons are synched and staggered so the actual monitoring is every 5 minutes).

The host running Perl 5.6.2 is notorious for timing out on connections. When it does not return a "read timeout" the connection attempt just hangs--completely hangs. That said, from time to time the program returns a legitimate error--one identical to the one returned by the second monitoring host. Still, the failing host reports more than 3 times the errors and most of them result in hangs.

I've even taken to calling the Perl program with a shell script that kicks off an assassin process to kill the hung process when it exceeds my time limit. I go to that extreme because I haven't been able to trap the problem via timeout() or alarm() (main code loop below).

So, I've had only minimal success from this host. Because it sometimes works as advertised, I feel that the appropriate modules are present. To "fix" the problem I decided to install Perl 5.8.4 on another host on a different subnet, along with all the appropriate modules. (Open SSL is already present on the Solaris 5.7 candidate.)

Since it was already running Perl 5.6.1, I installed 5.8.4 as follows:

make distclean rm -f config.sh Policy.sh sh Configure -des -Dcc=gcc make make test make install perl -V cd /usr/local/bin ln -s /usr/local/src/perl-5.8.4/perl perl ln -s /usr/local/src/perl-5.8.4/utils/perldoc perldoc ln -s /usr/local/src/perl-5.8.4/utils/perlbug perlbug ln -s /usr/local/src/perl-5.8.4/utils/perlcc perlcc ln -s /usr/local/src/perl-5.8.4/utils/pl2pm pl2pm
All worked as expected and Perl -V reported the following:

Summary of my perl5 (revision 5 version 8 subversion 4) configuration: Platform: osname=solaris, osvers=2.7, archname=sun4-solaris uname='sunos nada 5.7 generic_106541-27 sun4u sparc sunw,ultra-enterprise' config_args='-des -Dcc=gcc' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O', cppflags='-fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.7' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='gcc', ldflags =' -L/usr/local/lib ' libpth=/usr/local/lib /usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc perllibs=-lsocket -lnsl -ldl -lm -lc libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib' Characteristics of this binary (from libperl): Compile-time options: USE_LARGE_FILES Built under solaris Compiled at Sep 8 2004 09:01:01 @INC: /usr/local/lib/perl5/5.8.4/sun4-solaris /usr/local/lib/perl5/5.8.4 /usr/local/lib/perl5/site_perl/5.8.4/sun4-solaris /usr/local/lib/perl5/site_perl/5.8.4 /usr/local/lib/perl5/site_perl .

Then I installed what I think are all the needed modules:

/usr/local/src/HTML-Tagset-3.03 /usr/local/src/HTML-Parser-3.36 /usr/local/src/URI-1.18 /usr/local/src/libwww-perl-5.800 /usr/local/src/libwww-perl-5.800 /usr/local/src/MailTools-1.64 /usr/local/src/LWP-Protocol-http-SocketUnix /usr/local/src/Net-SSH-Perl-1.25 /usr/local/src/Net-SSH-0.08

Again, all goes well. Then I run a test https connection and I receive the following error:

Can't locate object method "new" via package "LWP::Protocol::https::Socket"

I've tried reinstalling that, but I still get the same error. Anyone have any ideas as to what I may be missing?

Before I receive a ton of answers asking "Why didn't you install thus-n-so?" or "Why didn't you do this or that?" let me do my penance now and say, because I didn't know any better.

Humbly yours,

Perl example code for timeout() and alarm() follows:

#----------------------------------------------------------------# # Use for-loop to allow two tries on red alerts. # #----------------------------------------------------------------# for (my $n=1; $n<=$retry; $n++) { @http_err = ""; # Reinitialize every time through. $ua = ""; # '' $response = ""; # '' $request = ""; # '' $headers = ""; # '' $body = ""; # '' $code = ""; # '' $desc = ""; # '' #----------------------------------------------------------# # If serialization of the URL requested, append hostname # # and seconds (from time() function) patameters. # #----------------------------------------------------------# if ($opt_s or $serialize) { sleep(2); $url = "$http_cmd"; $url_suffix = "hostname=$host&seqnumber=" . time(); $url .= ($url =~ /\?/) ? "\&${url_suffix}" : "\?${url_suffix}"; } $ua = LWP::UserAgent->new(); $ua->env_proxy(); # Check proxy settings. echo("$n. Checking connection to $uiPID\n"); echo("\$ua->agent('DMC $0/%I%')\n"); $ua->agent("DMC $0/%I%"); echo("\$response = \$ua->timeout($timeout)\n"); $response = $ua->timeout($timeout); ($opt_v or $URL_opt_v) && print "${sp}\$response=|$response|\n"; #----------------------------------------------------------------# # Wrap this in alarm trap to (hopefully) kill hanging # # requests. # # # $http_OK = 1; # Hope for the best. # $msg = "Alarm Timeout! ($url)"; # local $SIG{ALRM} = sub { # echo("$msg [\$@=|$@|]\n"); # $http_OK = 0; # }; # $timeout_alarm = $timeout + 5; # ($opt_v or $URL_opt_v) && echo("alarm($timeout_alarm)\n"); # alarm($timeout_alarm); # # echo("\$request = new HTTP::Request('GET', '$url')\n"); # $request = new HTTP::Request("GET", "$url"); # ($opt_v or $URL_opt_v) && print "${sp}\$request=|$request|\n"; # # echo("\$response = \$ua->request($request)\n"); # $response = $ua->request($request); # # ($opt_v or $URL_opt_v) && echo("alarm(0)\n"); # alarm(0); # Halt alarm. # # if ($@) # Propagate any errors (if any). # { # @http_err = "$@"; # foreach (@http_err) # Propagate any errors (if any). { print "${sp}\$@=|$_|\n"; } # $@ = ""; # } # if ($@) # # # #----------------------------------------------------------------# $null_n = $response =~ s/\x00//g; # Strip nulls $null_n ||= 0; if ($null_n) { $msg = "${sp}Removed $null_n nulls from \$response\n"; $len = length($response); $msg .= "${sp}\$response now $len bytes\n"; $subject = "$surname: NOTICE Nulls In HTTP Response"; email("$subject", "$msg", $support); if ($opt_v) { print "${sp}Removed $null_n nulls from \$response\n"; $len = length($response); print "${sp}\$response now at $len bytes\n"; } } ($opt_v or $URL_opt_v) && print "${sp}\$response=|$response|\n"; #----------------------------------------------------------# # In case of Alarm Timeout, $http_OK will be zero. We'll # # still try to capture the following info, but we'll also # # be testing both $http_OK and $response_OK before giving # # our blessing for the connectivity test. # #----------------------------------------------------------# $response_OK = ($response->is_success); echo("\$code = \$response->code\n"); $code = $response->code; ($opt_v or $URL_opt_v) && print "${sp}\$code = |$code|\n"; echo("\$desc = HTTP::Status::status_message($code)\n"); $desc = HTTP::Status::status_message($code); ($opt_v or $URL_opt_v) && print "${sp}\$desc = |$desc|\n"; #----------------------------------------------------------# # Get headers # #----------------------------------------------------------# echo("\$headers = \$response->headers_as_string\n"); $headers = $response->headers_as_string; if ($opt_v or $URL_opt_v) { @headers = split(/\n/,$headers); # Split on newlines foreach (@headers) { print "${sp}headers=$_\n"; } } #--------------------------------------------------------------# # $http_OK means we didn't alarm() out. $response_OK is from # # "$response_OK = ($response->is_success);" above. If both # # of these look good, then we check next for any HTTP output # # we're supposed to find. # #--------------------------------------------------------------# if ($http_OK and $response_OK) { #----------------------------------------------------------# # If we have expected or alternate responses, then check # # them before sounding the "All clear." # #----------------------------------------------------------# if ( (defined($expd_response) and $expd_response ne "") or (defined($alt_response ) and $alt_response ne "") ) { #----------------------------------------------------# # Get body -- print as needed. # #----------------------------------------------------# echo("\$body = \$response->content\n"); $body = $response->content; @body = split(/\n/,$body); # Split body on newlines if ($opt_v or $URL_opt_v) { foreach (@body) { print "${sp}content=$_\n" } } # if ($opt_v or $URL_opt_v) @grep_response = grep(/$expd_response/, @body); $response_n = @grep_response; #----------------------------------------------------# # If 1st response found, look for any optional/add'l.# #----------------------------------------------------# if ( $response_n > 0 && defined($addl_response) && $addl_response ne "" ) { @grep_response = grep(/$addl_response/, @body); $response_n = @grep_response; } #----------------------------------------------------# # Response not found, any alternate response? # #----------------------------------------------------# if ($response_n == 0) { if (defined($alt_response) and $alt_response ne "") { @grep_response = grep(/$alt_response/, @body); $response_n = @grep_response; } } #----------------------------------------------------# # Neither expected nor alternate response found. # #----------------------------------------------------# if ($response_n == 0) { if ($n > 1) # for (my $n=1; $n<=$retry; $n++) { $epage_msg = "$host: Web connection to $uiPID " . "failed (expected response not found)"; notify_support(); # Modifies $epage_msg $msg = "$host|$uiPID|$url|$alert|$epage_msg"; no strict 'refs'; ${$alert}++; use strict 'refs'; ELS_Agent("$msg"); } next; # Iterate "for (my $n=1; $n<=$retry; $n++)" } } # if (defined($expd_response) and .. #------------------------------------------------------# # Else, $http_OK is sufficient for "All clear." # #------------------------------------------------------# $shortdesc = "Successful web connection to $uiPID"; $n++; # Incr $n--no need to try again; it was successful. $msg = "$host|$uiPID|$url|green|$shortdesc|"; $green++; ELS_Agent("$msg"); echo("$0: $shortdesc\n"); last; # for (my $n=0; $n<=1; $n++) } # if ($http_OK) elsif ($n > ($retry - 1)) # Something's amuck. { $epage_msg = "$host: Web connection to $uiPID failed"; if (@http_err) { $epage_msg .= " ["; foreach (@http_err) { $epage_msg .= "$_ "; } $epage_msg =~ s/\s+$/\]/; } notify_support(); # Modifies $epage_msg (appends to it). $msg = "$host|$uiPID|$url|$alert|$epage_msg"; no strict 'refs'; ${$alert}++; use strict 'refs'; ELS_Agent("$msg"); } # if ($http_OK); elsif ($n > 1) else { sleep(2); } # if ($http_OK); elsif ($n > 1); else } # for (my $n=0; $n<=1; $n++)

Replies are listed 'Best First'.
Re: Can't locate object method "new"
by dragonchild (Archbishop) on Sep 09, 2004 at 18:20 UTC
    Are you installing LWP with the same perl that you running the scripts with? Have you made sure to do a 'use lib' for the directory that LWP is in, assuming you're not installing it as root?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Installed as root. I added the following to my program (same stuff I got from "perl -V"--didn't know if I needed'em all):
      use lib "/usr/local/lib/perl5/5.8.4/sun4-solaris"; use lib "/usr/local/lib/perl5/5.8.4"; use lib "/usr/local/lib/perl5/site_perl/5.8.4/sun4-solaris"; use lib "/usr/local/lib/perl5/site_perl/5.8.4"; use lib "/usr/local/lib/perl5/site_perl";
      Same result. I have no objection to wiping all Perl off the host and reinstalling it all from scratch again
        There's a much simpler solution, but it's just not an obvious one. Plus, reinstalling Perl isn't a quick thing to do. I'd create a simple testcase that reproduces the problem, before doing much more.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested