Forum Discussion
Kalyan_Reddy_Da
Nimbostratus
Sep 03, 2010Irule with Datagroup External file is not working. Please help
Hi friends,
I am new for writing irules.
I have a requirement where we have 1000 pools and for each pool users will be accessign with different URI's.
Example:
Pool1 : /uri1
Pool2 : /uri2 ... and so on.
As my pools are growing i can't use a simple Switch case irule with HTTP URI .
The following is the irule i have written using Data Groups "External File" with Type "String"
External File
-------------
[admin@server1:Active] config cat dg1
"uri1" := "uri1",
"uri2" := "uri2",
Irule
-------
when HTTP_REQUEST {
set URIPOD [string tolower [getfield [HTTP::uri] "/" 2] ]
log local0. "URIPOD: $URIPOD"
if { [matchclass $URIPOD equals $::dg1] } {
log local0. "In IF Loop"
set myPool [findclass $URIPOD $::dg1 " "]
log local0. "Pool Name: $myPool"
pool $myPool
}
}
This irule is not checking the values against the external file.
Please suggest if there is any best way
I used below irule to ensure it is not checking against external file
when HTTP_REQUEST {
if {[catch {[set match [matchclass [HTTP::uri] contains $::dg1]]} errmsg]} {
log local0. "Fail - $errmsg"
} else {
if { $match } {
log local0. "In IF Loop"
} else {
log local0. "In ELSELoop"
}
}
}
- naladar_65658
Altostratus
What version of TMOS are you using Kalyan Reddy Daida? - Kalyan_Reddy_Da
Nimbostratus
The below is version i am using - naladar_65658
Altostratus
First things first I would convert that over to use the new class match syntax to avoid any weirdness you may be experiencing by using $:: in your iRule. I am not an iRule guru by any means, but here is a good post that explains the switch over from matchclass to class match: - naladar_65658
Altostratus
So I think it would look like this rewritten:
Edit: Added -value and class getwhen HTTP_REQUEST { set URIPOD [string tolower [getfield [HTTP::uri] "/" 2] ] if { [class match -value $URIPOD equals dg1] } { set myPool [class get $URIPOD dg1 " "] pool $myPool } }
- Kalyan_Reddy_Da
Nimbostratus
Hi Naladar,: TCL error: Payforce - expected boolean value but got "" while executing "if { [class match -value $URIPOD equals kalyan2] } { set myPool [findclass $URIPOD kalyan2 " "] pool $myPool }"
- naladar_65658
Altostratus
I do not have a version 10.x unit I can test with at the moment, but the wiki page for the class command outlines something almost exactly like what you are looking for if I understand your requirements right. They just go about doing it in a little different way:when HTTP_REQUEST { set app_pool [class match –value [HTTP::uri] starts_with app_class] if {$app_pool ne ""} { pool $app_pool } else { pool default_pool } } }
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