cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.
Joe_Pruitt
Cirrostratus
Cirrostratus

Problem this snippet solves:

This iRule application builds on the LinkTracking and LinkTracking2 iRule2 that allows you to track URI's that come in through your virtual server and store them in a table with the number of times they have been referenced. The data stored can then be viewed by passing in the "/linkadmin" url which will generate a table of the URI's and their view counts. In this iRule, I've built on the report filtering in LinkTracking2 by adding adding support for URI prefilters that allow you to only store the data for URIs that match specific patterns.

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 ")") } {
        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 {Link Tracking
        
        
        
        
"; append content "" append content {} append content ""; append content {} if { "" != $msg } { append content ""; } append content "
iRule Link TrackingControl Panel
Table Name} append content "$TABLE_LINK
Link Count$count
Controls Clear Data Clear Filters Refresh
URI Filters" foreach key [table keys -subtable $TABLE_FILTERS] { append content "\[x\] $key"; } append content "
Add Filter
Message$msg
"; append content "" append content ""; append content ""; 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 ""; } } elseif { "" != $count_filter } { set v [table lookup -subtable $TABLE_LINK $key]; if { $v >= $count_filter } { append content ""; } } else { set v [table lookup -subtable $TABLE_LINK $key]; append content ""; } } append content "
Link Metrics
URICount
Filter Results } append content " [x] [x]
\[x\] $key$v
\[x\] $key$v
\[x\] $key$v
"; 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; } } } if { $match == 1} { if { [table incr -subtable $TABLE_LINK -mustexist [HTTP::uri]] eq ""} { table set -subtable $TABLE_LINK [HTTP::uri] 1 indefinite indefinite; } } } } }
Comments
B_Earp
Nimbostratus
Nimbostratus

Blank screen....

 

B_Earp
Nimbostratus
Nimbostratus

The "HTTP::respond 200 Content $content" should have a lower case c ==> "HTTP::respond 200 content $content"

 

Version history
Last update:
‎18-Mar-2015 12:14
Updated by:
Contributors