cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Problem this snippet solves:

This application will replicate the network map functionality found in the BIG-IP management GUI with a perl console application.

The BIG-IP Management GUI has a feature called the Network Map that includes a hierarchical summary of the objects on the system and their current statuses. This tech tip will take that GUI component and break it down into the underlying iControl method calls and present an alternative implementation from within perl.

Code :

#!/usr/bin/perl
#----------------------------------------------------------------------------
# The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
# Software Development Kit for iControl"; you may not use this file except in
# compliance with the License. The License is included in the iControl
# Software Development Kit.
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is iControl Code and related documentation
# distributed by F5.
#
# The Initial Developer of the Original Code is F5 Networks,
# Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
# Inc. All Rights Reserved.  iControl (TM) is a registered trademark of F5 Networks, Inc.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU General Public License (the "GPL"), in which case the
# provisions of GPL are applicable instead of those above.  If you wish
# to allow use of your version of this file only under the terms of the
# GPL and not to allow others to use your version of this file under the
# License, indicate your decision by deleting the provisions above and
# replace them with the notice and other provisions required by the GPL.
# If you do not delete the provisions above, a recipient may use your
# version of this file under either the License or the GPL.
#----------------------------------------------------------------------------

#use SOAP::Lite + trace => qw(method debug);
use SOAP::Lite;
use MIME::Base64;

#----------------------------------------------------------------------------
# Validate Arguments
#----------------------------------------------------------------------------
my $sHost = $ARGV[0];
my $sPort = 443;
my $sUID = $ARGV[1];
my $sPWD = $ARGV[2];
my $sProtocol = "https";

$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;

my @g_vs_list;
my @g_vs_destination_list;
my @g_vs_pool_list;
my @g_vs_rule_list;

if ( ("80" eq $sPort) or ("8080" eq $sPort) )
{
$sProtocol = "http";
}

if ( ($sHost eq "") or ($sPort eq "") or ($sUID eq "") or ($sPWD eq "") )
{
&usage();
}

#----------------------------------------------------------------------------
# usage
#----------------------------------------------------------------------------
sub usage()
{
print "Usage: LocalTrafficMap.pl host uid pwd\n";
exit();
}

#----------------------------------------------------------------------------
# Transport Information
#----------------------------------------------------------------------------
sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
return "$sUID" => "$sPWD";
}

