Ps Local Traffic Map
Problem this snippet solves:
This application will replicate the network map functionality found in the BIG-IP management GUI with a PowerShell console implementation.
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 Windows PowerShell.
Code :
#---------------------------------------------------------------------------- # 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-2008 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. #---------------------------------------------------------------------------- param ( $g_bigip = $null, $g_uid = $null, $g_pwd = $null ) Set-PSDebug -strict; $g_vs_list = $null; $g_vs_pool_list = $null; $g_vs_rule_list = $null; #------------------------------------------------------------------------- # function Show-Usage #------------------------------------------------------------------------- function Show-Usage() { Write-Host "Usage: LocalTrafficSummary.ps1 host uid pwd"; exit; } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Sanitize-Array() { param ( [string[]]$in ); $out = $null; foreach ($item in $in) { if ( $item.Length -gt 0 ) { if ( $null -eq $out ) { $out = (, $item) } else { $out += $item } } } return $out; } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Get-VSList() { if ( $null -eq $g_vs_list ) { $g_vs_list = (Get-F5.iControl).LocalLBVirtualServer.get_list(); } return $g_vs_list; } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Get-VSPoolList() { if ( $null -eq $g_vs_pool_list ) { $g_vs_pool_list = (Get-F5.iControl).LocalLBVirtualServer.get_default_pool_name( (Get-VSList) ); } return $g_vs_pool_list; } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Get-VSRuleList() { if ( $null -eq $g_vs_rule_list ) { $g_vs_rule_list = (Get-F5.iControl).LocalLBVirtualServer.get_rule( (Get-VSList) ); } return $g_vs_rule_list; } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Get-ObjectStatus() { param ( $object_status ); $avail = $object_status.availability_status; $enabled = $object_status.enabled_status; $s_avail = ""; $s_enabled = ""; $s_desc = $object_status.status_description; switch($avail) { "AVAILABILITY_STATUS_GREEN" { $s_avail = "Available"; } "AVAILABILITY_STATUS_YELLOW" { $s_avail = "Unavailable"; } "AVAILABILITY_STATUS_RED" { $s_avail = "Unavailable"; } "AVAILABILITY_STATUS_BLUE" { $s_avail = "Unknown"; } "AVAILABILITY_STATUS_GRAY" { $s_avail = "Unavailable"; } default { $s_avail = "Unknown"; } } switch($enabled) { "ENABLED_STATUS_ENABLED" { $s_enabled = "Enabled"; } "ENABLED_STATUS_DISABLED" { $s_enabled = "Disabled"; } "ENABLED_STATUS_DISABLED_BY_PARENT" { $s_enabled = "Disabled"; } default { } } return "$s_avail ($s_enabled) $s_desc"; } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Print-LocalTrafficMap() { $vs_list = Get-VSList; $pool_list = Get-VSPoolList; $vs_statuses = (Get-F5.iControl).LocalLBVirtualServer.get_object_status( $vs_list ); $pool_statuses = (Get-F5.iControl).LocalLBPool.get_object_status( (Sanitize-Array $pool_list) ); $MemberStatAofA = (Get-F5.iControl).LocalLBPoolMember.get_object_status( $pool_list ); $VSRuleAofA = Get-VSRuleList; Write-Host "***** SITE MAP FOR BIG-IP $g_bigip ******" for($i=0; $i -lt $vs_list.Length; $i++) { $vs = $vs_list[$i]; $stat_str = Get-ObjectStatus $vs_statuses[$i]; Write-Host "$vs (VS)"; Write-Host "| $stat_str" if ( $pool_list[$i].Length -gt 0 ) { $pool = $pool_list[$i]; $stat_str = Get-ObjectStatus $pool_statuses[$i]; Write-Host "+-> $pool (P)" Write-Host " | $stat_str" for($j=0; $j -lt $MemberStatAofA[$i].Length; $j++) { $MemberStat = $MemberStatAofA[$i][$j]; $member = $MemberStat.member; $addr = $member.address; $port = $member.port; $stat_str = Get-ObjectStatus $MemberStat.object_status; Write-Host " +-> ${addr}:${port} (PM)" Write-Host " | $stat_str" } } if ( $VSRuleAofA[$i].Length -gt 0 ) { for ($j=0; $j -lt $VSRuleAofA[$i].Length; $j++) { $RuleDef = $VSRuleAofA[$i][$j]; $rule_name = $RuleDef.rule_name; Write-Host "+-> $rule_name (R)" } } } } #------------------------------------------------------------------------- # #------------------------------------------------------------------------- function Do-Initialize() { $snapin = Get-PSSnapin | Where-Object { $_.Name -eq "iControlSnapIn" } if ( $null -eq $snapin ) { Add-PSSnapIn iControlSnapIn } $success = Initialize-F5.iControl -HostName $g_bigip -Username $g_uid -Password $g_pwd; return $success; } #------------------------------------------------------------------------- # Main Application Logic #------------------------------------------------------------------------- if ( ($g_bigip -eq $null) -or ($g_uid -eq $null) -or ($g_pwd -eq $null) ) { Show-Usage; } if ( Do-Initialize ) { Print-LocalTrafficMap } else { Write-Error "ERROR: iControl subsystem not initialized" }
Published Mar 09, 2015
Version 1.0CodeCentral_194
Cirrus
Joined May 05, 2019
CodeCentral_194
Cirrus
Joined May 05, 2019
- paul_dawson_258NimbostratusHi, I would like to include the VIP destination address into the output. Could you provide a function definition for this?
- SriniM_188537Nimbostratus
Below command does not work. Any changes to this ? Also I am chaning the partition to a custom partition with the command " (Get-( ( ,"Partition_a"))"
This command failing (Get-