For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Perl Script to check GTM Wideip and its associated Pool status

Problem this snippet solves:

This Perl script will query the status and state of Wideip and its Associated Pool and pool member state

How to use this snippet:

gtmstate.pl < gtmsyncmember> < user> < pass> < wideip>

Code :

#!/usr/bin/perl

use SOAP::Lite;
use Data::Dumper;

my $BIGIP = $ARGV[0];
my $User = $ARGV[1];
my $Pass = $ARGV[2];
my $sWideIP = $ARGV[3];


sub SOAP::Transport::HTTP::Client::get_basic_credentials
{
  return "$User" => "$Pass";
}

 
&getWideIPPoolList($sWideIP);


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

sub GetInterface()
{
  my ($module, $name) = @_;

  $interface = SOAP::Lite
    -> uri("urn:iControl:$module/$name")
    -> readable(1)
    -> proxy("https://$BIGIP/iControl/iControlPortal.cgi");
  eval { $interface->transport->http_request->header
  ( 'Authorization' => 'Basic ' . MIME::Base64::encode("$User:$Pass", '') ); };

  return $interface;
}


sub getWideIPPoolList()
{
  my ($wideIP) = @_;
  
  print "WIDEIP: $wideIP\n";
  $GTMWideip = &GetInterface("GlobalLB", "WideIP");  
  
  $soapResponse = $GTMWideip->get_wideip_pool(SOAP::Data->name(wide_ips => [$wideIP]));
  $soapResponse2 = $GTMWideip->get_enabled_state(SOAP::Data->name(wide_ips => [$wideIP])); 
  $soapResponse3 = $GTMWideip->get_object_status(SOAP::Data->name(wide_ips => [$wideIP])); 
   
  
  @WideIPPoolAofA = @{$soapResponse->result};
  @WideIPPoolA = @{@WideIPPoolAofA[0]}; 
  
  @states =@{$soapResponse2->result};
  @avail=@{$soapResponse3->result};
  
  print "Wideip State::@states\n";
  foreach $availa (@avail)
  {
   $availb=$availa->{"availability_status"};
   print "Wideip Status:$availb\n";
   }  


  foreach $WideIPPool (@WideIPPoolA)
  {
    $pool_name = $WideIPPool->{"pool_name"};
    print "  Pool $pool_name\n";
    &getWideIPPoolMemberList($pool_name);
    
 }

}

sub getWideIPPoolMemberList()
{
  my ($pool) = @_;  
  $GTMPool = &GetInterface("GlobalLB", "Pool");
  $GTMPoolmember=&GetInterface("GlobalLB","PoolMember");
  
  $soapResponse = $GTMPool->get_member(SOAP::Data->name(pool_names => [$pool]) );
  $soapResponse2=$GTMPool->get_enabled_state(SOAP::Data->name(pool_names => [$pool]));
  $soapResponse3=$GTMPool->get_object_status(SOAP::Data->name(pool_names => [$pool]));
  
  @states = @{$soapResponse2->result};
  @poolstate = @{$soapResponse3->result};
  
  
  foreach $poolavail (@poolstate)
  {
   $pools=$poolavail->{"availability_status"};
   print "Pool Status:$pools\n";
   }


  @PoolMemberDefinitionAofA = @{$soapResponse->result};
  @PoolMemberDefinitionA = @{@PoolMemberDefinitionAofA[0]};
  
  foreach $PoolMemberDefinition(@PoolMemberDefinitionA)
  {
    $member = $PoolMemberDefinition->{"member"};
    $address = $member->{"address"};
    $port = $member->{"port"};
    print "  MEMBER: ${address}:${port}:STATE:@states\n";
   }

}
Updated Jun 06, 2023
Version 2.0

1 Comment

  • Hi, Can you share any sample output of this script. It would be good to view before trying it into production