Forum Discussion
kwondra34_26054
Nimbostratus
Jun 23, 2016F5 iControl REST - API calls required to get Load Balancer, Virtual Server URL, IP, Port, Pool Name/Status/Members
Hi everyone,
I am attempting to use the F5 REST API to create a csv containing the following fields (potentally others if they are available, but these will suffice):
- Virtual Server (URL/Name)...
rodolfosalgado_
Altostratus
Jul 14, 2016I did something similar using Powershell 4.0. You are also going to need the BIG IP 11.5.3 (I guess at least), I'm using 11.6.1. Maybe my code can shed some light for you... it's a very simple one:
function Get-F5Token(
[Parameter(Mandatory=$True)]
[string]$currentf5
)
{
$username="admin"
$password="admin"
$url="https://"+$currentf5+"/mgmt/shared/authn/login"
$payload='{"username":"'+$username+'","password":"'+$password+'","loginProviderName":"tmos"}'
Convert Username/Password to Base64 and create Header
$bytesauth = [System.Text.Encoding]::UTF8.GetBytes($username+":"+$password)
$authvalue = "Basic "+[System.Convert]::ToBase64String($bytesauth)
$headers = @{ Authorization = $authvalue }
return ((Invoke-WebRequest -headers $headers -contenttype "application/json" -Method POST -uri $url -body $payload).content |Convertfrom-Json).token
}
Allow self-signed certificates
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$global:Authentication = (Get-F5Token 10.10.66.92)
$global:tokenheader = @{ "X-F5-Auth-Token" = $Authentication.token }
Create timer
$backgroundTimer = New-Object System.Timers.Timer
Set interval (ms)
$backgroundTimer.Interval = 5000
Make sure timer stops raising events after each interval
$backgroundTimer.AutoReset = $true
if((Get-EventSubscriber | where { $_.SourceIdentifier -eq "renewToken" }) -eq $null){
Have powershell "listen" for the event in the background
Register-ObjectEvent $backgroundTimer -EventName 'Elapsed' -SourceIdentifier 'renewToken' -Action {
$global:Authentication = (Get-F5Token 10.10.66.92)
$global:tokenheader = @{ "X-F5-Auth-Token" = $global:Authentication.token }
Restart timer
$backgroundTimer.Start()
}
}
Enable the timer, with that we will get a new token every 5 seconds.
$backgroundTimer.Enabled = $true
Get information regarding this F5:
$ltm = new-object Psobject
$ltm | Add-Member irule $null
$ltm | Add-Member pool $null
$ltm | Add-Member vs $null
$ltm | add-member policies $null
$ltm.policies = @(New-Object psobject -Property @{
vsname = $null;
policy = $null;
})
Now all the informations regarding VirtualServers, Irules, Pools are going to be in the object called $ltm
- kwondra34_26054Jul 14, 2016
Nimbostratus
Thank you so much! This helps tremendously. I will review this and give it a shot. I'll mark the answer as correct or at least helpful soon.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects