Forum Discussion
Perl script to display All BigIP pool members
("poolname" "address" "port" "session_state" "priority_group")
preferably in a toggle script under the showPoolMembers() subroutine.
I see the get_priority() method is only listed as a java method. Is there a perl equivalent that could list all of these elements in one script?
thanks in advance for any help.
24 Replies
- None of our methods are Java only. Where are you seeing that documented? iControl is a web service (SOAP) based API so all the methods are language independent. If you choose to use perl, then you have access to all the same methods that you would if you were using Java or .Net.
The methods in the PoolMember interface should get you the info you are looking for. I would query the pools, then pass that list into the LocalLBPool.get_member method. That will give you all the member addresses and ports. You can then call the get_session_enabled_state() method to get the session states and the get_priority method will return your the priority numbers for the specified members.
Also, what is the "showPoolMembers()" subroutine you are referring to? Is that in your code?
Let me know if you need further direction.
-Joe - ltaylor510_5583
Nimbostratus
Joe,
thanks for the information however i am stuck -
the script is now returning this error:
SOAP-ENV:Client Unknown method "{urn:iControl:LocalLB/Pool}:get_priority"
i added the method as follows - apparently this is incorrect - do you have an example I could use? thanks.
sub getPoolMemberStates()
{
my (@pool_list) = @_;
$soapResponse = $PoolMember->get_session_enabled_state
(
SOAP::Data->name(pool_names => [@pool_list])
);
$soapResponse = $PoolMember->get_priority
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse);
@member_state_lists = @{$soapResponse->result};
return @member_state_lists;
} - ltaylor510_5583
Nimbostratus
Joe,
thanks for the information however i am stuck -
the script is now returning this error:
SOAP-ENV:Client Unknown method "{urn:iControl:LocalLB/Pool}:get_priority"
i added the method as follows - apparently this is incorrect - do you have an example I could use? thanks.
sub getPoolMemberStates()
{
my (@pool_list) = @_;
$soapResponse = $PoolMember->get_session_enabled_state
(
SOAP::Data->name(pool_names => [@pool_list])
);
$soapResponse = $PoolMember->get_priority
(
SOAP::Data->name(pool_names => [@pool_list])
); - From the error it looks as if you are attempting to access the LocalLB.Pool.get_priority() method which does not exist. You want to be going to the LocalLB.PoolMember interface. Are you defining your $PoolMember variable corectly?
$PoolMember = SOAP::Lite -> uri('urn:iControl:LocalLB/PoolMember') -> readable(1) -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
Odds are you have declared like this:$PoolMember = SOAP::Lite -> uri('urn:iControl:LocalLB/Pool') -> readable(1) -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
Let me know if this fixes your issue.
-Joe - ltaylor510_5583
Nimbostratus
Hello Joe,
Thanks again for all the pointers - I'm almost there now but I am having issues getting the member_priority array to print the correct values with the @member_state array.
I tried pushing (merging) the arrays but nothing is working. Depending on my foreach loop I either get the correct priority values for each pool to print without the cooresponding member_state value; or I get the correct member_state values without the correct corresponding priority value. Any suggestions on how i could code these arrays in order to print ALL correct values on each line output?
below is the code:
use SOAP::Lite;
----------------------------------------------------------------------------
Validate Arguments
----------------------------------------------------------------------------
my $sHost = $ARGV[0];
my $sPort = $ARGV[1];
my $sUID = $ARGV[2];
my $sPWD = $ARGV[3];
my $sPool = $ARGV[4];
my $sNodeAddr = $ARGV[5];
my $sProtocol = "https";
sub usage()
{
die ("Usage: PoolToggle.pl host port uid pwd ([pool]) \n");
}
if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq ""))
{
usage();
}
----------------------------------------------------------------------------
Transport Information
----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}
$Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> readable(1)
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
$PoolMember = SOAP::Lite
-> uri('urn:iControl:LocalLB/PoolMember')
-> readable(1)
-> proxy("$sProtocol://$sHost:$sPort/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", '')
); };
eval { $Pool->transport->http_request->header
(
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
----------------------------------------------------------------------------
support for custom enum types
----------------------------------------------------------------------------
sub SOAP::Deserializer::typecast
{
my ($self, $value, $name, $attrs, $children, $type) = @_;
my $retval = undef;
if ( "{urn:iControl}Common.EnabledState" == $type )
{
$retval = $value;
}
return $retval;
}
----------------------------------------------------------------------------
Main logic
----------------------------------------------------------------------------
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
&showPoolMembers(@pool_list);
----------------------------------------------------------------------------
Show list of pools and members
----------------------------------------------------------------------------
sub showPoolMembers()
{
my (@pool_list) = @_;
my @sortedPool = sort { lc($a) cmp lc($b) } @pool_list;
my @member_state_lists = &getPoolMemberStates(@sortedPool);
my @member_priority_lists = &getPoolPriority(@sortedPool);
print "Pool Members Enabled State\n";
print "==========================\n";
$i = 0;
foreach $pool (@sortedPool)
{
@priorityCheck = @{@member_priority_lists[$i]};
@memberState = @{@member_state_lists[$i]};
foreach $member_priority (@priorityCheck)
{
$priority = $member_priority->{"priority"};
foreach $member_state (@memberState)
{
$member = $member_state->{"member"};
$addr = $member->{"address"};
$port = $member->{"port"};
$session_state = $member_state->{"session_state"};
----------------------------------------------------------------------------
PRINT THE OUTPUT:
print "$pool:$addr:$port:$session_state:$priority\n";
$i++;
}}}
}
----------------------------------------------------------------------------
returns the status structures for the members of the specified pools
----------------------------------------------------------------------------
sub getPoolMemberStates()
{
my (@pool_list) = @_;
$soapResponse = $PoolMember->get_session_enabled_state
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse);
@member_state_lists = @{$soapResponse->result};
return @member_state_lists;
}
sub getPoolPriority()
{
my (@pool_list) = @_;
$soapResponse2 = $PoolMember->get_priority
(
SOAP::Data->name(pool_names => [@pool_list])
);
&checkResponse($soapResponse2);
@member_priority_list = @{$soapResponse2->result};
return @member_priority_list;
}
&checkResponse($soapResponse);
&checkResponse($soapResponse2);
----------------------------------------------------------------------------
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'll have to check this out this weekend. From a first glance it looks like your issue is with the the loop over the member_state inside the member_priority foreach. Both of those arrays will be the same size for the given pool index. You'll want to do a for loop, looping over the length of those arrays and pull out the separate entries together. I'll get something whipped up for you by Monday.
-Joe - hwidjaja_37598
Altostratus
Pls read next post - hwidjaja_37598
Altostratus
Try the attached file.
Sample output:
./devcentral.pl 10.11.22.33 admin admin_pwd
pool1 10.1.1.1 80 SESSION_STATUS_DISABLED 1
pool1 10.1.1.2 80 SESSION_STATUS_ADDRESS_DISABLED 2
pool2 20.1.1.1 80 SESSION_STATUS_ENABLED 1
pool2 20.1.1.2 80 SESSION_STATUS_ENABLED 1
Is that what you want?
This is my first iControl, so lots of enhancement can be done - Try this out:
sub showPoolMembers() { my (@pool_list) = @_; my @sortedPool = sort { lc($a) cmp lc($b) } @pool_list; my @member_state_lists = &getPoolMemberStates(@sortedPool); my @member_priority_lists = &getPoolPriority(@sortedPool); print "Pool Members Enabled State\n"; print "==========================\n"; $i = 0; for $i (0 .. scalar(@sortedPool)-1) { $pool = @sortedPool[ $i ]; @MemberSessionStateList = @{@member_state_lists[ $i ]}; @MemberPriorityList = @{@member_priority_lists[ $i ]}; for $j (0 .. scalar(@MemberSessionStateList)-1) { $MemberSessionState = @MemberSessionStateList[ $j ]; $MemberPriority = @MemberPriorityList[ $j ]; $member = $MemberSessionState->{"member"}; $address = $member->{"address"}; $port = $member->{"port"}; $session_state = $MemberSessionState->{"session_state"}; $priority = $MemberPriority->{"priority"}; print "$pool:$address:$port:$session_state:$priority\n"; } } }
-Joe - ltaylor510_5583
Nimbostratus
Joe,
Thanks a million - this worked. I really appreciate your help on all this - I can now move on with this project; this has been a learning experience for me.
Have a good one.
Best Regards,
Larry
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com