POSH-LTM-Rest
POSH-LTM-Rest copied to clipboard
Add Get Sync Status support
I would like to check the status of a GroupName before I make changes. Would it be possible to get a sync status?
Knowing sync dates would be good have, and its sync partner(s).
I believe these three endpoints provide the info you're looking for:
https://LTM.domain.com/mgmt/tm/cm/syncStatus https://LTM.domain.com/mgmt/tm/cm/failover-status https://LTM.domain.com/mgmt/tm/sys/db/configsync.localconfigtime
Outside of this module, I've created Get-LTMSyncStatus and Get-LTMActiveStatus, which use the first two endpoints. Below is an example using them.
I had to do a little searching, but I found that the third endpoint will give you the last sync time in unix seconds, which can be converted to a date.
PS C:\Users\egagn> $LTMs = @"
>> location1-ltm-1.company.com
>> location1-ltm-2.company.com
>> location2-ltm-1.company.com
>> location2-ltm-2.company.com
>> "@
PS C:\Users\egagn> $LTMs = $LTMs.split("`n").trim()
PS C:\Users\egagn>
PS C:\Users\egagn> Get-LTMSyncStatus $Credential $LTMs
LTM Status
--- ------
location1-ltm-1.company.com In Sync
location1-ltm-2.company.com In Sync
location2-ltm-1.company.com In Sync
location2-ltm-2.company.com In Sync
PS C:\Users\egagn> Get-LTMActiveStatus $Credential $LTMs
LTM Status
--- ------
location1-ltm-1.company.com STANDBY
location1-ltm-2.company.com ACTIVE
location2-ltm-1.company.com STANDBY
location2-ltm-2.company.com ACTIVE
Questions that come to mind:
- Do you want to propose sample output of one or more functions?
- Do you have any interest in working on this yourself?
- We'll want to figure out how to fit this code in. Joel has been working on restructuring things as discussed in #138 and this probably fits better into a different module than this one.
I was just thinking keeping it simple Get-LTMSyncStatus would only take in 1 LTM and return "In Sync" by default and if you include -detailed then just returns the entire JSON.... or something like that (there is a lot of good info in that response).
if we go with the 1 LTM per call model wouldn't Get-LTMActiveStatus be just like Get-F5Status
Yes I'm interested in working on them with some guidance and as work hours allow. Can I see the details of Get-LTMSyncStatus and Get-LTMActiveStatus? Thanks Jeff
Hi, guys, So Get-F5Status looks at the value of failover-status. The sync status endpoint (slightly different than what Elijah mentioned - https://LTM.domain.com/mgmt/tm/cm/sync-status) returns different info than the failover status endpoint.
Following up on Elijah's comment, yes, my preference would be to put functions like this (and move the existing Get-F5Status function) to a new module, probably called BIGIP-CM, and have that be a child module of the parent F5-BIGIP.
https://gist.github.com/elijahgagne/3a65b396ff9573dc0c49f4bc31432e6f
Some quick thoughts:
- My functions are not using $F5Session, you'll want to change to use that
- Adding support for ValueFromPipelineByPropertyName might be nice.
- I probably wouldn't return the entire JSON. I recommend creating a PowerShell object that contains all the properties you might want. Then using "POSH-LTM-Rest\F5-LTM\TypeDataPoshLTM.Format.ps1xml" to display just default properties. The user can then get all the properties by piping to format-list * or something.
- I'd recommend looking at another function such as Get-Pool and model off of that. It addresses the above three points.
- You can continue having 2 (or 3) functions, but you might want to consider just having 1 function that gets data from all the endpoints
I think I'll probably put together a Get-F5SyncStatus function, and maybe alias Get-F5Status to Get-F5FailoverStatus. I'm a fan of keeping the functionally in separate functions.
This is what I added in the short term to make management happy :) I used -detailed to get $data.entries.'https://localhost/mgmt/tm/cm/sync-status/0'.nestedStats.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details'.nestedStats.entries.'https://localhost/mgmt/tm/cm/syncStatus/0/details/2'.nestedStats.entries.details.description This object basically gave me text to check against "Recommended action: Synchronize" and details to run Sync-DeviceToGroup not much of a change but seems to be working
Function Get-SyncStatus{
<#
.SYNOPSIS
Test whether the logged in F5 (F5 Session) currently synced
-Detail will output entire JSON
#>
[cmdletBinding()]
param (
$F5Session=$Script:F5Session,
[switch]$Detailed
)
#Test that the F5 session is in a valid format
Test-F5Session($F5Session)
$SyncPage = $F5Session.BaseURL -replace "/ltm/", "/cm/sync-status"
$SyncJSON = Invoke-F5RestMethod -Method Get -Uri $SyncPage -F5Session $F5Session
#This is where the failover status is indicated
if ($Detailed){
$SyncJSON
}else{
$SyncJSON.entries.'https://localhost/mgmt/tm/cm/sync-status/0'.nestedStats.entries.status.description
}
}
Thanks for posting this, Jeff. The tricky thing with getting values out of stats is that, since the module supports v 11.5/6 as well as 12+, we need to retrieve stats in two different ways. I'm going to do what I can to set up this new function to return useful info for all these versions - wish me luck!
good luck!!!
Here's what I have so far: https://gist.github.com/joel74/e64e4539b3d24ce9d9fda4c97b9ccce6 It returns pretty much everything available in the sync status endpoint, and works with 11.5, 12.1, and 13.0.