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.
JRahm
Community Manager
Community Manager

Problem this snippet solves:

The following iRule will utilize the Stream profile to auto-inject the required client side Gomez Networks performance measurement JavaScript code. It builds on the GomezInjection CodeShare entry in that it provides support for the Group id parameter to allow for datacenter specific search within the Gomez Reporting engine. Just like the previous example, this iRule performs two functions:

First of all, it will serve up the Gomez Javascript bootstrap code so you do not have to come up with a location to store this on one of your servers. In this example, the javascript is included inline in the script. As a consequence, a string substitution has to be made to replace all the braces at runtime. This overcomes a limitation with the BIG-IP command line import utility in it's handling of a large number of embedded braces. An alternate implementation could be to store this script in an external class file and load the contents with a TCL lindex command as seen in Automatic Sorry Page

How to use this snippet:

Steps to Install

  • Gomez Account Id: You need to apply for a Gomez account and obtain your Gomez Application Id. This is typically a 6-character string. You'll need to replace the value of the GOMEZ_APP_ID variable with your correct application id.
  • Build a list of your local addresses on all of your virtual servers and add them to the GOMEZ_GROUPID_LIST TCL list in the HTTP_REQUEST event.
  • Virtual Server: Enable the default Stream filter profile on your Virtual Server. Also, ensure you have a valid HTTP profile configured.
  • HTTP Profile: Set the value of "Response Chunking" in your HTTP Profile to "Rechunk".
  • iRule: Save the iRule to your LTM and add it as a resource to your Virtual Server.

Code :

