Forum Discussion
jay_41157
Aug 26, 2010Nimbostratus
Heat Maps irule by Colin.
Hi,
Thanks to Colin Walker for the great heatmap's irule.
I have tried to implement this irule but run into some problems and not sure where to look..Below is what I see in the l...
Chris_Miller
Aug 27, 2010Altostratus
I modified it a bit, assuming you didn't need the randomization logic.
when RULE_INIT {
set static::resp1 "Here is your site's usage by Country:
Zoom to region: | | | | | | "
}
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/asia" -
"/africa" -
"/europe" -
"/middle_east" -
"/south_america" -
"/usa" -
"/world" -
"/heatmap*" {
set chld ""
set chd ""
set zoom [string map {"/" "" "heatmap" "world"} [HTTP::uri]]
Configure the table query to be based on the countries subtable or the states subtable
if {$zoom eq "usa"} {
set region "states"
} else {
set region "countries"
}
Get a list of all states or countries and the associated count of requests from that area
foreach rg [table keys -subtable $region] {
append chld $rg
append chd "[table lookup -subtable $region $rg],"
}
set chd [string trimright $chd ","]
Send back the pre-formatted response, set in RULE_INIT, combined with the map zoom, list of areas, and request count
HTTP::respond 200 content "${static::resp1}${zoom}&chd=t:${chd}&chld=${chld}${static::resp2}"
}
"/resetmap" {
foreach country [table keys -subtable countries] {
table delete -subtable countries $country
}
foreach state [table keys -subtable states] {
table delete -subtable states $state
}
HTTP::respond 200 Content "
Table Cleared.
"
}
default {
Look up country & state locations
set cloc [whereis [IP::client_addr] country]
set sloc [whereis [IP::client_addr] abbrev]
Set Country
if {[table incr -subtable countries -mustexist $cloc] eq ""} {
table set -subtable countries $cloc 1 indefinite indefinite
}
Set State
if {[table incr -subtable states -mustexist $sloc] eq ""} {
table set -subtable states $sloc 1 indefinite indefinite
}
}
}
}
Give that a few shots and if you get TCL errors about variables not existing, we can add some catch logic...
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