Relational class or tables

We are running v9.4.8.

I am looking to create a relation based class, not sure if this is a function of a table in v10.

the relation is that I want a way to evaluate more than 1 criteria for a class in relation. I know I can create 2 classes and have the irule match both, but the problem I run into is that the group of users may not all match the group of commands to be matched on.

In the example below I want to match testsuser1 on commands 1 and 2, but testuser2 should only match on command2. It is not scalable to create multiple matching classes for every user as the list is dynamic and will be frequently updated via api. At times there could be 2 users or there could be 15 users. Same with commands.

class penatly_box {

“testuser1” “command1”

“testuser1” “command2”

“testuser1” “command2”

}’

Is there a function that exists to handle these relations?

With datagroups and memory tables, the key must be unique. If you want to have multiple values for a key, you could combine them:

class penatly_box {
"testuser1"   "command1|command2|command3"
"testuser2"   "command2"
"testuser3"    "command1"
}

To parse these values you could use getfield:

http://devcentral.f5.com/wiki/iRules.getfield.ashx

Aaron

Thanks Aaron.

I will read up on getfield.

Still need a bit of clarification on this.

b class test_penaltybox '{

“testuser1 command1”

“testuser1 command2”

“testuser2 commnad1”

}’

http://domain-name.com/?uid=testuser1&command=command1 should match

http://domain-name.com/?uid=testuser1&command=command2 should match

http://domain-name.com/?uid=testuser2&command=command1 should match

http://domain-name.com/?uid=testuser2&command=command2 should not match

if {[matchclass [string tolower [HTTP::uri]] contains [getfield $::bentest_penaltybox] “:” 1 ]} {

pool $penaltyboxpool

}

I can’t get the syntax correct to work. Also I want to expand it so that URI contains both “1” and “2” or “testuser1” and “command1”, but not if it only has one of the two.

Can getfield be applied to a class, or can it only be applied to a URI?

duplicate

duplicate

sorry duplicate. deleted text

Sorry, I was mistaken on the name value format I gave for 9.x. That was added in ~10.0 or 10.1.

If you have a data group defined as this:

class test_penaltybox {
   "testuser1 command1"
   "testuser1 command2"
   "testuser2 commnad1"
}

To look up a single string (like the UID) in the data group and get the second field you could use findclass:

log local0. [findclass testuser1 test_penaltybox " "]

Note that the data group name is test_penaltybox and should be referenced without the $:: prefix in 9.4.4+.

Or if you want to check if a uid and command combination exist, you could try this:

if {[matchclass "[URI::query ?&[HTTP::query] &uid] [URI::query ?&[HTTP::query] &command]" equals test_penaltybox]}{
        log local0. "matched"
    } else {
        log local0. "no match"
    }

Note the workaround used for a URI::query bug which was fixed in v11:

http://devcentral.f5.com/wiki/iRules.uri__query.ashx

Aaron

Thanks very much! Early testing looks great. Now I just have to sort out the logic.

Hoolio.

I can’t seem to get the “string tolower” to work with this scenario. Can you assist?

if {[matchclass [string tolower “[URI::query ?&[HTTP::query] &uid] [URI::query ?&[HTTP::query] &command]” ] equals test_penaltybox]}{

pool penaltybox-pool

log local0. “matched”

return

} else {

log local0. “no match”

}

That looks right to me and saves on a test box. When you say it’s not working, what error or issue do you see and when (saving the rule, during runtime or just not matching)?

Aaron

The Irule is valid in terms of syntax but if the user is Testuser1 instead of testuser1, or the command is Command1 instead of command1 the log reports match and the pool is not hit.

Are your data group entries in all lower case? And does it log matched and go to the pool or log no match and not go to the penaltybox pool?

Aaron

datagroup entries use only lower case. It logs “no match” and does not go to the penatly box pool. I also added in additional logging.

I also added addtional logging and “Value 2” logs correctly when the URI values are lowercase. Value 2 logs nothing when the URI values use any uppercase.

Start of changes

log local0. “----------------------”

log local0. “URI Information”

log local0. “----------------------”

log local0. “HTTP::uri: [HTTP::uri]”

log local0. “----------------------”

log local0. "Value1: [URI::query ?&[HTTP::query] &uid] "

log local0. “----------------------”

log local0. "Value2: [URI::query ?&[HTTP::query] &command] "

log local0. “----------------------”

log local0. “Path Information”

log local0. “----------------------”

log local0. “HTTP::path: [HTTP::path]”

if {[matchclass [string tolower “[URI::query ?&[HTTP::query] &uid] [URI::query ?&[HTTP::query] &command]” ] equals test_penaltybox]}{

pool test_penaltybox-80

log local0. “matched”

return

} else {

log local0. “no match”

}

Sorry, URI::query is case sensitive. So you can try this instead:

set query “&[string tolower [HTTP::query]]”

if {[matchclass “[URI::query $query &uid] [URI::query $query &command]” equals test_penaltybox]}{

Aaron

Thanks again Hoolio for pointing me in the right direction. After quite a bit of logging and failures I adjusted the query slightly and seem to be getting great results.

I will update this after a bit of Q/A testing if there need to be any additional changes.

Start of changes

set testquery1 [ URI::query [string tolower [HTTP::uri]] command ]

log local0. “----------------------”

log local0. “testquery1:”

log local0. “----------------------”

log local0. “$testquery1”

log local0. “----------------------”

set testquery2 [ URI::query [string tolower [HTTP::uri]] uid ]

log local0. “----------------------”

log local0. “testquery2:”

log local0. “----------------------”

log local0. “$testquery2”

log local0. “----------------------”

if {[matchclass “[ URI::query [string tolower [HTTP::uri]] uid] [ URI::query [string tolower [HTTP::uri]] command ]” equals test_penaltybox]}{

pool test_penaltybox-80

log local0. “matched”

return

} else {

log local0. “no match”

}

End of new changes