Tech Tips on DevCentral
   
You are here: Tutorials > Tech Tips

Current Articles | Categories | Search | Syndication

iControl Apps - #19 - Pool Membership Reverse Lookup

by Joe - 4569 views Article Rating

Pool's are collections of pool members which are IP address and ports for a specific back end application server.  Currently through the iControl API there is no direct way to do a reverse lookup of which pools a specified application server is a member of.  This application will, given a pool member specification, do a reverse lookup and list all the associated pools that member is included in.

Usage

The arguments for this application are the address, username, password of the BIG-IP as well as an optional wildcard spec for the address:port of the requested Pool Member.  This is declared in the top of the script with the following param statement.  There is also a Write-Usage function to display the arguments to the user.

 param ( $bigip = $null, $user = $null, $pass = $null, $poolmember = $null ); Set-PSDebug -strict; #------------------------------------------------------------------------- # function Write-Usage #-------------------------------------------------------------------------
 function Write-Usage() { Write-Host "Usage: PoolLookup.ps1 host uid pwd [poolmember]"; exit; }

Initialization

As is with all of my PowerShell scripts, the initialization component will look to see if the iControlSnapIn is loaded into the current PowerShell session.  If not, the Add-PSSnapIn Cmdlet is called to add the snapin into the runtime.  Then a call to the Initialize-F5.iControl cmdlet to setup the connection to the BIG-IP.  If this succeeds, then a call to the Lookup-Pool function is called to lookup the pools containing the requested member address:port combination.

 function Do-Initialize() { if ( (Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn"}) -eq $null ) { Add-PSSnapIn iControlSnapIn
 } $success = Initialize-F5.iControl -HostName $bigip -Username $user -Password $pass; return $success; } #------------------------------------------------------------------------- # Main Application Logic #-------------------------------------------------------------------------
 if ( ($bigip -eq $null) -or ($user -eq $null) -or ($pass -eq $null) ) { Write-Usage; } if ( Do-Initialize ) { if ( $poolmember ) { Lookup-Pool $poolmember; } else { Lookup-Pool; } } else { Write-Error "ERROR: iControl subsystem not initialized" }

Querying Pool Names and Members

The Lookup-Pool function takes an optional argument containing the virtual server address:port query.  If a query is specified, it will attempt to be split apart with a colon separator.

Once the query is disassembled, the Pool list is retrieved as well as the associated pool members.  For each of the pool members , a comparison is done to determine if the input query is a match.  If no query is supplied, the entry is displayed.

The Write-Match then is called to print a spaced formatted output for the results

 function Lookup-Pool() { param([string]$query = $null); $addr = "*"; $port = "*"; if ( $query ) { $addr = $query; $tokens = $query.Split(':'); if ( $tokens.Length -eq 2 ) { $addr = $tokens[0];
 $port = $tokens[1]; } if ( !$addr ) { $addr = "*"; } if ( !$port ) { $port = "*"; } } $pool_list = (Get-F5.iControl).LocalLBPool.get_list(); $member_lists = (Get-F5.iControl).LocalLBPool.get_member($pool_list); for($i=0; $i-lt$pool_list.Length; $i++) { $pool
 = $pool_list[$i]; $member_list = $member_lists[$i]; for($j=0; $j-lt$member_list.Length; $j++) { $maddr = $member_list[$j].address; $mport = $member_list[$j].port; if ( !($query) -or ("${maddr}:${mport}" -like "${addr}:${port}") ) { Write-Match -pool $pool
 -address $maddr -port $mport; } } } } function Write-Match() { param( [string]$pool = $null, [string]$address = $null, [int]$port = $null ); if ( $pool -and $address -and $port ) { $obj = 1 | select PoolMember, Pool $obj.PoolMember = "${address}:${port}";
 $obj.Pool = $pool; $obj; } }

Running The Code

With no query specified, a list of all pool members is displayed along with their associated pools.  Note that pool members may be displayed twice if they belong to more than one pool.  The next few executions pass various wildcard options for th e the ip address and/or port and shows the resulting displays.

 PS> .\PoolLookup.ps1 bigip user pass PoolMember Pool ---------- ---- 10.10.10.149:22 xpbert-ssh
 10.10.10.149:80 xpbert-http 10.10.10.149:81 xpbert-http 20.20.20.102:80 pool_2 10.10.10.149:80 pool_1 20.20.20.101:80 pool_1 10.10.10.201:80 dc-sea-web 10.10.10.202:80 dc-sea-web 10.10.10.203:80 dc-sea-media 10.10.10.211:80 dc-llix-web 10.10.10.212:80 dc-llix-web
 10.10.10.213:80 dc-llix-media 10.10.10.148:22 catbert-ssh 10.10.10.148:80 catbert-http PS> .\PoolLookup.ps1 bigip user pass *:22 PoolMember Pool ---------- ---- 10.10.10.149:22 xpbert-ssh 10.10.10.148:22 catbert-ssh PS .\PoolLookup.ps1 bitip user pass *.149:8*
 PoolMember Pool ---------- ---- 10.10.10.149:80 xpbert-http 10.10.10.149:81 xpbert-http 10.10.10.149:80 pool_1

Conclusion

This script shows the steps on how to do a reverse wildcard lookup for virtual server names that have a destination address matching a specified search criteria.  Similar logic could be performed to do reverse lookups for pool members or node addresses.

Sample Walkthrough

The full source for this application can be found in the iControl Codeshare under PsPoolLookup.



Rate This Article:

COMMENTS

There are currently no comments, be the first to post one.
Only registered users may post comments.
  
Subscriptions: Video  |  Audio  |  Tutorials  |  Tech Tips  |  Features  | 

More...

 

 

Essentials Quick Start Guides
iRules Wiki | iControl SDK | WebAccelerator Wiki iRules | iControl
FirePass Wiki | Advanced Design & Config Wiki WebAccelerator | FirePass

 

Videos

  

Audio

Cache in with LTM and iRules
Can iRules fix my cert mismatch errors?
Concurrent iControl Programming Explained
Cookie LoJack vi iRules
Creating An iControl PowerShell Monitoring Dashboard With Google Charts
Custom SNMP Traps
Exchange Persistence Duality and iRules
FTPS Offload via iRules
Getting Started with pyControl
iControl 101 - #19 - Time Conversions
iControl 101 - #20 - Port Lockdown
iControl 101 - #21 - Rate Classes
iControl 101 - #22 - GTM Data Centers
iControl Apps - #04 - Graceful Server Shutdown
iControl Apps - #05 - Rate Based Statistics
iControl Apps - #06 - Configuration Archiving
iControl Apps - #07 - System Http Statistics
iControl Apps - #08 - System IP Statistics
iControl Apps - #09 - TMM Statistics
iControl Apps - #10 - Bigpipe List
iControl Apps - #11 - Global GTM Statistics
iControl Apps - #12 - Global SSL Statistics
iControl Apps - #13 - System PVA Statistics
iControl Apps - #14 - Global Statistics
iControl Apps - #18 - Virtual Server Reverse Lookup
Investigating the LTM TCP Profile: Acknowledgements
Investigating the LTM TCP Profile: Congestion Control Algorithms
Investigating the LTM TCP Profile: ECN & LTR
Investigating the LTM TCP Profile: Max Syn Retransmissions & Idle Timeout
Investigating the LTM TCP Profile: Nagle’s Algorithm
Investigating the LTM TCP Profile: The Finish Line
Investigating the LTM TCP Profile: Windows & Buffers
iRules 101 - #13 - TCL String Commands Part 1
iRules 101 - #14 - TCL String Commands Part 2
iRules 101 - #15 - TCL List Handling Commands
iRules Event Order
Managing The System Boot Location with iControl
Persisting SSL Connections
Replacing the WebSphere Apache Plugin with iRules
Ruby meets iControl: Creating VIPs
Ruby meets iControl: Making Wide IPs
Ruby Meets iControl: Switching Policies
Ten Steps to iRules Optimization
Unbind your LDAP servers with iRules
v.10 - A new iRules Namespace
v.10 - FastHTTP and Cookie Persistence
v.10 - iRules and the after command
v.10 - New class features in iRules
v.10 - Remote Authorization via TACACS+
v10.1 - Configuring GTM's DNS Security Extensions

  

Features

  

Tutorials

  

iControl

  

iRules

  

Monitoring & Management

  

Advanced Design & Config

  

93,050 Members in 191 Countries and Growing!

Join DevCentral Today!

About DevCentral

F5 DevCentral is your source for the best technical documentation, discussion forums, blogs, media and more related to application delivery networking.

So dive in, meet your peers, and get familiar with DevCentral. We hope it makes your job easier and helps you get more from your F5 investment. If new to DevCentral, check out the Getting Started section. And if you have any problems, or think something could be easier to use, let us know.

Got It !

We've received your comment and transmitted it directly to DevCentral HQ.

Thanks for taking time to let us know what's on your mind. At DevCentral | Community Matters!

Get In Touch With Us

Have questions, suggestions or just want to get something off your chest?

Use our handy form below to Direct Connect with DevCentral Mission Control.

Send Us Feedback      or