Forum Discussion

Gary_Bristol_19's avatar
Gary_Bristol_19
Icon for Nimbostratus rankNimbostratus
Oct 12, 2015

Irule to External Data Group not pulling up second data field

In using an External Data Group everything seems to work except for the pulling up of the second data area.

when RULE_INIT { Turn Debug on or off (0=off 1=on) Turn debug off in prod set static::redir_debug 0 } when HTTP_REQUEST { Use following to match against datagroup set match_string [string tolower [HTTP::host]] append match_string [string tolower [HTTP::path]] if {$static::redir_debug}{log local0. "Match String: $match_string"}

  Lookup the redirect or pool based upon match_sting value
  set goto [class lookup $match_string www_ou_edu_redir_class]
  if {$static::redir_debug}{log local0. "Goto: $goto"}
  if { [getfield $goto "," 1] equals "pool" }{
    if {$static::redir_debug}{log local0. "Pool declaration detected. Going to: [getfield $goto "," 2]"}
    pool [getfield $goto "," 2]
  } else {
    if {$static::redir_debug}{log local0. "Redirect declaration detected. Redirecting to: [getfield $goto "," 2]"}
    HTTP::redirect https://[getfield $goto "," 2]
  }
}

7 Replies

  • when RULE_INIT {
      Turn Debug on or off (0=off 1=on)
      Turn debug off in prod
      set static::redir_debug 0
    }
    when HTTP_REQUEST {
      Use following to match against datagroup
      set match_string [string tolower [HTTP::host]]
      append match_string [string tolower [HTTP::path]]
      if {$static::redir_debug}{log local0. "Match String: $match_string"}
    
      Lookup the redirect or pool based upon match_sting value
      set goto [class lookup $match_string www_ou_edu_redir_class]
      if {$static::redir_debug}{log local0. "Goto: $goto"}
      if { [getfield $goto "," 1] equals "pool" }{
        if {$static::redir_debug}{log local0. "Pool declaration detected. Going to: [getfield $goto "," 2]"}
        pool [getfield $goto "," 2]
      } else {
        if {$static::redir_debug}{log local0. "Redirect declaration detected. Redirecting to: [getfield $goto "," 2]"}
        HTTP::redirect https://[getfield $goto "," 2]
      }
    }
    
    • Gary_Bristol_19's avatar
      Gary_Bristol_19
      Icon for Nimbostratus rankNimbostratus
      here is a sample of the Data aasa.ou.edu := redir,www.ou.edu/studentlife/diverse_communities/asian_american_studentlife/groups/aasa.html, academictech.ou.edu := redir,ouacademictech.com, action.ou.edu := pool,ouwww_bostitch, admissions.ou.edu := redir,www.ou.edu/admissions.html, admissions.ou.edu/calendar := redir,www.ou.edu/admissions/calendar, admissions.ou.edu/gened.htm := redir,www.ou.edu/enrollment, admissions.ou.edu/records.html := redir,www.ou.edu/recordsandtranscripts, admissions.ou.edu/registration.html := redir,www.ou.edu/enrollment, admissions.ou.edu/transcripts.html := redir,www.ou.edu/recordsandtranscripts, advisement.ou.edu := redir,www.ou.edu/advising.html, ags.ou.edu := redir,www.ou.edu/ags.html, ags.ou.edu/~ := redir,http://parker.ou.edu, airport.ou.edu := =,www.ou.edu/airport.html, alc.ou.edu := pool,ouwww_bostitch, alc.ou.edu := redir,http://www.ou.edu/univcoll/alc, alerts.ou.edu := redir,www.ou.edu/ouit/help/alerts, alumni.coa.ou.edu := redir,www.ou.edu/content/architecture/aud/alumni_friends.html, alumni.ou.edu := redir,http://www.ou.edu/alumni, ame.ou.edu := redir,www.ou.edu/coe/ame/home.html, annualreport.ou.edu := redir,www.ou.edu/web/about_ou/communityimpactreport, aoi.ou.edu := pool,ouwww_bostitch,
  • Your code looks reasonable. Are you just not returning a value into $goto? The class lookup command uses an implied "equals" comparison, so you might just not be making an exact match. Try this instead:

     

    set goto [class match -value $match_string starts_with www_ou_edu_redir_class]

    where the data group is the least specific URL pattern. You can also simplify some of your code by getting rid of a few variables:

     

    set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
  • The [HTTP::uri] command will always return at least "/", even if no URL path is specified, so most of your samples won't ever match. You should see that in your log statement:

    if {$static::redir_debug}{log local0. "Match String: $match_string"}
    

    With a call to "admissions.ou.edu", which should return:

    admissions.ou.edu/ 
    

    If in your log statement you see, for example:

    Goto: pool,ouwww_bostitch,
    

    But you see nothing from:

    [getfield $goto "," 2]
    

    then there's another issue that might be better solved with a list function. But I'm more inclined to think its a data group matching issue still.

  • but doesn't the "redirection declaration detected. Redirecting to:" show that it is infact matching ?

    That's inside an else clause, so no.

    if { [getfield $goto "," 1] equals "pool" }    
    

    which it never does because $goto is empty.

  • Here is the final version of the iRule

    when RULE_INIT {
      Turn Debug on or off (0=off 1=on)
      Turn debug off in prod
      set static::redir_debug 1
    }
    when HTTP_REQUEST {
      Use following to match against datagroup
    
      Lookup the redirect or pool based upon match_string value
      set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
      if {$static::redir_debug}{log local0. "Goto: $goto"}
      if { [getfield $goto "," 1] equals "pool" }{
        if {$static::redir_debug}{log local0. "Pool declaration detected. Going to: [getfield $goto "," 2]"}
        pool [getfield $goto "," 2]
      } else {
        if {$static::redir_debug}{log local0. "Redirect declaration detected. Redirecting to: [getfield $goto "," 2]"}
        HTTP::redirect http://[getfield $goto "," 2]
      }
    }
    

    and then here is a sample of the external Datagroup file that goes with the rule that works.

    ags.ou.edu := "redir,www.ou.edu/ags.html",
    ags.ou.edu/~ := "redir,parker.ou.edu",
    airport.ou.edu := "redir,www.ou.edu/airport.html",
    alc.ou.edu := "pool,ouwww_bostitch",
    

    so what i was missing, which was pointed out here was the fact that the F5 was unable to pull out the second part of the data. encapsulating the data in Double Quotes enabled that to work.

  • so what i was missing, which was pointed out here was the fact that the F5 was unable to pull out the second part of the data. encapsulating the data in Double Quotes enabled that to work

    Great that it works, but that most likely was not the reason. You changed your class command:

    set goto [class match -value [string tolower [HTTP::host][HTTP::path]] starts_with www_ou_edu_redir_class]
    

    which gave you a little more depth in the search. For example, if your incoming host was

    ags.ou.edu
    

    and there was no specified URI, which made "/" the default path, then your search string would have been

    ags.ou.edu/
    

    If then you're doing an EXACT match with the [class lookup ] command, feeding it this pattern, but you only have the following in the data group

    ags.ou.edu
    

    then it would never match, as you witnessed. If you then switch to a [class match -value $pattern starts_with datagroup] search, your more generic data group entry matches because the input "ags.ou.edu/" does indeed start with "ags.ou.edu".

    The data group entries themselves don't need to be encapsulated in double quotes.