when HTTP_REQUEST {

  set GOMEZ_APP_ID "XXXXXX";
  set GOMEZ_DEBUG 0;
  set GOMEZ_DEFAULT_GROUP_ID "DC_PRD";
  
  set GOMEZ_GROUPID_LIST [list \
    "xxx.xxx.xxx.141 DC_PRD_DC1" \
    "xxx.xxx.xxx.28 DC_PRD_DC2_C1" \
    "xxx.xxx.xxx.28 DC_PRD_DC2_C2" \
    "xxx.xxx.xxx.36 DC_PRD_DC2_C2_NO_WAM" \
    "xxx.xxx.xxx.167 DC_PRD_DC3" \
    "xxx.xxx.xxx.117 DC_DEV_DC1" \
    "xxx.xxx.xxx.116 DC_DEV_DC1" \
    "xxx.xxx.xxx.115 DC_DEV_DC2" \
    "xxx.xxx.xxx.40 DC_STG_DC1" \
  ];

  set gomez_group_id "";

  set gws_luri [string tolower [HTTP::uri]]
  
  if { $gws_luri eq "/js/axftag.js" } {
    
    # -----------------------------------------------------------------------
    # Serve up Gomez bootstrap javascript
    # -----------------------------------------------------------------------
    HTTP::respond 200 content [string map {LBR \{ RBR \}} {/*Gomez tag version: 5.0*/var gomez=gomez?gomez:LBRRBR;gomez.h3=function(d, s)LBRfor(var p in s)LBRd[p]=s[p];RBRreturn d;RBR;gomez.h3(gomez,LBRb3:function(r)LBRif(r<=0)return false;return Math.random()<=r&&r;RBR,b0:function(n)LBRvar c=document.cookie;var v=c.match(new RegExp(';[ ]*'+n+'=([^;]*)'));if(!v)v=c.match(new RegExp(n+'=([^;]*)'));if(v)return unescape(v[1]);return '';RBR,c2:function(n,v,e,p,d,s)LBRtryLBRvar t=this,a=location.hostname;var c=n+'='+escape(v)+(e?';expires='+e.toGMTString():'')+(p?';path='+p:';path=/')+(d?';domain='+d:';domain='+a)+(s?';secure':'');document.cookie=c;RBRcatch(e)LBRRBRRBR,z0:function(n)LBRvar t=this;if(n)LBRvar s =t.b0("__g_c");if(!s)return '';var v=s.match(new RegExp(n+':([^\|]*)'));if(v)return unescape(v[1]);return '';RBRelse return '';RBR,z1:function(n,m)LBRvar t=this;if(n)LBRvar s=t.b0("__g_c");if(s)LBRif(s.indexOf(n+':')!=-1)s=s.replace(new RegExp('('+n+':[^\|]*)'),n+':'+m);else s=s==' '?n+':'+m:s+'|'+n+':'+m;t.c2("__g_c",s);RBRelse t.c2("__g_c",n+':'+m);RBR;RBRRBR);if(gomez.wrate)LBRgomez.i0=gomez.z0('w');if(gomez.i0)LBRgomez.runFlg=parseInt(gomez.i0)>0?true:false;RBRelse if(gomez.b3(parseFloat(gomez.wrate)))LBRgomez.runFlg=true;gomez.z1('w',1);RBRelseLBRgomez.runFlg=false;gomez.z1('w',0);RBRRBRelse if(gomez.wrate==undefined)LBRgomez.runFlg=true;gomez.z1('w',1);RBRelseLBRgomez.runFlg=false;gomez.z1('w',0);RBR;if(gomez.runFlg)LBRgomez.h1=function(v,d)LBRreturn v?v:dRBR;gomez.gs=gomez.h1(gomez.gs,new Date().getTime());gomez.acctId=gomez.h1(gomez.acctId,'');gomez.pgId=gomez.h1(gomez.pgId,'');gomez.grpId=gomez.h1(gomez.grpId, '');gomez.E=function(c)LBRthis.s=c;RBR;gomez.E.prototype=LBRg1:function(e)LBRvar t=gomez,i=t.g6(e);if(i)i.e=t.b5();RBRRBR;gomez.L=function(m)LBRthis.a=m;RBR;gomez.L.prototype=LBRg2:function(m)LBRvar t=gomez,n=t.b5();var s=document.getElementsByTagName(m);var e=t.k;if(m=='script')e=t.j;if(m=='iframe')e=t.l;if(s)LBRvar l=s.length;for(var i=0;i<\/scr"+"ipt>");else t.h5(s);RBR;t.b=t.z0('g');RBR,h7:function()LBRvar t=gomez,u=t.tloc?t.tloc:location.protocol+'//'+t.acctId+'.t.axf8.net/js/gtag5.js';if(t.gSfr)document.write("<\/scr"+"ipt>");else t.h5(u);RBR,n0:function(h)LBRvar t=gomez,f=new Date(t.gt()+946080000000),g=t.b0('__g_u');t.n1=h;t.z1('h',h);if(g&&g!='1'&&g.indexOf('NaN')==-1&&g.indexOf('undefined')==-1)LBRvar r=g.split('_');g=''+r[0]+'_'+r[1]+'_'+r[2]+'_'+r[3]+'_'+r[4]+'_'+r[5]+'_'+h;t.c2('__g_u',g,f);RBR;RBR,b1:function(v,s,q,f)LBRvar t=this;if(t._a)return;if(t.b3(v))LBRt._w=true;t.a=1;var p=parseFloat(s/v);if(t.b3(p))LBRt.x=true;t.a=3;RBR;RBR;t.d=true;t.z1('a',t.a);t.z1('e',v);t.z1('f',s);t.gc.i=v;t.gc.j=s;t.h4(v,s,q,f);if(t._w)LBRt.h7();t._a=true;RBR;RBR,b2:function(v,s)LBRvar t=this,f=new Date(t.gt()+946080000000),g=''+v+'_'+s;if(t._a)return;t.c2('__g_u',g,f);t.gc.c=v;t.gc.d=s;t.z1('c',v);t.z1('d',s);RBR,h4:function(o,p,q,d)LBRvar t=this,f=new Date(t.gt()+946080000000),g=t.b0('__g_u');if(g&&g!='1'&&g.indexOf('NaN')==-1&&g.indexOf('undefined')==-1)LBRvar r=g.split('_'),s;if(d)s=d;else if(q&&q>=0)s=new Date(t.gt()+parseInt(q*86400000)).getTime();elseLBRq=5;s=new Date(t.gt()+432000000).getTime();RBR;g=''+r[0]+'_'+r[1]+'_'+o+'_'+p+'_'+q+'_'+s;t.c2('__g_u',g,f);RBR;RBR,gt:function()LBRreturn new Date().getTime()RBR,b5:function()LBRreturn new Date().getTime()-gomez.gsRBR,b6:function()LBRvar t=gomez;t.p=t.b5();RBR,f8:function()LBRvar t=this;if(t.pollId1)clearInterval(t.pollId1);if(t.pollId2)clearInterval(t.pollId2);if(t.pollId3)clearInterval(t.pollId3);if(t.pollId4)clearInterval(t.pollId4);RBR,b7:function()LBRvar t =gomez;t.f8();t.q=t.b5();RBR,c7:function(u, s)LBRvar t=this;t.m=u;t.s=s;RBR,c8:function()LBRvar t=gomez,n=t.b5(),l=document.images.length;if(l>t._h)LBRfor(var i=t._h; i20) n=n.substring(0,20);var t=this,f=t.u;if(p==3)LBRf[f.length]=LBR'n':'a','a':n,'b':b,'e':p,'f':undefinedRBR;RBRelseLBRf[f.length]=LBR'n':'a','a':n,'b':t.b5(),'e':p,'f':bRBR;RBRRBR,customValue:function(n,v)LBRvar t=this;if(typeof(v)!='number')LBRreturn;RBRt.f6(n,3,v);RBR,d8:function(e)LBRif(gomez.gIE)return e.srcElement||LBRRBR;else return e.currentTarget||e.target||LBRRBR;RBR,e2:function(e,p,f,c)LBRvar n='on'+p;if(e.addEventListener)e.addEventListener(p,f,c);else if(e.attachEvent)e.attachEvent(n, f);elseLBRvar x=e[n];if(typeof e[n]!='function')e[n]=f;else e[n]=function(a)LBRx(a);f(a);RBR;RBRRBR,i1:function()LBRvar d =window.document, done=false,i2=function ()LBRif(!done)LBRdone=true;gomez.b6();gomez.a9();RBRRBR;(function ()LBRtryLBRd.documentElement.doScroll('left');RBRcatch(e)LBRsetTimeout(arguments.callee, 50);return;RBRi2();RBR)();d.onreadystatechange=function()LBRif(d.readyState=='complete')LBRd.onreadystatechange=null;i2();RBRRBR;RBR,g7:function()LBRtryLBRvar t=gomez;t.gc.a=t.acctId;/*@cc_on t.gIE=true;@*/if(t.gIE)LBRt.i1();window.attachEvent('onload', t.b7);RBRelse if(t.gSfr)LBRvar m=setInterval(function()LBRif(/loaded|complete/.test(document.readyState))LBRclearInterval(m);delete m;t.b6();t.b7();RBRRBR, 10);RBRelse if(window.addEventListener)LBRwindow.addEventListener('DOMContentLoaded', t.b6, false);window.addEventListener('load', t.b7, false);RBRelse return;t.c8();t.pollId1=setInterval(t.c8, 10);gomez.L.m['link'].g2('link');t.pollId3=setInterval("gomez.L.m['link'].g2('link')", 10);gomez.L.m['iframe'].g2('iframe');t.pollId4=setInterval("gomez.L.m['iframe'].g2('iframe')", 10);if(!t.gIE)t.a9();RBRcatch(e)LBRreturn;RBRRBRRBR);gomez.h2();gomez.g7();RBR}] "Content-Type" "application/x-javascript" "Cache-Control" "max-age=86400";

  } else {
    
    # ---------------------------------------------------------------------
    # Don't allow response data to be chunked
    # ---------------------------------------------------------------------
    if { [HTTP::version] eq "1.1" } {
      
      # -------------------------------------------------------------------
      # Force downgrade to HTTP 1.0, but still allow keep-alive connections.
      # Since HTTP 1.1 is keep-alive by default, and 1.0 isn't,
      # we need make sure the headers reflect the keep-alive status.
      # -------------------------------------------------------------------
      
      if { [HTTP::header is_keepalive] } {
        HTTP::header replace "Connection" "Keep-Alive";
      }
    }
      
    # ---------------------------------------------------------------------
    # Lookup the Group ID from the local address on this virtual server.
    # ---------------------------------------------------------------------
    set gomez_group_id [findclass [IP::local_addr] $GOMEZ_GROUPID_LIST " "]
    if { $gomez_group_id eq "" } {
      if { $GOMEZ_DEBUG > 0 } { log local0. "Couldn't find addr [IP::local_addr] in group lookup..." }
      set gomez_group_id $GOMEZ_DEFAULT_GROUP_ID;
    }
    
    if { $GOMEZ_DEBUG > 0 } { log local0. "Local Addr: [IP::local_addr] - group $gomez_group_id"; }
  }
}

 when HTTP_RESPONSE {
   
  # -------------------------------------------------------------------------
  # Stream filter is disabled by default
  # -------------------------------------------------------------------------
  STREAM::disable;
   
  # -------------------------------------------------------------------------
  # Only process stream replacement for a valid response and content type is html.
  # -------------------------------------------------------------------------
  if { ([HTTP::header Content-Type] starts_with "text/html") && ([HTTP::status] == 200) } {
    
    if { $GOMEZ_DEBUG > 1 } { log local0. "Adding Gomez JavaScript"; }
    
    set gomez_client [subst { 
Version history
Last update:
‎17-Mar-2015 14:21
Updated by:
Contributors