This could be useful depending on your environment. Bigipreport let’s you find things, but it can only go so far.
If you want to do a bit more advanced searches you can use the built in functions in powershell to convert json into objects. The beauty with powershell objects is that you can easily run queries against them.
Attaching a few examples to get you going:
#Create new webclient object $WebClient = New-Object System.Net.WebClient #Enable integrated authentication $WebClient.UseDefaultCredentials = $true #Get the json objects $Virtualservers = ($WebClient.DownloadString("https://bigipreport.mydomain.local/json/virtualservers.json")) | ConvertFrom-Json $rules = ($WebClient.DownloadString("https://bigipreport.mydomain.local/json/irules.json")) | ConvertFrom-Json $pools = ($WebClient.DownloadString("https://bigipreport.mydomain.local/json/pools.json")) | ConvertFrom-Json $monitors = ($WebClient.DownloadString("https://bigipreport.mydomain.local/json/monitors.json")) | ConvertFrom-Json #The data group lists can be a pain to convert if you have identical data save the case of the characters. If that's the case you need to replace the duplicates before using ConvertFrom-Json $datagrouplists = ($WebClient.DownloadString("https://bigipreport.mydomain.local/json/datagrouplists.json")) | ConvertFrom-Json #Get which virtual servers that has a specific rule $Virtualservers | Where-Object { $_.irules -contains "/Mypartition/rulename" } | select name #Find all monitors with dk in the name and no receive string. Show columns name, interval and load balancer $monitors | Where-Object { $_.name.contains("dk") -and $_.receivestring -eq "" } | select name, interval, loadbalancer
Hi,
Sorry for lame question (don’t know PS at all). How to use above examples? Should I just enter those commands in PowerShell interface?
Piotr
Just replace the base with that of your report. So instead of https://bigipreport.mydomain.local/ you use the address to your bigipreport.
Then you can check the examples for how to search. Please go ahead and ask questions on how to query the data and I can give you examples based on your needs.
/Patrik
Hi,
Thanks, but my simple question was if I should just copy all listed commands to one file (.ps1) and then execute it (of course modifying what’s necessary) or I should enter those commands interactively in PS shell?
Considering what I would like to query is for example if VS is enabled on vlans, if is disabled on vlans or is enabled on all vlans – don’t know if it’s possible.
Thanks in advance,
Piotr
I added the VLAN information to the virtual server and published a new version just now.
Example:
To get which virtual servers that is listening to vlan EXTERNAL that resides in the Common partition you’d load the base in the post above and execute the following query:
$virtualservers | Where-Object { $_.vlans -contains “/Common/EXTERNAL” }
Thanks once more, will try this if I manage, really appreciate your help!
There is one issue I noticed here – well maybe not issue but…
When you use Enabled on but do not move any VLAN to the Selected area result in json is like that
name vsstate vlans vlanstate
—- ——- —– ———
/test/vlans-enabled_empty_vs STATE_ENABLED {} enabled
So there is empty array returned. It could be like that except I have no idea what condition to use in $virtualservers | Where-Object { to find VS with such setup.
I did mod like that:
if($virtualservervlans[$i].state -eq “STATE_DISABLED” -and $virtualservervlans[$i].vlans.count -eq 0){
$objTempVirtualServer.vlanstate = “enabled”
} elseif ($virtualservervlans[$i].state -eq “STATE_DISABLED”) {
$objTempVirtualServer.vlanstate = “disabled”
$objTempVirtualServer.vlans = $virtualservervlans[$i].vlans
} elseif ($virtualservervlans[$i].state -eq “STATE_ENABLED” -and $virtualservervlans[$i].vlans.count -eq 0) {
$objTempVirtualServer.vlanstate = “enabled”
$objTempVirtualServer.vlans = “No VLANs”
} elseif ($virtualservervlans[$i].state -eq “STATE_ENABLED” ) {
$objTempVirtualServer.vlanstate = “enabled”
$objTempVirtualServer.vlans = $virtualservervlans[$i].vlans
}
Now output is
name vsstate vlans vlanstate
—- ——- —– ———
/test/vlans-enabled_empty_vs STATE_ENABLED {No VLANs} enabled
but when using:
$virtualservers | Where-Object { $_.name.contains(“/test”) -and $_.vlans.contains(“No VLANs”) } | sort vlanstate | select name, vsstate, vlans, vlanstate
I am getting error like that
You cannot call a method on a null-valued expression.
At C:\scripts\vs_vlan_state_vsstate.ps1:6 char:34
+ … re-Object { $_.name.contains(“/test”) -and $_.vlans.contains(“No VLAN …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\scripts\vs_vlan_state_vsstate.ps1:6 char:34
+ … re-Object { $_.name.contains(“/test”) -and $_.vlans.contains(“No VLAN …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Still correct VS is returned as an result.
What’s wrong with my approach?
Piotr
Could you please create a Powershell pastebin with the script you’re using to parse the json files? I’ll see if I can reproduce.
Hi
You can do both. 🙂 When I want to query the data one time I use the shell. If I want to use it more times I’ll save a script.
The VLAN information is not available yet. But should be easy enough to add.
/Patrik
Sorry, but it seems that it is to advanced right now 🙁
I tried to create script like that
$WebClient = New-Object System.Net.WebClient
$WebClient.UseDefaultCredentials = $true
$pools = ($WebClient.DownloadString(“http://localhost/json/virtualservers.json”)) | ConvertFrom-Json
echo “Pools: $pools”
But everything what I am getting as an echo output is:
Pools:
So I am doing something horribly wrong 🙁
Piotr
Sorry for previous port. I figured it out 🙂
You mentioned on DevCentral that “Turns out that the VIP status column was already there. :)” – to be honest I can’t find anything related to Virtual Server Enabled/Disabled State setting – or VIP status means something else?
Piotr
Good stuff! The VIP status column was already in the report feature requests. It’s not available yet. 🙂
/Patrik
I wonder if adding new properties to be retrieved and placed into json is very complicated. If not so I would appreciate if you could share some magic here 🙂
One part seems to be add declaration in public class VirtualServer
Then I can see actual code for VirtualServer processing after:
log info “Caching Virtual servers”
I assume this is part actually retrieving info
[array]$virtualservervlans = $f5.LocalLBVirtualServer.get_vlan($virtualserverlist);
now how to get any other parameter – I am just talking about having it in json not displaying in report GUI.
Piotr
Sorry, just last one. Is there a way using where or other PS cmdlet to do relation like filtering. Something like show me all VS names that are using pool with given node?
Piotr
Adding additional properties is not so hard, but it takes some experience with the PS iControl module. Your assumptions are correct, but there were a few more additions.
You can check github for the full diff:
https://github.com/epacke/BigIPReport/commit/97c0c3823d29cb22392c4a93ab6b8959bafefc20#diff-546b57a2b8c34dc2e3bbb4483240ad1d
Hi,
My modifications to get VS state are:
public string vsstate;
[array]$virtualserverstate = $f5.LocalLBVirtualServer.get_enabled_state($virtualserverlist)
$objTempVirtualServer.vsstate = [string]$virtualserverstate[$i]
Is that all I have to change? Seems to be working but…
Piotr
That looks right, well done! 🙂
/Patrik
Regarding your other question, can you have a look at my demo of bigipreport and give me an example from it? Then I can post a working sample that you can use.
/Patrik
Well, it’s not about doing something in GUI, it’s rather related to additional queries/filtering as in your post Synergy effect of running BigIPReport;
#Get which virtual servers that has a specific rule
$Virtualservers | Where-Object { $_.irules -contains “/Mypartition/rulename” } | select name
I was looking at json for virtualserver and there seems to be no data that allows to find all virtuals using given node – at least using simple command like above. But maybe with some additional magic it could be done?
Piotr
It’s possible with a little additional logic. Check out this snippet:
https://pastebin.com/pyM8UB23
/Patrik
Great, thanks a lot. It’s starting point at the level I will be able to use, even if I am not always sure how it works 🙂
Piotr