Skip to content

Commit a938c36

Browse files
committed
feat: add more stats props
1 parent 5153adc commit a938c36

4 files changed

Lines changed: 153 additions & 22 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-CIPPStatsTimer.ps1

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function Start-CIPPStatsTimer {
55
#>
66
[CmdletBinding(SupportsShouldProcess = $true)]
77
param()
8+
89
#These stats are sent to a central server to help us understand how many tenants are using the product, and how many are using the latest version, this information allows the CIPP team to make decisions about what features to support, and what features to deprecate.
910

1011

@@ -31,6 +32,7 @@ function Start-CIPPStatsTimer {
3132
$FunctionOffloading = (Get-CIPPAzDataTableEntity @ConfigTable -Filter "RowKey eq 'OffloadFunctions' and PartitionKey eq 'OffloadFunctions'").state
3233
$OffloadingEnabled = $false
3334
[bool]::TryParse($FunctionOffloading, [ref]$OffloadingEnabled) | Out-Null
35+
$CIPPNG = $env:CIPPNG -eq 'true'
3436

3537
# Get counts of various entities across all tenants
3638
$counts = Get-CIPPDbItem -TenantFilter AllTenants -CountsOnly
@@ -39,30 +41,42 @@ function Start-CIPPStatsTimer {
3941
$groupsCount = ($counts | Where-Object { $_.RowKey -eq 'Groups-Count' } | Measure-Object -Property DataCount -Sum).Sum
4042
$managedDevicesCount = ($counts | Where-Object { $_.RowKey -eq 'ManagedDevices-Count' } | Measure-Object -Property DataCount -Sum).Sum
4143
$policyCount = ($counts | Where-Object { $_.RowKey -match 'Intune' -and $_.RowKey -match 'Policies|Policy' } | Measure-Object -Property DataCount -Sum).Sum
44+
$deployedApps = ($counts | Where-Object { $_.RowKey -eq 'IntuneApplications-Count' } | Measure-Object -Property DataCount -Sum).Sum
45+
$ReportsTable = Get-CippTable -tablename 'ReportBuilderTemplates'
46+
$CustomReportCount = (Get-CIPPAzDataTableEntity @ReportsTable -Filter "PartitionKey eq 'ReportBuilderTemplates'").count
47+
$uniqueStandardsApplied = Get-CIPPStatsUniqueStandardsApplied
48+
$driftStandardsCount = Get-CIPPStatsDriftStandardsCount
49+
$mobileEnrollment = Get-CIPPStatsMobileEnrollment
4250

4351
$SendingObject = [PSCustomObject]@{
44-
rgid = $env:WEBSITE_SITE_NAME
45-
SetupComplete = $SetupComplete
46-
Hosted = $env:CIPP_HOSTED -eq 'true'
47-
OffloadingEnabled = $OffloadingEnabled
48-
RunningVersionAPI = $APIVersion.trim()
49-
CountOfTotalTenants = $TenantCount
50-
uid = $env:TenantID
51-
UserCount = $userCount
52-
DeviceCount = $deviceCount
53-
GroupsCount = $groupsCount
54-
ManagedDevicesCount = $managedDevicesCount
55-
PolicyCount = $policyCount
56-
CIPPAPI = $RawExt.CIPPAPI.Enabled
57-
Hudu = $RawExt.Hudu.Enabled
58-
Sherweb = $RawExt.Sherweb.Enabled
59-
Gradient = $RawExt.Gradient.Enabled
60-
NinjaOne = $RawExt.NinjaOne.Enabled
61-
haloPSA = $RawExt.haloPSA.Enabled
62-
HIBP = $RawExt.HIBP.Enabled
63-
PWPush = $RawExt.PWPush.Enabled
64-
CFZTNA = $RawExt.CFZTNA.Enabled
65-
GitHub = $RawExt.GitHub.Enabled
52+
rgid = $env:WEBSITE_SITE_NAME
53+
SetupComplete = $SetupComplete
54+
Hosted = $env:CIPP_HOSTED -eq 'true'
55+
CIPPNG = $CIPPNG
56+
OffloadingEnabled = $OffloadingEnabled
57+
RunningVersionAPI = $APIVersion.trim()
58+
CountOfTotalTenants = $TenantCount
59+
uid = $env:TenantID
60+
UserCount = $userCount
61+
DeviceCount = $deviceCount
62+
GroupsCount = $groupsCount
63+
ManagedDevicesCount = $managedDevicesCount
64+
PolicyCount = $policyCount
65+
UniqueStandardsApplied = $uniqueStandardsApplied
66+
DriftStandardsCount = $driftStandardsCount
67+
MobileEnrollment = $mobileEnrollment
68+
DeployedApps = $deployedApps
69+
CustomReportCount = $CustomReportCount
70+
CIPPAPI = $RawExt.CIPPAPI.Enabled
71+
Hudu = $RawExt.Hudu.Enabled
72+
Sherweb = $RawExt.Sherweb.Enabled
73+
Gradient = $RawExt.Gradient.Enabled
74+
NinjaOne = $RawExt.NinjaOne.Enabled
75+
haloPSA = $RawExt.haloPSA.Enabled
76+
HIBP = $RawExt.HIBP.Enabled
77+
PWPush = $RawExt.PWPush.Enabled
78+
CFZTNA = $RawExt.CFZTNA.Enabled
79+
GitHub = $RawExt.GitHub.Enabled
6680
} | ConvertTo-Json
6781

6882
try {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function Get-CIPPStatsDriftStandardsCount {
2+
[CmdletBinding()]
3+
param()
4+
5+
try {
6+
$Standards = @(Get-CIPPStandards -TenantFilter allTenants)
7+
$TemplateTable = Get-CippTable -tablename 'templates'
8+
$TemplateRows = @(Get-CIPPAzDataTableEntity @TemplateTable -Filter "PartitionKey eq 'StandardsTemplateV2'")
9+
10+
$TemplateTypeByGuid = @{}
11+
foreach ($TemplateRow in $TemplateRows) {
12+
if ([string]::IsNullOrWhiteSpace($TemplateRow.JSON)) { continue }
13+
14+
try {
15+
$TemplateData = $TemplateRow.JSON | ConvertFrom-Json -Depth 30 -ErrorAction Stop
16+
} catch {
17+
continue
18+
}
19+
20+
$TemplateGuid = [string]($TemplateData.GUID ?? $TemplateRow.GUID)
21+
if ([string]::IsNullOrWhiteSpace($TemplateGuid)) { continue }
22+
23+
$TemplateTypeByGuid[$TemplateGuid] = [string]$TemplateData.type
24+
}
25+
26+
$DriftStandardIds = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
27+
foreach ($Standard in $Standards) {
28+
if ([string]::IsNullOrWhiteSpace($Standard.TemplateId)) { continue }
29+
if ([string]::IsNullOrWhiteSpace($Standard.Standard)) { continue }
30+
if (-not $TemplateTypeByGuid.ContainsKey([string]$Standard.TemplateId)) { continue }
31+
if ($TemplateTypeByGuid[[string]$Standard.TemplateId] -ne 'drift') { continue }
32+
33+
$TemplateValue = $null
34+
if ($Standard.Settings -and $Standard.Settings.PSObject.Properties['TemplateList']) {
35+
if ($Standard.Settings.TemplateList -and $Standard.Settings.TemplateList.PSObject.Properties['value']) {
36+
$TemplateValue = [string]$Standard.Settings.TemplateList.value
37+
}
38+
}
39+
40+
$Id = if ([string]::IsNullOrWhiteSpace($TemplateValue)) {
41+
[string]$Standard.Standard
42+
} else {
43+
"{0}|{1}" -f $Standard.Standard, $TemplateValue
44+
}
45+
46+
if ([string]::IsNullOrWhiteSpace($Id)) { continue }
47+
[void]$DriftStandardIds.Add($Id)
48+
}
49+
50+
return $DriftStandardIds.Count
51+
} catch {
52+
Write-LogMessage -API 'CIPPStatsTimer' -tenant $env:TenantID -message "Failed to calculate DriftStandardsCount: $($_.Exception.Message)" -sev Warning
53+
return 0
54+
}
55+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function Get-CIPPStatsMobileEnrollment {
2+
[CmdletBinding()]
3+
param()
4+
5+
try {
6+
$MobileEnrollment = 0
7+
$ManagedDeviceRows = Get-CIPPDbItem -TenantFilter allTenants -Type 'ManagedDevices'
8+
foreach ($ManagedDeviceRow in $ManagedDeviceRows) {
9+
if (-not $ManagedDeviceRow.Data) { continue }
10+
11+
try {
12+
$ManagedDevice = $ManagedDeviceRow.Data | ConvertFrom-Json -Depth 20 -ErrorAction Stop
13+
} catch {
14+
continue
15+
}
16+
17+
$OperatingSystem = [string]$ManagedDevice.operatingSystem
18+
if ($OperatingSystem -match 'iOS|iPadOS|Android') {
19+
$MobileEnrollment++
20+
}
21+
}
22+
23+
return $MobileEnrollment
24+
} catch {
25+
Write-LogMessage -API 'CIPPStatsTimer' -tenant $env:TenantID -message "Failed to calculate MobileEnrollment: $($_.Exception.Message)" -sev Warning
26+
return 0
27+
}
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function Get-CIPPStatsUniqueStandardsApplied {
2+
[CmdletBinding()]
3+
param()
4+
5+
try {
6+
$Standards = @(Get-CIPPStandards -TenantFilter allTenants)
7+
$DistinctStandards = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
8+
9+
foreach ($Standard in $Standards) {
10+
if (-not $Standard.Standard) { continue }
11+
12+
$TemplateValue = $null
13+
if ($Standard.Settings -and $Standard.Settings.PSObject.Properties['TemplateList']) {
14+
if ($Standard.Settings.TemplateList -and $Standard.Settings.TemplateList.PSObject.Properties['value']) {
15+
$TemplateValue = [string]$Standard.Settings.TemplateList.value
16+
}
17+
}
18+
19+
$Id = if ([string]::IsNullOrWhiteSpace($TemplateValue)) {
20+
[string]$Standard.Standard
21+
} else {
22+
"{0}|{1}" -f $Standard.Standard, $TemplateValue
23+
}
24+
25+
if ([string]::IsNullOrWhiteSpace($Id)) { continue }
26+
[void]$DistinctStandards.Add($Id)
27+
}
28+
29+
return $DistinctStandards.Count
30+
} catch {
31+
Write-LogMessage -API 'CIPPStatsTimer' -tenant $env:TenantID -message "Failed to calculate UniqueStandardsApplied: $($_.Exception.Message)" -sev Warning
32+
return 0
33+
}
34+
}

0 commit comments

Comments
 (0)