on 18-Mar-2015 15:19
Problem this snippet solves:
This sample goes along with the Tech Tip titled Session Table Control With iRules . It creates an iRules-based HTML application to allow you to view, edit, delete, import, and export your session subtable data.
10/1/2020 - This iRule has been updated to fix the script tag, uri, and "C"ontent issues.
How to use this snippet:
Apply to a virtual server with session table entries and you can import/export/edit/delete entries.
Code :
when HTTP_REQUEST { set APPNAME "subtables"; set luri [string tolower [HTTP::path]] set app [getfield $luri "/" 2]; set cmd [getfield $luri "/" 3]; set tname [URI::decode [getfield [HTTP::path] "/" 4]]; set arg1 [URI::decode [getfield [HTTP::path] "/" 5]]; set arg2 [URI::decode [getfield [HTTP::path] "/" 6]]; set resp ""; set send_response 1; if { $app equals $APPNAME } { log local0. "Processing application $app..."; if { $cmd eq "" } { set cmd "edit"; } if { $tname eq "file" } { set tname ""; } log local0. "INCOMING URI: $luri, app=$app, cmd=$cmd, tname=$tname"; set TABLENAME_FORM ""; set FILEINPUT_FORM " "; append resp "
iRule Table Control($cmd)edit | export | import | delete" #------------------------------------------------------------------------ # Process commands #------------------------------------------------------------------------ switch $cmd { "edit" { #---------------------------------------------------------------------- # edit #---------------------------------------------------------------------- log local0. "SUBCOMMAND: edit"; if { $tname eq "" } { append resp $TABLENAME_FORM } else { append resp ""; append resp "\n"; append resp "
Subtable $tname successfully deleted"; } } "deletekey" { #---------------------------------------------------------------------- # deletekey #---------------------------------------------------------------------- log local0. "SUBCOMMAND: deletekey"; if { ($tname ne "") && ($arg1 ne "") } { log local0. "Deleting subtable $tname key $arg1..."; table delete -subtable $tname $arg1; HTTP::redirect "http://[HTTP::host]/${APPNAME}/edit/${tname}"; return; } } "insertkey" { #---------------------------------------------------------------------- # insertkey #---------------------------------------------------------------------- log local0. "SUBCOMMAND: insert"; if { ($tname ne "") && ($arg1 ne "") && ($arg2 ne "") } { log local0. "Inserting subtable $tname key $arg1..."; table set -subtable $tname $arg1 $arg2 indefinite indefinite HTTP::redirect "http://[HTTP::host]/${APPNAME}/edit/${tname}"; return; } } } if { $send_response == 1 } { append resp " |
I found this recently and greatly appreciate the code. It has made monitoring a table very easy. I do have one caution to anyone else using it. The act of refreshing the edit display to see what is in the table, resets the timeout. In my case,. I did not want the observation of the table to reset the time. I added -notouch to the line
foreach key [table keys -notouch -subtable $tname] {
(line 133 above). I also added -notouch to line 135 so it reads
append resp "<td class='tvalue'>[table lookup -notouch -subtable $tname $key]</td>";