Skip to content

Commit 5fc9a6d

Browse files
committed
Feat: Add TERRL status scripted alert
1 parent 5b29480 commit 5fc9a6d

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Get-CIPPAlertTERRL {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
Param (
8+
[Parameter(Mandatory = $false)]
9+
[Alias('input')]
10+
$InputValue,
11+
$TenantFilter
12+
)
13+
14+
try {
15+
# Set threshold with fallback to 80%
16+
$Threshold = if ([string]::IsNullOrWhiteSpace($InputValue)) { 80 } else { [int]$InputValue }
17+
18+
# Get TERRL status
19+
$TerrlStatus = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-LimitsEnforcementStatus'
20+
21+
if ($TerrlStatus) {
22+
$UsagePercentage = [math]::Round(($TerrlStatus.ObservedValue / $TerrlStatus.Threshold) * 100, 2)
23+
24+
if ($UsagePercentage -gt $Threshold) {
25+
$AlertData = [PSCustomObject]@{
26+
UsagePercentage = $UsagePercentage
27+
CurrentVolume = $TerrlStatus.ObservedValue
28+
ThresholdLimit = $TerrlStatus.Threshold
29+
EnforcementEnabled = $TerrlStatus.EnforcementEnabled
30+
Verdict = $TerrlStatus.Verdict
31+
Message = 'Tenant is at {0}% of their TERRL limit (using {1} of {2} messages). Tenant Enforcement Status: {3}' -f $UsagePercentage, $TerrlStatus.ObservedValue, $TerrlStatus.Threshold, $TerrlStatus.Verdict
32+
}
33+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $AlertData
34+
}
35+
}
36+
} catch {
37+
Write-AlertMessage -tenant $($TenantFilter) -message "Could not get TERRL status for $($TenantFilter): $(Get-NormalizedError -message $_.Exception.message)"
38+
}
39+
}

0 commit comments

Comments
 (0)