Forum Discussion

Geronimo_Martin's avatar
Geronimo_Martin
Icon for Nimbostratus rankNimbostratus
Mar 10, 2016

External Monitor on Perl

Hi, I have set this External Monitor, on a BIG-IP Virtual, just whit GTM:

 

use LWP::UserAgent;

 

my $url = ''; my $timeout = 20; my $agent = 'MA Performance Test Agent'; my $username = '1158553890'; my $password = '121e4f6b2d93d3f508359c8700406a1b992733af'; my $ua = LWP::UserAgent->new; $ua->agent($agent); $ua->timeout($timeout);

 

my $requestbody = qq({"client":{"osName":"Android","osVersion":"4.3","platform":"Android"},"password":"${password}","username":"${username}","requestId":"d094e3c7-e599-480e-83b6-f651344c66d6","rememberMe":false}});

 

my $request = HTTP::Request->new("POST","${url}/login",undef,$requestbody); $request->header('Accept' => "application/json", 'Accept-Charset' => "utf-8", 'cid' => 'a4a99111-b62a-4483-9598-8cfd13ed5ad4'); $request->content_type('application/json'); my $response = $ua->request($request);

 

if ($response->is_success) { my $content = $response->decoded_content; print "SUCCESSFUL RESPONSE\nBEGIN\n$content\nEND\n"; my ($email) = ($content =~ m/"email":"([^"]*)"/); print "Email address: $email\n"; } else { printf "FAIL (%d) : %s '%s'\n", $response->code, $url, $response->status_line; }

 

If I run this from the command line, the script runs successfully, they returns me the print "SUCCESSFUL RESPONSE" . But on the BIG-IP web, the monitor doesn't. Do you have any idea about this!?.

 

Regards.

 

1 Reply

  • When invoked as an external monitor, the perl "print" command with no other options returns the printed text to the bigd daemon (which invoked the monitor script) rather than displaying the printed text on the console.

    The sample perl monitor (/config/monitors/arg_example) shows how to send results to a file instead of return them bigd:

     Open the output file
    my $outfile = "/var/arg_ex_out";
    open( OUTF, ">>$outfile" );
     Print the command line args
    my $cmdlinearg = 0;
    print OUTF "---- Command Line Args ----\n";
    while( $cmdlinearg = shift @ARGV ) {
       print OUTF $cmdlinearg, "\n";
    }
    

    Remember that any data returned via the "print" command to bigd is interpreted as a successful monitor probe:

     Arbitrarily tell bigd that the node is up.
    print "up\n";
    exit(0);