Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update telemetry method #632

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The following is the unique IDs (also known as PIDs) used in each of the modules
| `Export-NonComplianceReports` | `f464b017-898b-4156-9da5-af932831fa2f` |
| `Get-AzExemptions` | `3f02e7d5-1cf5-490a-a95c-3d49f0673093` |
| `New-AzPolicyReaderRole` | `f4b5b7ac-70b4-40fc-836f-585791aa83e7` |
| `Sync-ALZPolicies` | `pid-a5e82cd0-9dda-417b-948c-68ec81596c32`|

## Support

Expand Down
13 changes: 13 additions & 0 deletions Scripts/CloudAdoptionFramework/Sync-ALZPolicies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ if ($DefinitionsRootFolder -eq "") {
}
}

try {
$telemetryEnabled = (Get-Content $DefinitionsRootFolder/global-settings.jsonc | ConvertFrom-Json).telemetryOptOut
$deploymentRootScope = (Get-Content $DefinitionsRootFolder/global-settings.jsonc | ConvertFrom-Json).pacEnvironments[0]
if (!($telemetryEnabled)) {
Write-Information "Telemetry is enabled"
Submit-EPACTelemetry -Cuapid "pid-a5e82cd0-9dda-417b-948c-68ec81596c32" -DeploymentRootScope $deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
}
}
catch {}

New-Item -Path "$DefinitionsRootFolder\policyDefinitions" -ItemType Directory -Force -ErrorAction SilentlyContinue
New-Item -Path "$DefinitionsRootFolder\policyDefinitions\ALZ" -ItemType Directory -Force -ErrorAction SilentlyContinue
New-Item -Path "$DefinitionsRootFolder\policySetDefinitions" -ItemType Directory -Force -ErrorAction SilentlyContinue
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Deploy/Build-DeploymentPlans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $null = Set-AzCloudTenantSubscription -Cloud $pacEnvironment.cloud -TenantId $pa
# Telemetry
if ($pacEnvironment.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-3c88f740-55a8-4a96-9fba-30a81b52151a")
Submit-EPACTelemetry -Cuapid "pid-3c88f740-55a8-4a96-9fba-30a81b52151a" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Deploy/Deploy-PolicyPlan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $null = Set-AzCloudTenantSubscription -Cloud $pacEnvironment.cloud -TenantId $pa
# Telemetry
if ($pacEnvironment.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-fe9ff1e8-5521-4b9d-ab1d-84e15447565e")
Submit-EPACTelemetry -Cuapid "pid-fe9ff1e8-5521-4b9d-ab1d-84e15447565e" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Deploy/Deploy-RolesPlan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $null = Set-AzCloudTenantSubscription -Cloud $pacEnvironment.cloud -TenantId $pa
# Telemetry
if ($pacEnvironment.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-cf031290-b7d4-48ef-9ff5-4dcd7bff8c6c")
Submit-EPACTelemetry -Cuapid "pid-cf031290-b7d4-48ef-9ff5-4dcd7bff8c6c" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
3 changes: 3 additions & 0 deletions Scripts/Helpers/Add-HelperScripts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@
. "$PSScriptRoot/Set-ExportNodeAncestors.ps1"
. "$PSScriptRoot/Set-UniqueRoleAssignmentScopes.ps1"


. "$PSScriptRoot/Split-ArrayIntoChunks.ps1"
. "$PSScriptRoot/Split-AzPolicyResourceId.ps1"
. "$PSScriptRoot/Split-HashtableIntoChunks.ps1"

. "$PSScriptRoot/Submit-EPACTelemetry.ps1"

. "$PSScriptRoot/Switch-PacEnvironment.ps1"

. "$PSScriptRoot/Write-AssignmentDetails.ps1"
Expand Down
18 changes: 18 additions & 0 deletions Scripts/Helpers/Submit-EPACTelemetry.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function Submit-EPACTelemetry {
[CmdletBinding()]
param(
[string]$Cuapid,
[string]$DeploymentRootScope
)
$method = "PUT"

# Note - all these calls are meant to fail - we can track the pid in the logs
if ($DeploymentRootScope -match "Microsoft.Management/managementgroups") {
$managementGroupId = $DeploymentRootScope.Split("/")[-1]
Invoke-AzRestMethod -Uri "https://management.azure.com/providers/Microsoft.Management/managementGroups/$($managementGroupId)/providers/Microsoft.Resources/deployments/$($Cuapid)?api-version=2021-04-01" -Method $method -ErrorAction SilentlyContinue -AsJob | Out-Null
}
elseif ($DeploymentRootScope -match "subscriptions") {
$subscriptionId = $DeploymentRootScope.Split("/")[-1]
Invoke-AzRestMethod -Uri "https://management.azure.com/subscriptions/$($subscriptionId)/providers/Microsoft.Resources/deployments/$($Cuapid)?api-version=2021-04-01" -Method $method -ErrorAction SilentlyContinue -AsJob | Out-Null
}
}
2 changes: 1 addition & 1 deletion Scripts/Operations/Build-PolicyDocumentation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (-not (Test-Path $outputPath)) {
# Telemetry
if ($globalSettings.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-2dc29bae-2448-4d7f-b911-418421e83900")
Submit-EPACTelemetry -Cuapid "pid-2dc29bae-2448-4d7f-b911-418421e83900" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Operations/Export-AzPolicyResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ $invalidChars += (":[]()$".ToCharArray())
# Telemetry
if ($globalSettings.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-dc5b73fd-e93c-40ca-8fef-976762d1d30")
Submit-EPACTelemetry -Cuapid "pid-dc5b73fd-e93c-40ca-8fef-976762d1d30" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Operations/Export-NonComplianceReports.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ $account = Set-AzCloudTenantSubscription -Cloud $pacEnvironment.cloud -TenantId
# Telemetry
if ($pacEnvironment.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-f464b017-898b-4156-9da5-af932831fa2f")
Submit-EPACTelemetry -Cuapid "pid-f464b017-898b-4156-9da5-af932831fa2f" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Operations/Get-AzExemptions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ $policyExemptionsFolder = "$($pacEnvironment.outputFolder)/policyExemptions"
# Telemetry
if ($pacEnvironment.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-3f02e7d5-1cf5-490a-a95c-3d49f0673093")
Submit-EPACTelemetry -Cuapid "pid-3f02e7d5-1cf5-490a-a95c-3d49f0673093" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Operations/New-AzPolicyReaderRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $null = Set-AzCloudTenantSubscription -Cloud $pacEnvironment.cloud -TenantId $pa
# Telemetry
if ($pacEnvironment.telemetryEnabled) {
Write-Information "Telemetry is enabled"
[Microsoft.Azure.Common.Authentication.AzureSession]::ClientFactory.AddUserAgent("pid-f4b5b7ac-70b4-40fc-836f-585791aa83e7")
Submit-EPACTelemetry -Cuapid "pid-f4b5b7ac-70b4-40fc-836f-585791aa83e7" -DeploymentRootScope $pacEnvironment.deploymentRootScope
}
else {
Write-Information "Telemetry is disabled"
Expand Down