The idle tracker installs itself through the VM's UserData on first boot. It only installs when AppEnabled is True and OdlTrackingSource is 1 or 2.
Windows VM: idle tracker in UserData
This block is added only when AppEnabled is True and OdlTrackingSource is 1 or 2. Otherwise the UserData just prints App Enabled is False.
Enable TLS 1.2 so the download works.
Download the installer from WindowsIdletrackingInstallationScriptUrl to C:\WindowsIdleTrackingInstallationScripts.ps1.
Get the instance ID from AWS metadata (169.254.169.254), using a token first.
Run the installer with the idle settings below plus the instance ID.
Delete the installer with Remove-Item.
Script to add
Add this Fn::If block inside the UserData's Fn::Join list, after your own setup script and before the closing </powershell>. It also needs the AppEnabledAndOdlTrackingCondition under Conditions.
{
"Fn::If": [
"AppEnabledAndOdlTrackingCondition",
{
"Fn::Join": ["\n", [
{ "Fn::Sub": "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;" },
{ "Fn::Sub": "Invoke-WebRequest ${WindowsIdletrackingInstallationScriptUrl} -OutFile 'C:/WindowsIdleTrackingInstallationScripts.ps1'" },
{ "Fn::Sub": "$Token = (Invoke-WebRequest -Method PUT -Uri \"http://169.254.169.254/latest/api/token\" -Headers @{\"X-aws-ec2-metadata-token-ttl-seconds\" = \"21600\"} -UseBasicParsing).Content\n$InstanceID = (Invoke-WebRequest -Uri \"http://169.254.169.254/latest/meta-data/instance-id\" -Headers @{\"X-aws-ec2-metadata-token\" = $Token} -UseBasicParsing).Content" },
{ "Fn::Sub": "C:\\WindowsIdleTrackingInstallationScripts.ps1 ${WindowsIdlecheckFeatureConnectionString} ${Version} ${AppEnabled} ${ShutdownOnIdle} ${ShutdownOnIdleTimeout} ${WarningWaitTimeout} ${TrackingMode} ${ShutdownOnDisconnect} ${ShutdownOnDisconnectTimeout} ${ShutdownWhenNoUsersConnected} ${ShutdownWhenNoUsersConnectedTimeout} ${AppCheckFrequency} $InstanceID ${CloudLabsDeploymentIDEncrypt}" },
{ "Fn::Sub": "Remove-Item 'C:/WindowsIdleTrackingInstallationScripts.ps1' -Force" }
]]
},
{ "Fn::Sub": "echo 'App Enabled is False'" }
]
}
Keep the installer arguments in this order; the script reads them by position. ${...} values come from the parameters below, while $Token and $InstanceID are PowerShell variables set at boot.
The condition to add under Conditions:
"AppEnabledAndOdlTrackingCondition": {
"Fn::And": [
{ "Fn::Equals": [{ "Ref": "AppEnabled" }, "True"] },
{ "Fn::Or": [
{ "Fn::Equals": [{ "Ref": "OdlTrackingSource" }, 1] },
{ "Fn::Equals": [{ "Ref": "OdlTrackingSource" }, 2] }
]}
]
}
Windows VM: parameters
CloudLabs fills these from the parameter file at deployment.
Parameter | Value in parameter file | What it does |
|---|---|---|
WindowsIdletrackingInstallationScriptUrl | AWS-WINDOWS-IDLETRACKING-INSTALLATION-SCRIPT-URL | Where the installer is downloaded from |
WindowsIdlecheckFeatureConnectionString | WINDOWS-IDLECHECK-FEATURE-CONNECTION-STRING | Where the tracker reports activity |
Version | GET-IDLE-TRACKING-VERSION | Tracker version |
AppEnabled | GET-ODL-ENABLE-ATTENDEE-TRACKING | Turns tracking on (True / False) |
OdlTrackingSource | GET-ODL-TRACKING-SOURCE | Must be 1 or 2, or the tracker is skipped |
ShutdownOnIdle | GET-ODL-ENABLE-SHUTDOWNONIDLE | Shut down when the user is idle |
ShutdownOnIdleTimeout | GET-ODL-SHUTDOWNONIDLE-TIMEOUT | Idle time before shutdown |
WarningWaitTimeout | GET-ODL-SHUTDOWNONIDLE-WARNINGWAITTIMEOUT | How long the idle warning waits |
TrackingMode | GET-ODL-SHUTDOWNONIDLE-TRACKINGMODE | Idle detection mode |
ShutdownOnDisconnect | GET-ODL-ENABLE-SHUTDOWNONDISCONNECT | Shut down after RDP disconnects |
ShutdownOnDisconnectTimeout | GET-ODL-SHUTDOWNONDISCONNECT-TIMEOUT | Wait time after disconnect |
ShutdownWhenNoUsersConnected | GET-ODL-ENABLE-SHUTDOWNWHENNOUSERSCONNECTED | Shut down when nobody is signed in |
ShutdownWhenNoUsersConnectedTimeout | GET-ODL-SHUTDOWNWHENNOUSERSCONNECTED-TIMEOUT | Wait time with no users signed in |
AppCheckFrequency | 2 | How often the tracker checks |
CloudLabsDeploymentIDEncrypt | GET-DEPLOYMENT-ID-ENCRYPT | Links the VM to its deployment |
Sample Windows VM Idle Tracker File URL’s:
Linux VM: idle tracker in UserData
Same condition as Windows: the block runs only when AppEnabled is True and OdlTrackingSource is 1 or 2. Your base script must install wget, curl and dos2unix first, since the tracker block uses them.
Download and run the bashrc script from AddToBashrcScriptUrl to /opt/main.sh.
Download the installer from IdleTrackingInstallationScriptUrl to /opt/LinuxIdleTrackingInstallationScript.sh. dos2unix fixes Windows line endings in both scripts.
Add sysadmin to sudoers and get the instance ID from AWS metadata, using a token first.
Run the installer with the idle-check and xprintidle download URLs (x64 and arm64), the idle settings and the instance ID.
Delete both scripts.
Script to add
Add this Fn::If block inside the UserData's Fn::Join list, after your bash setup script. The same AppEnabledAndOdlTrackingCondition goes under Conditions.
{
"Fn::If": [
"AppEnabledAndOdlTrackingCondition",
{
"Fn::Join": ["\n", [
{ "Fn::Sub": "wget ${AddToBashrcScriptUrl} -O /opt/main.sh\nchmod 0777 /opt/main.sh\ndos2unix /opt/main.sh\n/opt/main.sh" },
{ "Fn::Sub": "wget ${IdleTrackingInstallationScriptUrl} -O /opt/LinuxIdleTrackingInstallationScript.sh\nchmod 0777 /opt/LinuxIdleTrackingInstallationScript.sh\ndos2unix /opt/LinuxIdleTrackingInstallationScript.sh" },
{ "Fn::Sub": "echo 'sysadmin ALL=(ALL:ALL) ALL' >> /etc/sudoers\nTOKEN=$(curl -X PUT 'http://169.254.169.254/latest/api/token' -H 'X-aws-ec2-metadata-token-ttl-seconds: 21600')\ninstanceId=$(curl -H \"X-aws-ec2-metadata-token: $TOKEN\" -v http://169.254.169.254/latest/meta-data/instance-id)" },
{ "Fn::Sub": "/opt/LinuxIdleTrackingInstallationScript.sh ${X64LinuxIdleCheckDownloadUrl} ${Arm64LinuxIdleCheckDownloadUrl} ${X64xprintIdleDownloadUrl} ${Arm64xprintIdleDownloadUrl} ${Version} ${AppEnabled} ${ShutdownOnIdle} ${ShutdownOnIdleTimeout} ${WarningWaitTimeout} ${TrackingMode} ${ShutdownOnDisconnect} ${ShutdownOnDisconnectTimeout} ${ShutdownWhenNoUsersConnected} ${ShutdownWhenNoUsersConnectedTimeout} ${AppCheckFrequency} $instanceId ${CloudLabsDeploymentIDEncrypt}" },
{ "Fn::Sub": "rm /opt/LinuxIdleTrackingInstallationScript.sh\nrm /opt/main.sh" }
]]
},
{ "Fn::Sub": "echo 'App Enabled is False'" }
]
}
Keep the installer arguments in this order; the script reads them by position. $TOKEN and $instanceId are bash variables set at boot.
Linux VM: parameters
Parameter | Value in parameter file | What it does |
|---|---|---|
AddToBashrcScriptUrl | AWS-ADD-TO-BASHRC-SCRIPT-URL | Script that sets up the user's bashrc for tracking |
IdleTrackingInstallationScriptUrl | AWS-LINUX-IDLETRACKING-INSTALLATION_SCRIPT-URL | Where the installer is downloaded from |
X64LinuxIdleCheckDownloadUrl | X64-LINUX-IDLECHECK-DOWNLOAD-URL | Idle-check agent for x64 VMs |
Arm64LinuxIdleCheckDownloadUrl | ARM64-LINUX-IDLECHECK-DOWNLOAD-URL | Idle-check agent for ARM64 VMs |
X64xprintIdleDownloadUrl | X64-XPRINTIDLE-DOWNLOAD-URL | xprintidle tool for x64 VMs |
Arm64xprintIdleDownloadUrl | ARM64-XPRINTIDLE-DOWNLOAD-URL | xprintidle tool for ARM64 VMs |
Version | GET-IDLE-TRACKING-VERSION | Tracker version |
AppEnabled | GET-ODL-ENABLE-ATTENDEE-TRACKING | Turns tracking on (True / False) |
OdlTrackingSource | GET-ODL-TRACKING-SOURCE | Must be 1 or 2, or the tracker is skipped |
ShutdownOnIdle | GET-ODL-ENABLE-SHUTDOWNONIDLE | Shut down when the user is idle |
ShutdownOnIdleTimeout | GET-ODL-SHUTDOWNONIDLE-TIMEOUT | Idle time before shutdown |
WarningWaitTimeout | GET-ODL-SHUTDOWNONIDLE-WARNINGWAITTIMEOUT | How long the idle warning waits |
TrackingMode | GET-ODL-SHUTDOWNONIDLE-TRACKINGMODE | Idle detection mode |
ShutdownOnDisconnect | GET-ODL-ENABLE-SHUTDOWNONDISCONNECT | Shut down after the session disconnects |
ShutdownOnDisconnectTimeout | GET-ODL-SHUTDOWNONDISCONNECT-TIMEOUT | Wait time after disconnect |
ShutdownWhenNoUsersConnected | GET-ODL-ENABLE-SHUTDOWNWHENNOUSERSCONNECTED | Shut down when nobody is signed in |
ShutdownWhenNoUsersConnectedTimeout | GET-ODL-SHUTDOWNWHENNOUSERSCONNECTED-TIMEOUT | Wait time with no users signed in |
AppCheckFrequency | 2 | How often the tracker checks |
CloudLabsDeploymentIDEncrypt | GET-DEPLOYMENT-ID-ENCRYPT | Links the VM to its deployment |
AppPopupWaitTimeout (10) is in the parameter file but is not passed to the installer.