Forum Discussion
ML_108504
Nimbostratus
Apr 13, 2009iRule Editor can't find default_pool
Hi folks, I'm experimenting with some simple iRules (I thought) from devcentral examples. When I check the following iRule in the Editor it complains with:
line 5: [can't find pool] [pool default_pool] I assumed that the 'default_pool' string corresponded to, effectively, a variable representing the default pool for the virtual running the iRule. I want to write this iRule once and apply it to dozens of virtuals, obviously I don't want an individual iRule for each pool, what am I missing? (Hopefully something simple and obvious).
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } {
pool p_PUB_botfarm
} else {
pool default_pool
}
} Save the noob! (thank you)
15 Replies
- lmwf1_55268
Nimbostratus
If you have not created the actual pool names in web based gui, then it will complaint. - dennypayne
Employee
While there is no "default pool" variable, if you don't specify a pool in the rule, then it will "fall out" to the default pool that is configured on the virtual server.
So if you want your rule to be portable, just take out the else clause:when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } }
Denny - hoolio
Cirrostratus
You can get the default pool configured on the VIP using LB::server pool. You'll want to do this before the pool has been selected on the TCP connection, so run LB::server in CLIENT_ACCEPTED:when CLIENT_ACCEPTED { Save the name of the default pool set default_pool [LB::server pool] } when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } else { pool $default_pool } }
Denny, I don't think removing the else clause will have the desired result. I don't think a second HTTP request on the existing HTTP connection from a non-bots request would go to the default pool. In general, it's a good practice to explicitly specify a pool for all cases if you do it for any case.
Aaron - ML_108504
Nimbostratus
Posted By dennypayne on 04/14/2009 8:41 AM
While there is no "default pool" variable, if you don't specify a pool in the rule, then it will "fall out" to the default pool that is configured on the virtual server.
So if you want your rule to be portable, just take out the else clause:when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } }
Denny
Aha! Excellent, I was hoping it was something obvious like that.
Cheers - ML_108504
Nimbostratus
Posted By hoolio on 04/14/2009 8:50 AM
You can get the default pool configured on the VIP using LB::server pool. You'll want to do this before the pool has been selected on the TCP connection, so run LB::server in CLIENT_ACCEPTED:when CLIENT_ACCEPTED { Save the name of the default pool set default_pool [LB::server pool] } when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } else { pool $default_pool } }
Denny, I don't think removing the else clause will have the desired result. I don't think a second HTTP request on the existing HTTP connection from a non-bots request would go to the default pool. In general, it's a good practice to explicitly specify a pool for all cases if you do it for any case.
Aaron
OK, this was my plan B (after more forum research), it looks just like your suggestion:when CLIENT_ACCEPTED { set default_pool [LB::server pool] } when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } else { pool $default_pool } }
At least we have a test env. to try this on.
Thanks! - Craig_Jackson_2
Nimbostratus
Thanks for the info about saving the default pool in the CLIENT_ACCEPTED event.
Even though that exists, it's a hack. There should be more environmental-inquiry commands in iRules. You should be able to ask the name of the default pool right in the HTTP_REQUEST event and get a reliable answer. It's needed for some other things, like learning the name of the cookie-persistence cookie.
Craig - dennypayne
Employee
[LB::server pool] is valid in the HTTP_REQUEST event as well, according to the wiki. Click here
Denny - ML_108504
Nimbostratus
Thanks for the tips and discussion guys, here's what I've ended up with at the moment, it passes the syntax checker at least ..
I've added a check for < 1 active member in the bot pool with a corresponding event disable to hop out of the rule if there are no active members in the bot pool.
Is there a better/more effecient way to compose this iRule?when CLIENT_ACCEPTED { set default_pool [LB::server pool] } when HTTP_REQUEST { if { [active_members p_PUB_botfarm] < 1 } { event disable } elseif { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } else { pool $default_pool } } - ML_108504
Nimbostratus
Actually, I'd like to use this one more, as I don't need to worry about health monitoring the default pool from the iRule, and don't need the default_pool variable.
I want this iRule to run only if a bot user-agent comes along, thoughts?when HTTP_REQUEST { if { [active_members p_PUB_botfarm] < 1 } { event disable } elseif { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { pool p_PUB_botfarm } else { event disable } } - dennypayne
Employee
Posted By mlameyer on 04/14/2009 5:04 PM
I want this iRule to run only if a bot user-agent comes along, thoughts?
Well it's going to run on every HTTP_REQUEST regardless, but I'd flip it around so that you don't do the active_members check unless you've already matched the bots User-Agent. That might perform a little better since user requests won't trigger the active_members check (and in either version the matchclass runs anyway).when HTTP_REQUEST { if { [matchclass [string tolower [HTTP::header User-Agent]] contains $::bots] } { if { [active_members p_PUB_botfarm] > 0 } { pool p_PUB_botfarm } else { return } } }
(I think I got the brackets correct there but double-check...)
I would test this throroughly though to make sure you don't need to specify the default pool like Aaron said.
Denny
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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