Heatmap iRule Errors

I’ve implemented this - http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1084382/Heatmaps-iRules-Style-Part-1.aspxComments and am getting a few errors. Here’s the rule, slightly modified for my environment.

when HTTP_REQUEST { 
if { [HTTP::header exists "True-Client-IP"] }
     { set user_ip2 [HTTP::header True-Client-IP] }
else { set user_ip2 [IP::client_addr] }
  if {[HTTP::uri] starts_with "/heatmap" and [matchclass $user_ip2 equals $::whitelist]} { 
    set chld ""  
    set chd "" 
    foreach state [table keys -subtable states] { 
      append chld $state 
      append chd "[table lookup -subtable states $state]," 
    } 
    set chd [string trimright $chd ","] 
   HTML REMOVED SO DC DOESN'T PUT UP PIC
    log local0. "heatmap accessed by $user_ip2"
  } elseif {[HTTP::uri] starts_with "/resetmap" and [matchclass $user_ip2 equals $::whitelist]} { 
    foreach state [table keys -subtable states] { 
      table delete -subtable states $state 
    } 
    log local0. "heatmap reset by $user_ip2"
  } else { 
    set loc [whereis $user_ip2 abbrev] 
     log local0. "location is $loc"
    } 
    if {[table incr -subtable states -mustexist $loc] eq ""} { 
      table set -subtable states $loc 1 indefinite indefinite 
    }
  }

This produces the following errors in logs:

TCL error: rule_heatmap  - Illegal value (line 24) invoked from within "table incr -subtable states -mustexist $loc"

Hi Chris, I am curious to see what value you have for $loc. Have you tried outputting the value in debug? Bhattman

Posted By Bhattman on 07/06/2010 09:26 AM

Hi Chris, I am curious to see what value you have for $loc. Have you tried outputting the value in debug? Bhattman

Here’s some pretty typical behavior:

Jul  6 11:38:36 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:36 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:36 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:38 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm info tmm[12357]: 01220001:6: Resuming log processing at this invocation; held 4 messages.
Jul  6 11:38:39 local/tmm err tmm[12357]: 01220001:3: TCL error: rule_heatmap  - Illegal value (line 24)     invoked from within "table incr -subtable states -mustexist $loc"
Jul  6 11:38:39 local/tmm err tmm[12357]: 01220001:3: TCL error: rule_heatmap  - Illegal value (line 24)     invoked from within "table incr -subtable states -mustexist $loc"
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm err tmm[12357]: 01220001:3: TCL error: rule_heatmap  - Illegal value (line 24)     invoked from within "table incr -subtable states -mustexist $loc"
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm err tmm[12357]: 01220001:3: TCL error: rule_heatmap  - Illegal value (line 24)     invoked from within "table incr -subtable states -mustexist $loc"
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm err tmm[12357]: 01220001:3: TCL error: rule_heatmap  - Illegal value (line 24)     invoked from within "table incr -subtable states -mustexist $loc"
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm info tmm[12357]: 01220001:6: Per-invocation log rate exceeded; throttling.
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:39 local/tmm info tmm[12357]: Rule rule_heatmap : location is
Jul  6 11:38:40 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul  6 11:38:42 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul  6 11:38:43 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul  6 11:38:44 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul  6 11:38:46 local/tmm info tmm[12357]: Rule rule_heatmap : location is IL
Jul 6 11:44:00 :TCL error: rule_heatmap  - can't read "loc": no such variable while executing "table incr -subtable states -mustexist $loc"

Hi Chris,

Seems like the data you have isn’t acceptable which could be a negative number or a null value. My suggestion is to use a catch statement.

Here is a link to some info on catch http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/137/iRules-101\-\-07\-\-Catch.aspx

I hope this helps

Bhattman

Posted By Bhattman on 07/06/2010 11:36 AM

Hi Chris,

Seems like the data you have isn’t acceptable which could be a negative number or a null value. My suggestion is to use a catch statement.

Here is a link to some info on catch http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/137/iRules-101\-\-07\-\-Catch.aspx

I hope this helps

Bhattman

Thanks - I’ll check it out. How would I go about creating an additional heatmap? I basically want to have a heatmap that uses “True-Client-IP” as the source and another that uses “IP::client_addr” as the source. I imagine I’ll need two different tables and /heatmap and /heatmap2? I’m not sure what else I need to modify.

Hi Chris,

You’re trying to increment the states subtable on every request regardless of whether you’ve done a lookup of the client IP and saved the output to $loc. You can avoid the issue by moving the table incr command into the same else clause as the whereis command.

To build two separate heatmaps, you could use a token to differentiate between them. Here’s an untested suggestion to start with:

when HTTP_REQUEST {
   if { [HTTP::header exists "True-Client-IP"] }{
      set user_ip [HTTP::header True-Client-IP]
      set token "header"
   } else {
      set user_ip [IP::client_addr]
      set token "clientip"
   }
   if {[HTTP::uri] starts_with "/heatmap_$token" and [matchclass $user_ip equals whitelist]} {
      set chld ""
      set chd ""
      foreach state [table keys -subtable states_$token] {
         append chld $state
         append chd "[table lookup -subtable states_$token $state],"
      }
      set chd [string trimright $chd ","]
      HTML REMOVED SO DC DOESN'T PUT UP PIC
      log local0. "heatmap accessed by $user_ip"
   } elseif {[HTTP::uri] starts_with "/resetmap_$token" and [matchclass $user_ip equals whitelist]} {
      foreach state [table keys -subtable states_$token] {
         table delete -subtable states $state_$token
      }
      log local0. "heatmap reset by $user_ip"
   } else {
      set loc [whereis $user_ip abbrev]
      log local0. "location is $loc"
   }
   if {[table incr -subtable states_$token -mustexist $loc] eq ""} {
      table set -subtable states_$token $loc 1 indefinite indefinite
   }
}

Note that if you leave the $:: prefix on class names, the iRule will be demoted from CMP use.

Aaron