I am trying to find a way for an irule (9.x LTM) to query for a list of all pools on the system, but so far have not found a way to do so. Is this possible?
I don’t believe there is a single command or a set of commands that that can easily query ALL pools in the system, unless all your pools are similarly named but denoted with numbers for example pool1 to pool32. Then you can write an iRule that would loop through each iteration of the pool name and thus list our all the pools. Otherwise, the CLI is pretty much the only place where single command can list out all the pools.
Hope this helps
CB
It’s generally useful to name the pools using a format like app-name_protocol_pool so that you know what the pool is used for by the name. Maybe you can provide some background on what you’re trying to accomplish and we can provide a suggestion.
In general, you can get a list of configured pools using iControl. You can check to see if a pool exists by trying to assign it and handle an error for a pool not existing using catch (Click here). You could create a datagroup which contains all of the configured pool names and update that datagroup periodically using an iControl script. But again, it would help to know what you’re trying to do and why.
Aaron
Thanks for the feedback. We do not have iControl, and I am trying to create a read-only dashboard for our app developers to check to see if various pools are up or down. I would prefer to not manually edit the list each time I setup/tear down a pool.
when HTTP_REQUEST {
set POOLS {
“http_pool”
“https_pool”
}
set response “BIGIP Pool Status - [clock format [clock seconds]]”
foreach { curpool } $POOLS {
pool $curpool
if { [active_members [LB::server pool] ] < 1 } {
set response "$response DOWN - $curpool
"
} else {
set response "$response UP - $curpool
"
}
}
set response "$response "
HTTP::respond 200 content $response “Content-Type” “text/html”
}
That’s a novel approach for providing stats from an iRule. Short of manually listing all the pools in a datagroup, and possibly updating it via iControl or manually, I don’t see an option to do this from an iRule.
I think a few people have worked to create an iControl-based web dashboard. You do have iControl available--it’s part of any LTM installation. You might try searching the iControl forum for examples.
Aaron
Then I think you hit a limitation from this perspective. However it is the most common item that a lot of people have been requesting. Perhaps opening a case with F5 as a future feature will help. I also found your particular code useful for some clients who need a quick pulse on the current pool they have selected on the vip. I have posted it up for you
http://devcentral.f5.com/wiki/default.aspx/iRules/pool\_status\_page.html
CB
Thanks, will look into iControl to see what else I can do.
Take a look at something that may prove to be useful to you
http://devcentral.f5.com/wiki/default.aspx/iControl/VirtualServerPoolMemberStatusAndControl.html
It’s a client side application (using iControl) where any client can log into the LTM (with readme only account) and list the vips and pools and their status. It actually does more then list the virtuals and pools, but if they have a readme account they cannot do more then look at the status.
Another item that is close to what you are asking is based on Python
http://devcentral.f5.com/wiki/default.aspx/iControl/pyControl\_nodeAlert.html
Hopefully this might help you obtain what you are looking for.
CB
As with your “set POOLS {}” list example, you can enumerate the pool names from a class. If you use an external class you can use an external monitor script to modify that file at intervals. You’ll need to do a “b load” in the script once the file is created, so I’d probably set the monitor on an unused pool and set it to some long interval, perhaps once a day.
So the class might look like this:
"apache_pool",
"iis_pool",
"coldfusion_pool",
"java_pool",
In v10 the iRule might look like this:
when HTTP_REQUEST {
set response "BIGIP Pool Status - [clock format [clock seconds]]"
if { [HTTP::uri] eq "/status" } {
foreach { selectedpool } [class get pooltest] {
set thispool [getfield $selectedpool " " 1]
if { [catch {
if { [active_members $thispool] < 1 } {
set response "$response DOWN - $thispool
"
} else {
set response "$response UP - $thispool
"
}
} errmsg ] } {
set response "$response INVALID POOL NAME - $thispool
"
}
}
set response "$response "
HTTP::respond 200 content $response "Content-Type" "text/html"
}
}
Kevin
Here’s what the external monitor might look like:
!/bin/bash
b pool all name |awk '{ print "\"" $2 "\","}' >/var/class/testclass
tmsh show ltm pool |grep Pool: |awk '{ print "\"" $2 "\"," }' >/var/class/testclass
b load
Kevin
Not to be a post hog, but here’s another version of the iRule that turns it into an RSS feed:
when HTTP_REQUEST {
set response ""
set response "$response BigIP Server Pool Status"
set response "$response Server Pool Status"
set response "$response en"
set response "$response [clock format [clock seconds]]"
set response "$response 60"
if { [HTTP::uri] eq "/status" } {
foreach { selectedpool } [class get pooltest] {
set thispool [getfield $selectedpool " " 1]
if { [catch {
if { [active_members $thispool] < 1 } {
set response "$response "
set response "$response $thispool status"
set response "$response $thispool is DOWN"
set response "$response "
} else {
set response "$response "
set response "$response $thispool status"
set response "$response $thispool is UP"
set response "$response "
}
} errmsg ] } {
set response "$response "
set response "$response $thispool ERROR"
set response "$response Invalid pool name: $thispool"
set response "$response "
}
}
set response "$response "
set response "$response "
HTTP::respond 200 content $response "Content-Type" "text/xml"
}
}
Kevin
Hi Kevin,
That’s a very thorough and handy set of examples to do this in a fairly straightforward way without iControl. And it doesn’t even involve setting up a cronjob!
Aaron
Nice updates, Citizen. I’d read that append is more efficient than set var “$var$stuff”, but it’s nice to see it proved out.
I guess you could eek out a few CPU cycles by replacing some of the appends:
append response ""
append response "$thispool status"
append response "$thispool is DOWN"
append response ""
with:
append response "\
$thispool status\
$thispool is DOWN\
"
Aaron
True. So I eliminated as many appends as I could and reran the test without the pool member section, then added it back in for a test as well. So here are the final numbers, followed by the more-optimized version:
1) Original Version - 493901 avg cycles
2) Changed sets to appends - 436453 avg cycles
3) Minimized append statements - 414210 avg cycles
Definite savings! Adding the pool member code, however, shoots it back up (650614 avg cycles), and will do more so depending on how many pools & pool members you have.
when HTTP_REQUEST {
set response " \
BigIP Server Pool StatusServer Pool Status \
en[clock format [clock seconds]]60"
if { [HTTP::uri] eq "/status" } {
foreach { selectedpool } [class get pooltest] {
set thispool [getfield $selectedpool " " 1]
if { [catch {
if { [active_members $thispool] < 1 } {
append response "$thispool status$thispool is \
DOWN"
} else {
append response "$thispool status$thispool is \
UP"
Member Status Section for "UP" pools"
append response "$thispool member status foreach { pmem } [members -list $thispool] {
append response "Pool Member [join $pmem ":"] is \
[LB::status pool $thispool member [getfield $pmem " " 1] [getfield $pmem " " 2] ]
"
}
append response "\]\]>"
End Member Status Section
}
} errmsg ] } {
append response "$thispool ERROR \
Invalid pool name: $thispool"
}
}
append response ""
HTTP::respond 200 content $response "Content-Type" "text/xml"
}
}
Nice. Is there any difference between using [active_members $pool] compared with ‘[LB::status $pool] eq “UP”’?
Aaron
I don’t think you can get pool status with the LB::status command, only nodes or pool members. [LB::status $thispool] passes syntax check, but doesn’t return anything. Specifying the pool keyword requires additional arguments for members, which isn’t what we want. Any other ideas?
Ah… somehow I always had it in my head that you could get the pool state--not just pool members using LB::status.
Aaron
This post is definitely evolving. I am sorry we could answer tarsier’s original questions but this inspired fantastic contributions
Could or couldn’t answer tarsier’s original question? Didn’t we?
Kevin
My original question was resolved with Kevin’s shell script.
All the further contributions are very interesting as well. I never considered using an RSS feed to provide notifications, nor did I realize how simple they are to create.