APM - Track clicks on webtop resources
Problem this snippet solves:
This configuration sample provide to the administrator a way to log all APM webtop resources clicked by a logged-in user. Those logs can be exported to external systems like Splunk to do some Analytics.
Those configuration objects are currently for experimentation only. It is not recommended for production yet.
How to use this snippet:
Insert this javascript snippet to the end of the hometab.inc file that you can find and modify in Advanced Customization >> Your Webtop Name.
window.onclick = function(e) { if (e.target.parentNode.className == "favorite") { var xhttp = new XMLHttpRequest(); console.log(e.target.parentNode.id); var uri = "/analytics?t=" + Math.random() + "&r=" + encodeURIComponent(window.btoa(e.target.parentNode.id)) + "&d=" + Date.now(); xhttp.open("GET", uri, true); xhttp.send(); } if (e.target.parentNode.className == "image" && e.target.parentNode.parentNode.className == "favorite") { var xhttp = new XMLHttpRequest(); console.log(e.target.parentNode.id); var uri = "/analytics?t=" + Math.random() + "&r=" + encodeURIComponent(window.btoa(e.target.parentNode.parentNode.id)) + "&d=" + Date.now(); xhttp.open("GET", uri, true); xhttp.send(); } };
Then, add the irule provided in the attachment of this article to the Virtual Server with the access profile.
Here is an example of logged accesses :
time=08/14/17 20:19:24, clientip=10.20.30.5, user=test, session=a7585749, res=/Common/fullvpn-test time=08/14/17 20:19:22, clientip=10.20.30.5, user=test, session=a7585749, res=/Common/debian-test
Code :
when RULE_INIT { # Required Before v13.x set static::ACCESS_LOG_PREFIX "0149ffff:5:" } when ACCESS_ACL_ALLOWED { if { [HTTP::cookie exists MRHSession] and [ACCESS::session exists -state_allow -sid [HTTP::cookie MRHSession]] and [HTTP::path] eq "/analytics" } { set time [clock format [expr { [URI::query [HTTP::uri] "d"]/1000 }] -format "%D %T"] set res [b64decode [URI::decode [URI::query [HTTP::uri] "r"]]] set user [ACCESS::session data get session.logon.last.username] set session [HTTP::cookie value LastMRH_Session] set clientip [ACCESS::session data get session.user.clientip] # # Basic logging. Remote or local logging settings can be configured # # log local0. "time=$time, clientip=$clientip, user=$user, session=$session, res=$res" # # ACCESS logging before v13.x # log -noname accesscontrol.local1.notice "$static::ACCESS_LOG_PREFIX /Common/ap-ad-auth:Common:$session: time=$time, clientip=$clientip, user=$user, res=$res" # # ACCESS::log is available in v13.x. Log saved in Access report too. # # ACCESS::log accesscontrol.notice "time=$time, clientip=$clientip, user=$user, res=$res" ACCESS::respond 200 noserver } }
Tested this on version:
11.5Updated Jun 06, 2023
Version 2.0