$VirtualServer = SOAP::Lite
-> uri('urn:iControl:LocalLB/VirtualServer')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval {$VirtualServer->transport->http_request->header
(
'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
$Pool = SOAP::Lite
-> uri('urn:iControl:LocalLB/Pool')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval {$Pool->transport->http_request->header
(
'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };
$PoolMember = SOAP::Lite
-> uri('urn:iControl:LocalLB/PoolMember')
-> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi");
eval {$PoolMember->transport->http_request->header
(
'Authorization' => 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
); };

sub SOAP::Deserializer::typecast
{
my ($self, $value, $name, $attrs, $children, $type) = @_;
my $retval = undef;
if ( $type eq "{urn:iControl}LocalLB.AvailabilityStatus" )
{ $retval = $value; }
elsif ( $type eq "{urn:iControl}LocalLB.EnabledStatus" )
{ $retval = $value; }
return $retval;
}


&PrintLocalTrafficMap();

sub PrintLocalTrafficMap()
{
my @vs_list = GetVSList();
my @destination_list = GetVSDestinationList();
my @pool_list = GetVSPoolList();
my @vs_statuses = GetVSStatus();
my @pool_statuses = GetPoolStatus();
my @MemberStatAofA = GetPoolMemberStatus();
my @VSRuleAofA = GetVSRuleList();

print "***** SITE MAP FOR BIG-IP $sHOST ******\n";

for $i (0 .. scalar(@vs_list)-1)
{
$vs = @vs_list[$i];
$AddressPort = @destination_list[$i];
$address = $AddressPort->{"address"};
$port = $AddressPort->{"port"};

$stat_str = GetObjectStatus(@vs_statuses[$i]);
print "$vs (VS) ${address}:${port}\n";
print "|    $stat_str\n";
if ( length(@pool_list[$i]) > 0 )
{
$pool = @pool_list[$i];
$stat_str = GetObjectStatus(@pool_statuses[$i]);
print "+-> $pool (P)\n";
print "    | $stat_str\n";

@MemberStatA = @{$MemberStatAofA[$i]};
for $j (0 .. scalar(@MemberStatA)-1)
{
$MemberStat = @MemberStatA[$j];
$member = $MemberStat->{"member"};
$addr = $member->{"address"};
$port = $member->{"port"};
$stat_str = GetObjectStatus($MemberStat->{"object_status"});
print "    +-> $addr:$port (PM)\n";
print "        | $stat_str\n";
}
}
if ( scalar(@VSRuleAofA[$i]) > 0 )
{
@VSRuleA = @{$VSRuleAofA[$i]};
for $j (0 .. scalar(@VSRuleA)-1 )
{
$RuleDef = @VSRuleA[$j];
$rule_name = $RuleDef->{"rule_name"};
print "+-> $rule_name (R)\n";
}
}
}
}

sub GetVSStatus()
{
my $soapResponse = $VirtualServer->get_object_status (
SOAP::Data->name(virtual_servers => [&GetVSList()])
);
my @VS_statuses = @{$soapResponse->result};
return @VS_statuses;
}

sub GetPoolStatus()
{
my $soapResponse = $Pool->get_object_status (
SOAP::Data->name(pool_names => [&GetVSPoolList()])
);
my @pool_statuses = @{$soapResponse->result};
return @pool_statuses;
}

sub GetPoolMemberStatus()
{
my $soapResponse = $PoolMember->get_object_status (
SOAP::Data->name(pool_names => [&GetVSPoolList()])
);
my @poolmember_statuses = @{$soapResponse->result};
return @poolmember_statuses;
}

sub GetVSList()
{
$len = scalar(@g_vs_list);
if ( 0 == scalar(@g_vs_list) )
{
$soapResponse = $VirtualServer->get_list();
@g_vs_list = @{$soapResponse->result};
}
return @g_vs_list;
}

sub GetVSDestinationList()
{
if ( 0 == scalar(@g_vs_destination_list) )
{
$soapResponse = $VirtualServer->get_destination (
SOAP::Data->name(virtual_servers => [&GetVSList()])
);
@g_vs_destination_list = @{$soapResponse->result};
}
return @g_vs_destination_list;
}

sub GetVSPoolList()
{
if ( 0 == scalar(@g_vs_pool_list) )
{
$soapResponse = $VirtualServer->get_default_pool_name (
SOAP::Data->name(virtual_servers => [&GetVSList()])
);
@g_vs_pool_list = @{$soapResponse->result};
}
return @g_vs_pool_list;
}

sub GetVSRuleList()
{
if ( 0 == scalar(@g_vs_rule_list) )
{
$soapResponse = $VirtualServer->get_rule(
SOAP::Data->name(virtual_servers => [&GetVSList()])
);
@g_vs_rule_list = @{$soapResponse->result};
}
return @g_vs_rule_list;
}

sub GetObjectStatus()
{
my ($object_status) = (@_);

$avail = $object_status->{"availability_status"};
$enabled = $object_status->{"enabled_status"};

$s_avail = "";
$s_enabled = "";
$s_desc = $object_status->{"status_description"};

if ( $avail eq "AVAILABILITY_STATUS_GREEN" ) {
$s_avail = "Available";
} elsif ( $avail eq "AVAILABILITY_STATUS_YELLOW" ) {
$s_avail = "Unvailable";
} elsif ( $avail eq "AVAILABILITY_STATUS_RED" ) {
$s_avail = "Unvailable";
} elsif ( $avail eq "AVAILABILITY_STATUS_BLUE" ) {
$s_avail = "Unknown";
} elsif ( $avail eq "AVAILABILITY_STATUS_GRAY" ) {
$s_avail = "Unvailable";
} else {
$s_avail = "Unknown";
}

if ( $enabled eq "ENABLED_STATUS_ENABLED" ) {
$s_enabled = "Enabled";
} elsif ( $enabled eq "ENABLED_STATUS_DISABLED" ) {
$s_enabled = "Disabled";
} elsif ( $enabled eq "ENABLED_STATUS_DISABLED_BY_PARENT" ) {
$s_enabled = "Disabled";
}

return "$s_avail ($s_enabled) $s_desc";
}
Comments
sebonline_11124
Nimbostratus
Nimbostratus
Don't miss to remove "" into the code
paul_dawson_258
Nimbostratus
Nimbostratus
I'm getting "500 Can't connect to 10.51.170.108:443 (certificate verify failed) at perl-traffic-map.pl line 195."
Hi Paul, you can fix this by changing the three lines that contain the proxy setting to: -> proxy("$sProtocol://$sHost:$sPort/iControl/iControlPortal.cgi", ssl_opts => [ SSL_verify_mode => 0 ]);
paul_dawson_258
Nimbostratus
Nimbostratus
Thanks Neils!
DMA_95966
Nimbostratus
Nimbostratus
Hi Paul , could you please past here update script and just checking if we can get output using VIP address ?
wndak_159397
Nimbostratus
Nimbostratus

How to use different partitions?

 

silverem_84897
Nimbostratus
Nimbostratus

Interesting but coud you add irules with host header link to pools and members, please /

 

Version history
Last update:
‎07-Mar-2015 16:51
Updated by:
Contributors