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.