post body
1 TopiciRule to log all HTTP_REQUEST and insert a cookie
Hello, I wrote an iRule that uses HSL for sending syslog level data to remote servers. The iRule sends all HTTP_REQUESTs to HSL pool. There are three pools defined - each for specific purposes. I find that the iRule causes an issue of running on one CPU probably because the way the variables are defined and accessed. I have attached the iRule for your reference. Can somebody tell me if I am doing anything inefficient? Much appreciated. when RULE_INIT { array set ::active_clients { } } when CLIENT_ACCEPTED { set hsl [HSL::open -proto UDP -pool syslog_server_pool] set hsl1 [HSL::open -proto UDP -pool syslog_server_pool_1] set hsl2 [HSL::open -proto UDP -pool syslog_server_pool_2] Send the data using local7 facility <190> HSL::send $hsl "<190> [IP::client_addr] [[clock format [clock seconds] -format "%d/%b/%Y:%H:%M:%S %z"]] --[IP::local_addr]--NY--80--CLIENT_ACCEPTED" } when HTTP_REQUEST { if { [info exists ::active_clients([IP::client_addr])] } { incr ::active_clients([IP::client_addr]) } else { set ::active_clients([IP::client_addr]) 1 } if { not ([HTTP::cookie exists SITESERVER] ) } { set F2C "[string range [AES::key 128] 15 end][string range [AES::key 128] 15 end]" HTTP::cookie insert name "F2C" value $F2C } HSL::send $hsl1 "<190> [IP::client_addr] \[[clock format [clock seconds] -format "%d/%b/%Y:%H:%M:%S %z"]\] --[IP::local_addr]--NY--80--[URI::path [HTTP::uri]][URI::basename [HTTP::uri]]--UA=[HTTP::header User-Agent]--CT=[HTTP::header "Content-type"]" HSL::send $hsl2 "<190> [IP::client_addr] \[[clock format [clock seconds] -format "%d/%b/%Y:%H:%M:%S %z"]\] --[IP::local_addr]--NY--80--P2--[URI::path [HTTP::uri]][URI::basename [HTTP::uri]]--QS=[HTTP::query]--C=[HTTP::header cookie]--UA=[HTTP::header User-Agent]--CT=[HTTP::header "Content-type"]" } when HTTP_REQUEST_DATA { set refid "unknown" foreach x [split [string tolower [HTTP::payload]] "&"] { if { $x starts_with "refid=" } { set refid [lindex [split $x "="] 1] } } HSL::send $hsl2 "<190> [IP::client_addr] [[clock format [clock seconds] -format "%d/%b/%Y:%H:%M:%S %z"]] --[IP::local_addr]--NY--80--P2--refid=$refid--F2C=$F2C" } when HTTP_RESPONSE { if { [info exists F2C] and $F2C ne ""} { HTTP::cookie insert name "F2C" value $F2C unset -nocomplain F2C } } when CLIENT_CLOSED { if { [info exists ::active_clients([IP::client_addr])] } { HSL::send $hsl "<190> [IP::client_addr] [[clock format [clock seconds] -format "%d/%b/%Y:%H:%M:%S %z"]] --[IP::local_addr]--NY--80--CLIENT_CLOSED--$::active_clients([IP::client_addr])" unset ::active_clients([IP::client_addr]) } }364Views0likes7Comments