http://www.perlmonks.org?node_id=1020687

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

I am tring to write a new script using use LWP::UserAgent

#!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent; use JSON qw( decode_json ); use Data::Dumper; use Nagios::Plugin; use FindBin qw($Bin); use lib "$Bin/../lib"; my $jboss_url = 'http://admin:jboss@10.208.30.77:9990/management/?oper +ation=resource&name=server-state&include-runtime=true&json.pretty'; my $ua = LWP::UserAgent->new; $ua->credentials('10.208.30.77:9990','something','admin','jboss'); my $response = $ua->get ( $jboss_url ); print $response; my $json = $response->decoded_content; print Dumper $json;

My problem is i am getting the following error and I am not sure how to fix it..

./check_jboss_state.pl HTTP::Response=HASH(0x1448eb0)$VAR1 = 'Server closed connection withou +t sending any data back at /usr/local/nagios/perl/lib/Net/HTTP/Method +s.pm line 345. ';

An Update i have now got it working... and here's how needless to say it was my lack of understanding... In the end I amended

my $jboss_url = 'http://admin:jboss@10.208.30.77:9990/management/?oper +ation=resource&name=server-state&include-runtime=true&json.pretty';

To

$jboss_url = 'http://10.208.30.77:9990/management/?operation=resource& +name=server-state&include-runtime=true&json.pretty';

and this

$ua->credentials('10.208.30.77:9990','something','admin','jboss');

to this

$ua->credentials('10.208.30.77:9990','ManagementRealm','admin','jboss' +);
All is well again

Replies are listed 'Best First'.
Re: Server closed connection without sending any data back
by blue_cowdawg (Monsignor) on Feb 26, 2013 at 13:42 UTC

    Something to consider: some web servers are "agent sensitive". Check out this doco:

    $ua->agent('Checkbot/0.4 ' . $ua->_agent); $ua->agent('Checkbot/0.4 '); # same as above $ua->agent('Mozilla/5.0'); $ua->agent(""); # don't identify
    I'd pick something benign like 'Mozilla/5.0' to set your agent's ID to and you may have more success. I've run into this issue a few times...


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Server closed connection without sending any data back
by sundialsvc4 (Abbot) on Feb 26, 2013 at 13:27 UTC

    I would start by entering that exact URL-string on a web browser, while running the browser debugger (e.g. Firebug), in order to easily see what is going and coming across the wire.

    Next, do the same thing on the server side:   examine the logs.