Forum Discussion

RossVermette's avatar
RossVermette
Icon for Nimbostratus rankNimbostratus
Feb 17, 2016

AppDynamics custom script injection

Hey,

 

I'm looking for a way to host a java script file name adrum.js (either by using an iFile or other method) and modify a variable that is set in that file based on HTTP host header name matches that is accessing the file. In the java script(adrum.js) the content contains ";a.appKey=window["adrum-app-key"]||"EUM-AAB-AUC";" embedded into some other code.

 

Example:

 

If the HTTP host header matches "devserver1" then set the string in the java script line to "EUM-AAB-AUD" or if HTTP host header matches "devserver2" then set the sting in the java script line to "EUM-AAB-AUF"

 

Here is what I was thinking, use a Data group to controls the HTTP::host(devserve1,devserver2) to variable mappings(EUM-AAB-AUD, EUM-AAB-AUF), host the java script file as an iFile. Anybody have any ideas or suggestions?

 

When HTTP_REQUEST { set APP_VAR_NAME [class find [HTTP::host] DATAGROUP1 ] switch {[string tolower [HTTP::uri]} { "/adrum.js" { HTTP::respond 200 content (get ifile) content-type "text/javascript" } }

 

2 Replies

  • Hi Ross,

     

    check the iRule below to see how your *.js can be fetched from an iFile with the additional "adrum-app-key" content replacement...

     

    when HTTP_REQUEST { 
        if { [string tolower [HTTP::uri]] eq "/adrum.js" } then {
            HTTP::respond 200 content [string map [list "adrum-app-key" [class lookup [HTTP::host] DATAGROUP1]] [ifile get "ifile-adrum.js"]] content-type "text/javascript"
        }   
    }

    ... to understand this code you may also read the very much less optimized version of...

     

    when HTTP_REQUEST { 
        if { [string tolower [HTTP::uri]] eq "/adrum.js" } then {
            set APP_VAR_NAME [class lookup [HTTP::host] DATAGROUP1]
            set APP_VAR_NAME_REPLACEMENT [list "adrum-app-key" $APP_VAR_NAME]
            set IFILE_RAW_CONTENT [ifile get "ifile-adrum.js"]
            set IFILE_FINAL_CONTENT [string map $APP_VAR_NAME_REPLACEMENT $IFILE_RAW_CONTENT]
            HTTP::respond 200 content $IFILE_FINAL_CONTENT Content-Type "text/javascript"
        }   
    }

    Cheers, Kai

     

  • There is no need to host adrum.js locally, let the AppDynamics CDN serve this file for you. Instead, you can use STREAM profiles, or a new option HTML Profiles to dynamically re-write the content in your pages. The advantage here is that you can put the EUM key in a data group as well. This is something that I have not done yet, but it is on my todo list.

     

    I just posted my code out on CodeShare since this is a work in progress

     

    https://devcentral.f5.com/codeshare/appdynamics-eum-javascript-injection-for-selective-urls