Stream matched rewrite irule statistics
We have a rewrite irule that uses stream match to rewrite hostnames etc. For decomissioning purposes we woud like to generate a report showing which requests (urls) are using the irule and the results of rewrite. The report should have columns like
matched, replacewith, fromURI, count
when ACCESS_ACL_ALLOWED {
#STREAM::disable
#HTTP::header remove "Accept-Encoding"
#log local0. "[IP::client_addr] is accessing and we are removing Accept-Encoding"
}
when CLIENT_ACCEPTED {
ACCESS::restrict_irule_events enable
}
when HTTP_REQUEST {
STREAM::disable
HTTP::header remove "Accept-Encoding"
set http_uri "https://[HTTP::host][HTTP::uri]"
}
when HTTP_RESPONSE {
# Check if response type is text
if {([HTTP::header value Content-Type] contains "text") || ([HTTP::header value Content-Type] contains "json")}{
STREAM::expression {@https?:\/\/([^\/\"]*\.)*city\.council\.com@replace_me@}
# Enable the stream filter for this response only
STREAM::enable
}
}
when STREAM_MATCHED {
#log local0. "Debug1: STREAM_MATCHED"
set CHECK [class match -value [string tolower [STREAM::match]] starts_with URI_department.city.council.com_no_rewrite]
if { $CHECK == "1" } {
#log local0. "found exception for [STREAM::match]"
STREAM::replace [STREAM::match]
} else {
set RE {https:\/\/([^\/\"]*\.)*city\.council\.com}
set STRING "[string map {http:// https://} [STREAM::match]]"
set SUBST "https://\\1department.city.council.com
if {! ($STRING contains "intranett") } {
# we need to insert intranett
set STRING "[regsub -all $RE $STRING $SUBST ]"
}
#log local3. "[IP::client_addr]:[TCP::local_port]: matched: '[STREAM::match]', replaced with: '$STRING', from URI: $http_uri"
STREAM::replace $STRING
#if { ! ($STRING == [STREAM::match]) } {
# }
}
}