Forum Discussion

jj24_43946's avatar
jj24_43946
Icon for Nimbostratus rankNimbostratus
Jun 13, 2011

Help with LocalLB::Monitor::create_template

Hi, I'm trying to do two things with iControl using Perl:

 

 

1) Create a monitor template

 

2) Set the attributes of the template

 

 

In advance I'll say that I'm not too hot at creating data structures, so I'm terribly sorry for my hackish looking code. I used the SDK reference for LocalLB::Monitor::create_template.

 

 

First, the monitor template:

 

 

When I run the script, I get this error:

 

 

SOAP-ENV:Server Cannot convert a struct to a string.

 

 

I'm going to paste the dump of the structure first, followed by the code:

 

 

$ ./create_template_test.pl $VAR1 = [

 

{

 

'is_read_only' => 0,

 

'is_directly_usable' => 1,

 

'timeout' => 16,

 

'interval' => 5,

 

'dest_ipport' => {

 

'ipport' => {

 

'address' => '192.168.1.5',

 

'port' => '80'

 

},

 

'address_type' => { 'ATYPE_EXPLICIT_ADDRESS_EXPLI CIT_PORT' => '192.168.1.5:80'

 

}

 

},

 

'parent_template' => ''

 

}

 

];

 

 

 

Here's the code:

 

 

!/usr/bin/perl

 

use SOAP::Lite;

 

use Data::Dumper;

 

my ( $sUID, $sPWD, $sHost, $sMonitor ) = ( 'admin', 'somepassword', '10.10.0.1', 'test_monitor' );

 

 

----------------------------------------------------------------------------

 

Transport Information

 

----------------------------------------------------------------------------

 

sub SOAP::Transport::HTTP::Client::get_basic_credentials

 

{

 

return "$sUID" => "$sPWD";

 

}

 

 

$monitor = SOAP::Lite

 

-> uri('urn:iControl:LocalLB/Monitor')

 

-> readable(1)

 

-> proxy("https://$sHost/iControl/iControlPortal.cgi");

 

 

----------------------------------------------------------------------------

 

Attempt to add auth headers to avoid dual-round trip

 

----------------------------------------------------------------------------

 

eval { $Pool->transport->http_request->header

 

(

 

'Authorization' =>

 

'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')

 

); };

 

 

----------------------------------------------------------------------------

 

Main logic

 

----------------------------------------------------------------------------

 

 

CREATE DATA STRUCTURE

 

my @monitor_struct1;

 

my $template_def =

 

{

 

template_name => 'test_template1',

 

template_type => 'HTTP'

 

};

 

push @monitor_struct1, $template_def;

 

 

my @monitor_struct2;

 

my @monitor_struct3; for dest_ipport

 

my @monitor_struct4; for address_type

 

my @monitor_struct5; for address and port

 

my @monitor_struct6; test

 

my $address_type_attr =

 

{

 

ATYPE_EXPLICIT_ADDRESS_EXPLICIT_PORT => '192.168.1.5:80'

 

};

 

push @monitor_struct4, $address_type_attr;

 

 

my $address_port_attr =

 

{

 

address => '192.168.1.5',

 

port => '80'

 

};

 

push @monitor_struct5, $address_port_attr;

 

 

my $dest_ipport_attr =

 

{

 

address_type => @monitor_struct4,

 

ipport => @monitor_struct5

 

};

 

push @monitor_struct6, $dest_ipport_attr;

 

 

my $template_attr =

 

{

 

parent_template => '',

 

interval => 5,

 

timeout => 16,

 

dest_ipport => @monitor_struct6,

 

is_read_only => 0,

 

is_directly_usable => 1

 

 

};

 

 

push @monitor_struct2, $template_attr;

 

 

print Dumper(\@monitor_struct2); exit;

 

 

 

 

END DATA STRUCTURE

 

 

 

 

$soapResponse = $monitor->create_template(

 

SOAP::Data->name(templates => [@monitor_struct1]),

 

SOAP::Data->name(template_attributes => [@monitor_struct2])

 

);

 

&checkResponse($soapResponse);

 

print "Monitor $sMonitor created successfully\n";

 

 

----------------------------------------------------------------------------

 

checkResponse makes sure the error isn't a SOAP error

 

----------------------------------------------------------------------------

 

sub checkResponse()

 

{

 

my ($soapResponse) = (@_);

 

if ( $soapResponse->fault )

 

{

 

print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";

 

exit();

 

}

 

}

 

 

I haven't even gotten to 2, setting the monitor attributes, since I can't create one yet.

 

 

Can someone please give me a tip on what I'm doing wrong here? Thanks so much.

 

 

Justin
  • Instead of digging through your code, I'll take the easy way out and toss along some code that has worked for me in the past. Let me know if it doesn't work and I'll try to dig into yours a bit more:

     

     

    sub createMonitorTemplate()
    {
        $MonitorTemplate = {
            template_name => "joestemplate",
            template_type => "TTYPE_ICMP"
        };
        $IPPortDefinition = {
            address => "10.10.10.10",
            port => 80
        };
        $MonitorIPPort = {
            address_type => "ATYPE_STAR_ADDRESS",
            ipport => $IPPortDefinition
        };
        $CommonAttributes = {
            parent_template => 'icmp',
            interval => '60',
            timeout => '15', 
            dest_ipport => $MonitorIPPort,
            is_read_only => "false",
            is_directly_usable => "true"
        };
        
        print "Creating Monitor Template...\n";
        
        $soapResponse = $Monitor->create_template(
            SOAP::Data->name(templates => [$MonitorTemplate]),
            SOAP::Data->name(template_attributes => [$CommonAttributes])
        );
        &checkResponse($soapResponse);
    }

     

     

    Hope this helps out. Again, let me know if not, and I'll see what I can do to get yours working for you...

     

     

    -Joe