Forum Discussion
smiley_dba_1116
Feb 28, 2016Nimbostratus
URI Tracker - Question - ERROR: undefined procedure: swith][swith -glob [string tolower [HTTP::uri]]
URI tracker code is driving me nutts. I dont know if my backets are screwed up or if my HTTP::uri is screwed. For awhile, I was getting a cross bracket error, but after using Notepad++, I THINK i got...
Kai_Wilke
Feb 29, 2016MVP
Hi Smiley,
reworked your code formatings and catched almost a dozend TCL/HTML glitches.
I've changed a little bit your sytax to rely more on substitution instead of switching between "" and {} escaped $content. The new code will only leave HTML when you have to [if] or [foreach] dynamic HTML code.
when HTTP_REQUEST {
set TABLE_LINK "LINK_TRACKING_[virtual name]"
set TABLE_FILTERS "LINK_TRACKING_FILTERS_[virtual name]"
switch -glob [string tolower [HTTP::uri]] {
"/linkadmin*" {
set count_filter ""
set data_filter ""
set msg [URI::decode [getfield [HTTP::uri] "/" 3]]
if { ($msg starts_with "f(") && ($msg ends_with ")") } then {
set count_filter ""
set data_filter [string range $msg 2 end-1]
set msg ""
} elseif { ($msg starts_with "c(") && ($msg ends_with ")") } then {
set count_filter [string range $msg 2 end-1]
set data_filter ""
set msg ""
}
set count [table keys -subtable $TABLE_LINK -count]
set content "
URI tracking
URI Tracking
$TABLE_LINK
Link Count
$count
Controls
URI Filters
"
foreach key [table keys -subtable $TABLE_FILTERS] {
append content "\[\] $key
"
}
append content "
Add Filter
"
if { "" !=$msg } then {
append content "
Message
$msg
"
}
append content "
Link Metrics
URI
$count
Filter Results
\[\]
\[\]
"
foreach key [table keys -subtable $TABLE_LINK] {
if { "" != $data_filter } then {
if { [string match $data_filter $key] } then {
set v [table lookup -subtable $TABLE_LINK $key]
append content "
\[\] $key
$v
"
}
} elseif { "" != $count_filter } then {
set v [table lookup -subtable $TABLE_LINK $key]
if { $v >= $count_filter } {
append content "
\[\] $key
$v
"
}
} else {
set v [table lookup -subtable $TABLE_LINK $key]
append content "
\[\] $key
$v
"
}
}
append content "
"
HTTP::respond 200 Content $content
}
"/linkcleardata" {
table delete -subtable $TABLE_LINK -all
HTTP::redirect "http://[HTTP::host]/linkadmin/Link+Tracking+Cleared"
}
"/linkremovedata/*" {
set val [string range [HTTP::uri] [string length "linkremovedata/"] end]
if { "" != $val } then {
table delete -subtable $TABLE_LINK $val
}
HTTP::redirect "http://[HTTP::host]/linkadmin/Link+Deleted"
}
"/linkclearfilters" {
table delete -subtable $TABLE_FILTERS -all
HTTP::redirect "http://[HTTP::host]/linkadmin/Link+Filters+Cleared"
}
"/linkaddfilter/*" {
set f [string range [HTTP::uri] [string length "/linkaddfilter/"] end]
if { "" != $f} then {
table add -subtable $TABLE_FILTERS $f 1 indefinite indefinite
}
HTTP::redirect "http://[HTTP::host]/linkadmin/Filter+Added"
}
"/linkremovefilter/*" {
set val [string range [HTTP::uri] [string length "linkremovefilter/"] end]
if { "" != $val } then {
table delete -subtable $TABLE_FILTERS $val
}
HTTP::redirect "http::/[HTTP::host]/linkadmin/Filter+Deleted"
}
default {
set match 1
set c [table keys -subtable $TABLE_FILTERS -count]
if { $c != 0 } then {
set match 0
foreach key [lsort [table keys -subtable $TABLE_FILTERS]] {
set m [string match $key [HTTP::uri]]
if { 1 == $m } then {
set match 1
break
}
}
}
}
}
}
Note: Just saved the iRule for debugging purposes. But didn't executed the iRule at all.
Cheers, Kai
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects