joel74 / POSH-F5-BIGIP

A set of PowerShell modules for working with F5 BIGIP devices using the iControlREST API
14 stars 8 forks source link

Get-Pool does not return state #7

Closed spuder closed 6 years ago

spuder commented 6 years ago

If you attempt to use Get-PoolMember to get the state of the server, it returns 'UP' regardless if the server is actually up or not.

PS C:\Users\sowen\powerform> Get-PoolMember -PoolName 'foo' -Partition 'Common' -Name 'bar:80'

Name       Partition     Address        Description   Monitor    Session            State
----          ---------    -------        -----------    -------     -------             -----
bar1:80    Common    192.0.2.0                             default     user-disabled   up

There does not appear to be a way to query if a server is 'enabled', 'disabled' or 'forced offline'

spuder commented 6 years ago

@jordangillespie This is the only thing preventing the final F5-Rest transition.

joel74 commented 6 years ago

Hi, Spencer,

When checking the status of a pool member, there are two values to consider to determine the status: the Session and the State. When you disable a pool member, it changes the Session to 'user-disabled'. In the UI, this shows as a black circle. If you want to forced-disable a pool member, then you must use the -Force switch when calling Disable-PoolMember. That changes the State to 'down' as well as the Session to 'user-disabled.'

Below are the possible permutations and the corresponding symbols displayed in the UI:

Red diamond: session: monitor-enabled state: down

Green circle: session: monitor-enabled state: up

Black circle: session: user-disabled state: up

Black diamond: session: user-disabled state: down

Hope this helps clarify things. -Joel

spuder commented 6 years ago

That does help. Thank you. I implemented it like so:

  $Member = Get-PoolMember -PoolName $Pool -Partition $Partition -F5Session $global:F5session | ? { $_.Name -match $VMName }
  if (($Member.Session -eq 'monitor-enabled') -and ($Member.State -eq 'down')) {
    # Red Diamond
    return 'offline'
  }
  elseif (($Member.Session -eq 'monitor-enabled') -and ($Member.State -eq 'up')) {
    # Green Circle
    return 'enabled'
  }
  elseif (($Member.Session -eq 'user-disabled') -and ($Member.State -eq 'up')) {
    # Black Circle
    return 'disabled'
  }
  elseif (($Member.Session -eq 'user-disabled') -and ($Member.State -eq 'down')) {
    # Black Diamond (forced offline)
    return 'disabled'
  }
  else {
    Write-Host "Invalid state for $VMName $($Member.State): $($Member.Session)" -ForegroundColor Red
    break
  }