Skip to content

Instantly share code, notes, and snippets.

@joel74
Created September 15, 2017 03:13
Show Gist options
  • Save joel74/e64e4539b3d24ce9d9fda4c97b9ccce6 to your computer and use it in GitHub Desktop.
Save joel74/e64e4539b3d24ce9d9fda4c97b9ccce6 to your computer and use it in GitHub Desktop.
Get-F5SyncStatus
Function Get-F5SyncStatus{
<#
.SYNOPSIS
Retrieve the sync status details for the specific BIG-IP device
#>
[cmdletBinding()]
param (
$F5Session=$Script:F5Session
)
#Test that the F5 session is in a valid format
Test-F5Session($F5Session)
$SyncStatus = $F5Session.BaseURL -replace "/ltm/", "/cm/sync-status"
$JSON = Invoke-F5RestMethod -Method Get -Uri $SyncStatus -F5Session $F5Session
$JSON = Resolve-NestedStats -F5Session $F5Session -JSONData $JSON
<#
If available (v12+), retrieve the nested description values and return as a single value.
The nested stats are still available in the returned object, but this means that one doesn't need to dig into
'https://localhost/mgmt/tm/cm/syncStatus/0/details'.nestedStats.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details/0'.nestedStats.entries.details.description,
'https://localhost/mgmt/tm/cm/syncStatus/0/details'.nestedStats.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details/1'.nestedStats.entries.details.description,
'https://localhost/mgmt/tm/cm/syncStatus/0/details'.nestedStats.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details/2'.nestedStats.entries.details.description, etc.
to retrieve this information.
#>
If ($JSON.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details'.nestedStats.entries){
$Description = ''
$Nested_Stats = $JSON.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details'.nestedStats.entries
$Nested_Stats | Get-Member -MemberType NoteProperty | Select Name | %{
#For each entry, retrieve the value / details
$Description += $($Nested_Stats.$($_.Name).nestedStats.entries.details.description).toString() + "`r`n"
}
#Add composite description value to JSON
$JSON.entries | Add-Member -Name sync_description -MemberType NoteProperty $Description -Force
}
$JSON.entries
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment