Forum Discussion

smiley_dba_1116's avatar
smiley_dba_1116
Icon for Nimbostratus rankNimbostratus
Feb 28, 2016

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 them all. Now Im getting the attached error now. has anyone else used the Link tracker and had issues with the code parsing?

 

    when HTTP_REQUEST {

set TABLE_LINK "LINK_TRACKING_[virtual name]";
set TABLE_FILTERS "LINK_TRACKING_FILTERS_[virtual name]";

swith -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 ")") } {
set count_filter "";
set data_filter [string range $msg 2 end-1];
set msg "";
} elseif { ($msg starts_with "c(") && ($msg ends_with ")") } {
set count_filter [string range $msg end-1];
set data_filter "";
set msg "";
}
set count [table keys -subtable $TABLE_LINK -count]
set content {URI tracking





URI Tracking
append content "$TABLE_LINK"
append content "Link Count$count"
append content {Controls





}
append content "URI Filters"
foreach key [table keys -subtable $TABLE_FILTERS] {
append content "\[\] $key
";
}
append content "";
append content {Add Filter

}
if { "" !=$msg } {
append content "Message%msg";
}
append content "";
append content ""
append content "Link Metrics";
append content "URICount";
append content {Filter Results }
append content " []
}
append content " []
};
foreach key [lsort -dictionary [table keys -subtable $TABLE_LINK]] {
if { "" !=$data_filter } {
if { [string match $data_filter $key] } {
set v [table lookup -subtable $TABLE_LINK $key];
append content "\[\] $key$v";
}
}elseif { "" != $count_filter } {
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 }{
table delete -subtable $TABLE_LINK $val;
}
HTTP::redirect "http://[HTTP::host]/linkadmin/Link+Deleted";
}
"/linkclearfilter" {
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}{
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 }{
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 } {
set match 0;
foreach key [lsort [table keys -subtable $TABLE_FILTERS]] {
set m [string match $key [HTTP::uri]];
if { 1 == $m } {
set match 1;
break;
}
}
}
}
}
}

4 Replies

  • First issue I found after walking away is that i mispelled switch with swich. still getting errors. 01070151:3: Rule [/Common/test] error: /Common/test:16: error: [wrong args][string range $msg end-1] /Common/test:84: error: [undefined procedure: /linkcleardata]["/linkcleardata"{ table delete -subtable $TABLE_LINK -all; HTTP::redirect "http://[HTTP::host]/linkadmin/link+Tracking+Cleared"
  • There's a } missing before the "/linkcleardata".

     

    I don't have an F5 on me at the moment, so i can't confirm if there are any other errors.

     

    HTH.

     

  • ok. I tried that, but still getting that clear data issue.

    Error /linkcleardata]["/linkcleardata" { table delete -subtable $TABLE_LINK -all;

     

    when HTTP_REQUEST {
    
    set TABLE_LINK    "LINK_TRACKING_[virtual name]";
    set TABLE_FILTERS "LINK_TRACKING_FILTERS_[virtual name]";
    
    swith -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 ")") } {
    set count_filter "";
    set data_filter [string range $msg 2 end-1];
    set msg "";
    } elseif { ($msg starts_with "c(") && ($msg ends_with ")") } {
    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
    append content "$TABLE_LINK"
    append content "Link Count$count"
    append content {Controls
    
    
    
    
    
    }
    append content "URI Filters"
    foreach key [table keys -subtable $TABLE_FILTERS] {
    append content "\[\] $key
    ";
    }
    append content "";
    append content {Add Filter
    
    }
    if { "" !=$msg } {
    append content "Message%msg";
    }
    append content "";
    append content ""
    append content "Link Metrics";
    append content "URICount";
    append content {Filter Results }
    append content "x]
      }
    append content " []
    };
    foreach key [table keys -subtable $TABLE_LINK] {
    if { "" != $data_filter } {
    if { [string match $data_filter $key] } {
    set v [table lookup -subtable $TABLE_LINK $key];
    append content "\[\] $key$v";
    }
    } elseif { "" != $count_filter } {
    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 }{
    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}{
    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 }{
    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 } {
    set match 0;
    foreach key [lsort [table keys -subtable $TABLE_FILTERS]] {
    set m [string match $key [HTTP::uri]];
    if { 1 == $m } {
    set match 1;
    break;
    }
    }
    }
    }
    }
    }
    }
    

     

  • 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