Data group field accessible to iRule?

Hello,

I have an iRule that’s working fine to validate a variable containing the http header variable Origin to values defined in a data group.

if { [ class match [string tolower $request_origin ] starts_with dg_sb_fit1_allow_origin ] } …

I now have a need to compare the Referer header variable to that same data group. If the “starts_with” is a match, I was going to simply take the value from the data group rather than parsing the Referer down to just the domain (stripping off the URL/query string, etc.). I’ve been trying a number of variations of the following, but have not been able to get the value from the data group.

set dg_origin [class match -value $request_referer starts_with dg_sb_fit1_allow_origin]

I then log $dg_origin, expecting the likes of "; (value from the data group), but getting blanks. I suspect a syntax issue, but I’ve been trying variations to no avail.

Or would I be better off parsing the Referer variable from the start up to the “/” after the domain?

Regards, Scott

Does your data-group dg_sb_fit1_allow_origin have key-value pair or just key ? You may want to avoid using “-value” if you just have one column of data in the datagroup. If I am mistaken, it will be good to see an example of your datagroup with made-up data but something that resembles your datagroup.

I believe the answer is pretty simple here. Use

-name

instead of

-value

.

In this rule, the variable

ORIGIN

is

set

to the returned value and checks to see if it’s blank at the same time.

set REFERER [string tolower [HTTP::header value Referer]]
if { [set ORIGIN [class match -name $REFERER starts_with dg_sb_fit1_allow_origin]] ne "" } {
    log local0. "You matched ${ORIGIN}"
}