Forum Discussion

stan_peachey_86's avatar
Nov 13, 2015

findclass to class iRule help request

We had a v9.x iRule that called an internal datagroup (xxx_direct) via findclass and logged connections. I'm mostly concerned about proper use of class command to call datagroup. We are upgrading to v11.6; any suggestions for iRule improvement are greatly appreciated.

when HTTP_REQUEST {
set url [HTTP::header Host][HTTP::uri]
set host_org [ substr [HTTP::header Host] 0 "." ]
set host_org [ string tolower $host_org ]
set host [ substr $host_org 0 "_" ]
set org [ substr $host_org 7 "-" ]
set host_header_value $org.bla.blah.edu
HTTP::header replace Host $host_header_value
set direct [ findclass $host $::xxx_direct " " ]
pool xxx member $direct:80
}

when HTTP_RESPONSE {
set client [IP::client_addr]
set server [IP::server_addr]
log local0. "xxx_direct: url:$url client:$client server:$server
host_header:$host_header_value"

3 Replies

  • In v9 there were string data groups but no key value pair as there is in v10. Take the $::xxx_direct data group, create it with the same name xxx_direct but seperate each string on the first space into key and value pairs. Before the space is the key. The rest after the space is the value. Then your comand will be

    set direct [class match -value $host equals xxx_direct]
    

    Another command you could update would be the two for setting host_org and collapse them into this.

    set host_org [string tolower [getfield [HTTP::header "Host"] "." 1]] 
    
    • stan_peachey_86's avatar
      stan_peachey_86
      Icon for Cirrus rankCirrus
      Thanks! We will start testing in the newer code soon. Why does original set host_org change from 0 "." to "." 1 in your example?