!/usr/bin/perl
this script expects input of the following:
F5 device ($Host) in the form of a string,
User ID ($UID) in the form of a string,
Password ($PASSWD) in the form of a string and
Member ($member_def) in the form of ":"
we also assume transport is HTTPS on port 443 to the F5 device
we then print out the Pools to which the Pool Member belongs
and the Virtual Servers which use those Pools
use SOAP::Lite;
my $Host = $ARGV[0];
my $UID = $ARGV[1];
my $PASSWD = $ARGV[2];
my $member_def = $ARGV[3];
sub usage()
{
die ("usage: poolMemberInfo.pl host usedID passwd addr:port\n");
}
if (($Host eq "") or ($UID eq "") or ($PASSWD eq "") or ($member_def eq ""))
{
usage();
}
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$UID" => "$PASSWD";
}
set up Virtual Server, Pool and PoolMember SOAP Objects
$VirtualServer = SOAP::Lite
-> uri('urn:iControl:LocalLB/VirtualServer')
-> proxy("https://$Host:443/iControl/iControlPortal.cgi");
$Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> readable(1)
-> proxy("https://$Host:443/iControl/iControlPortal.cgi");
$PoolMember = SOAP::Lite
-> uri('urn:iControl:LocalLB/PoolMember')
-> readable(1)
-> proxy("https://$Host:443/iControl/iControlPortal.cgi");
pass login credentials
eval { $Pool->transport->http_request->header (
'Authorization' =>
'Basic ' . MIME::Base64::encode("$UID:$PASSWD", ''));
};
eval { $PoolMember->transport->http_request->header (
'Authorization' =>
'Basic ' . MIME::Base64::encode("$UID:$PASSWD", ''));
};
eval { $VirtualServer->transport->http_request->header (
'Authorization' =>
'Basic ' . MIME::Base64::encode("$sUID:$sPWD", ''));
};
if port is missing, set to 0
($IP, $port) = split(/:/, $member_def,2);
if ($port eq "") {
$port = "0";
}
Get list of Pools
$soapResponse = $Pool->get_list();
&checkResponse($soapResponse);
@pool_list = @{$soapResponse->result};
Get list of all Pool Members
$soapResponse = $Pool->get_member( SOAP::Data->name( pool_names => [@pool_list] ) );
&checkResponse($soapResponse);
@member_lists = @{$soapResponse->result};
Loop through member list to build up array of pools that contain the member
$i = 0;
foreach $pool_name (@pool_list) {
@member_list = @{@member_lists[$i]};
foreach $member (@member_list) {
$addr = $member->{"address"};
$pt = $member->{"port"};
if ($addr eq $IP and $pt == $port) {
fill up pool_names structure
push @PoolNames, $pool_name;
}
}
$i++;
}
pool member is not in any pools
if ($PoolNames < 0) {
print "$IP:$port not in any pools and thus, no virtual servers\n";
exit;
}
print out the pool names that contain the member
print "$IP:$port is in the following pools\n";
foreach $pool_name (@PoolNames) {
print "$pool_name\n";
}
Get list of Virtual Servers
$soapResponse = $VirtualServer->get_list();
&checkResponse($soapResponse);
@VS_list = @{$soapResponse->result};
Get list of default pools for the Virtual Servers
$soapResponse = $VirtualServer->get_default_pool_name(
SOAP::Data->name(virtual_servers => [@VS_list])
);
&checkResponse($soapResponse);
@default_pool_list = @{$soapResponse->result};
Loop through the default pool list to build up the array of Virtual Servers that use the pools
that contain the pool member
$i = 0;
foreach $default_pool_name (@default_pool_list) {
foreach $pool_name (@PoolNames) {
if ($pool_name eq $default_pool_name) {
push @VSNames, $VS_list[$i];
}
}
$i++;
}
pools not the default for any virtual servers
if ($VSNames < 0) {
print "$IP:$port not in any default pool of a virtual server\n";
exit;
}
print out the virtual server names with default pool that contains the member
print "$IP:$port is in the default pool of the following virtual servers\n";
foreach $virtual_name (@VSNames) {
print "$virtual_name\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();
}
}