Forum Discussion
error irules with regexp on HTTP::host
Hello,
I'm new to devcentral, can you help me for a default configuration of an irules.
here the irulewhen HTTP_REQUEST {
set i 0
set host [string tolower [HTTP::host]]
if { $host matches_regex {^.*\.\w+\.\w+$} } {
log local0. "on entre dans le regex"
regexp {^.*\.([w]+\.[w]+)$} [string tolower [HTTP::host]] -> endofhost
log local0. "dans le regex host : $host ; test end of host : $endofhost"
set i 1
}
if { $i == "0" } {
log local0. "i=$i"
if { ! ( [class match $host equals HTTP_exception_url_for_source_ip]) }{
log local0. "dans le match host : $host "
snat automap
forward
}
}
if { $i == "1" } {
log local0. "i=$i"
if { ! ( [class match $endofhost equals HTTP_exception_url_for_source_ip]) }{
log local0. "dans le match endofhost : $endofhost "
snat automap
forward
}
}
}
here the ltm log :
Jun 9 15:50:15 local/tmm info tmm[4880]: Rule irule_IP_and_url_exception : on entre dans le regex Jun 9 15:50:15 local/tmm err tmm[4880]: 01220001:3: TCL error: irule_IP_and_url_exception - can't read "endofhost": no such variable while executing "log local0. "dans le regex host : $host ; test end of host : $endofhost""
So my default is here : regexp {^.*.(w+.w+)$} [string tolower [HTTP::host]] -> endofhost
I want to catch the domain to the variable endofhost (why ? because i have got a datagroup list that only have domain on it, and i have to forward if it's match.)
if www.google.fr ==> endofhost = google.fr
I search for hours on devcentral /ask F5, i don't figure the solution...
Is there a good soul to help ,me ?
Best Regards,
7 Replies
- kullwahad_19151
Nimbostratus
for information , the bigip is on version 10.2.4 HF10 - kullwahad_19151
Nimbostratus
for information : i have a clue with the split option, but i have to put for each xxx.xxx.xxx.xxx that can exist... (here in the ex for maximum 4 field in HTTP::host : when HTTP_REQUEST { if { [class match [IP::remote_addr] equals HTTP_url_exception_based_on_source_ip_address] }{ set i 0 set host [string tolower [HTTP::host]] if { $host matches_regex {^\w+\.\w+$} } { log local0. "dans le regex double champs : $host" } if { $host matches_regex {^\w+\.\w+\.\w+$} } { set fields [split $host "."] set m1 [lindex $fields 0] set m2 [lindex $fields 1] set m3 [lindex $fields 2] set endofhost "$m2.$m3" log local0. "dans le regex fields 3 champs, champs1 : $m1, champs2 : $m2, champs3: $m3; endofhost : $endofhost " set i 1 } if { $host matches_regex {^\w+\.\w+\.\w+\.\w+$} } { set fields [split $host "."] set m3 [lindex $fields 2] set m4 [lindex $fields 3] set endofhost "$m3.$m4" log local0. "dans le regex fields 4 champs,champs3 : $m3, champs4: $m4; endofhost : $endofhost " set i 1 } if { $i == "0" } { log local0. "i=$i" if { ! ( [class match $host equals HTTP_exception_url_for_source_ip]) }{ log local0. "dans le match host : $host " snat automap forward } } if { $i == "1" } { log local0. "i=$i" if { ! ( [class match $endofhost equals HTTP_exception_url_for_source_ip]) }{ log local0. "dans le match endofhost : $endofhost " snat automap forward } } } } - kullwahad_19151
Nimbostratus
i've got another pb with HTTP::host contains "-" as www.google-analytics.com
"google-analytics" isn't match with "\w+"
I look at the regular expresssion documentation of TCL, but i don't figure how to do it...
Do you know how i can do it ?
Thx for the help.
- nitass_89166
Noctilucent
can we just use split command and then concat whatever domain level you want?
e.g.
% set host www.google-analytics.com www.google-analytics.com % set lhost [split $host .] www google-analytics com % put [llength $lhost] 3 % put [lindex $lhost 0] www % put [lindex $lhost 1] google-analytics % put [lindex $lhost 2] com- kullwahad_19151
Nimbostratus
thanks to you, I managed to do it. here for anyone for need it in a irule : set host [string tolower [HTTP::host]] set lhost [split $host .] set nbrfield [llength $lhost] set nbrendfiled [expr {$nbrfield - 1}] set nbrdomainfiled [expr {$nbrfield - 2}] set endfield [lindex $lhost $nbrendfiled] set domainfield [lindex $lhost $nbrdomainfiled] set endofhost "$domainfield.$endfield" Thanks a lot ! Regards
- nitass
Employee
can we just use split command and then concat whatever domain level you want?
e.g.
% set host www.google-analytics.com www.google-analytics.com % set lhost [split $host .] www google-analytics com % put [llength $lhost] 3 % put [lindex $lhost 0] www % put [lindex $lhost 1] google-analytics % put [lindex $lhost 2] com- kullwahad_19151
Nimbostratus
thanks to you, I managed to do it. here for anyone for need it in a irule : set host [string tolower [HTTP::host]] set lhost [split $host .] set nbrfield [llength $lhost] set nbrendfiled [expr {$nbrfield - 1}] set nbrdomainfiled [expr {$nbrfield - 2}] set endfield [lindex $lhost $nbrendfiled] set domainfield [lindex $lhost $nbrdomainfiled] set endofhost "$domainfield.$endfield" Thanks a lot ! Regards
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com