Is there any way to call iRule commands by string? For example, can I turn the string “starts_with” into a variable which calls the command ‘starts_with’?. I’m trying to make an iRule that interpret strings in a datagroup into commands efficiently, rather than using a bunch of switch statements.
To elaborate, say my iRule has just read a datagroup value, performed a split procedure on it, and returned a list with the values “HTTP::URI” , “starts_with” and “/blah” and then stored them into the variables $a , $b and $c respectively.
command which could otherwise be used for such purpose is excluded from the available iRule commands. Can you perhaps explain a bit what you’d like to do?
Do you want to select a specific pool or initiate a redirect, based on HTTP URI value? It also appears you want to manage all updates via an LTM data-group instead of iRule. Please give a few samples of condition/action in iRule format.
I can confirm you’re correct for 11.4.1 at least. I haven’t built my iRule exactly but fiddled did a lot of testing. I can turn attributes like
HTTP::uri
into variables just by set
x "HTTP::uri"
. then I can get the command HTTP::uri by
$x
. Alternatively if I do
[$x]
it returns the value of the HTTP uri.
I even did something like
when HTTP_REQUEST {
set a HTTP::header
set b "replace"
set c "host"
set d "new.host.header.value"
$a $b $c $d
}
And the last line actually replaced the host header.
I haven’t been able to turn things like “starts_with” into variables though - every approach has resulted in a run time error but I think I’ve gotten around it by using
matches_glob
for all string matching and leaving it up to the user to enter the correct wildcards into the datagroup that feeds into the iRule.
I think this is pretty much solved but I’ll build my iRule when I get a chance again and repost in a couple of days with an update.
I’m quite sure this is going to cut my iRule down to a third of its size at least. Thanks for your help again!