Forum Discussion

Rich_125959's avatar
Rich_125959
Icon for Nimbostratus rankNimbostratus
Sep 18, 2014

Evaluating data pulled from a data group

I am building an iRule that will redirect specific traffic. I have several different URL paths (uri_search_string) that I need to set this up for and would like to pull that from a data group along with the product specific information needed in the iRule. I get an error stating that a boolean is expected. I want it to execute or evaluate the code that is pulled from the data group. Is that possible?

 

data_group

 

product := product1

 

uri_search_string := ([string tolower [HTTP::uri]] equals "/xyz" || [string tolower [HTTP::uri]] contains "/abc/123") and not ([string tolower [HTTP::query]] contains "a1=y" || [string tolower [HTTP::query]] contains "a2=y")

 

iRule

 

set project [class match -value project equals data_group]

 

set uri_search_string [class match -value uri_search_string equals data_group]

 

if { $uri_search_string } {

 

 do redirect and other stuff here

}

 

else {

 

  do other stuff here

}

 

6 Replies

  • The problem is that you are doing a match, not retrieving the value from the datagroup. You need to use class element -value or something like that. Reference here

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Can you supply some sample URLs and actions based on each? That may make your request a bit easier to understand.

     

  • I stepped back and went at this a little different way. I created 3 datagroups and constructed my if statement to evaluate the contents of the datagroups. Now if the following paths are hit, it is properly redirected to the new URL.

     

    http://domain.com/abc

     

    http://domain.com/xyz/123

     

    The NOT portion of the statement is not working yet. Any ideas?

     

    http://domain.com/abc?x=y

     

    DataGroups

    datagroup_http_path_equals

     

    datagroup_http_path_contains

     

    datagroup_http_query_not_contains

     

    iRule

    if { ( [class match [string tolower [HTTP::path]] equals ${datagroup_http_path_equals}] || [class match [string tolower [HTTP::path]] contains ${datagroup_http_path_contains}] ) and not ( [class match [string tolower [HTTP::query]] contains ${datagroup_http_query_not_contains}] ) } {Redirect to new url}

     

    • Arie's avatar
      Arie
      Icon for Altostratus rankAltostratus
      What are the values in the class "datagroup_http_query_not_contains"?
  • I found my issue. The names of the datagroups had a hyphen in it (those shown above were variables set elsewhere in my script). Changing the hyphen in the datagroup names to underscores, resolved my issue.

     

    This works: if { ([class match [string tolower [HTTP::path]] equals HTTPpath_equals ] || [class match [string tolower [HTTP::path]] contains HTTPpath_contains ]) and not ([class match [string tolower [URI::query [HTTP::uri]]] contains HTTPpath_not_contain ]) } {

     

    where the datagroup names are: HTTPpath_equals; HTTPpath_contains; HTTPpath_not_contain

     

    It was interesting that it only affected the 'and not' section but...it works now.

     

    Thanks for your help.

     

  • I found my issue. The names of the datagroups had a hyphen in it (those shown above were variables set elsewhere in my script). Changing the hyphen in the datagroup names to underscores, resolved my issue.

     

    This works: if { ([class match [string tolower [HTTP::path]] equals HTTPpath_equals ] || [class match [string tolower [HTTP::path]] contains HTTPpath_contains ]) and not ([class match [string tolower [URI::query [HTTP::uri]]] contains HTTPpath_not_contain ]) } {

     

    where the datagroup names are: HTTPpath_equals; HTTPpath_contains; HTTPpath_not_contain

     

    It was interesting that it only affected the 'and not' section but...it works now.

     

    Thanks for your help.