Skip to content

Commit d2aac3e

Browse files
committed
log alerting tweaks
1 parent 04ce9f6 commit d2aac3e

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-SchedulerCIPPNotifications.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Push-SchedulerCIPPNotifications {
2525
$PartitionKey = Get-Date -UFormat '%Y%m%d'
2626
$Filter = "PartitionKey eq '{0}'" -f $PartitionKey
2727
$Currentlog = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object {
28-
$_.API -in $Settings -and $_.SentAsAlert -ne $true -and $_.Severity -in $severity
28+
$_.API -in $Settings -and $_.sentAsAlert -ne $true -and $_.Severity -in $severity
2929
}
3030
$StandardsTable = Get-CIPPTable -tablename CippStandardsAlerts
3131
$CurrentStandardsLogs = Get-CIPPAzDataTableEntity @StandardsTable -Filter $Filter | Where-Object {
@@ -50,12 +50,34 @@ function Push-SchedulerCIPPNotifications {
5050
$Subject = "$($Tenant): CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))"
5151
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'table' -CIPPURL $CIPPURL
5252
Send-CIPPAlert -Type 'email' -Title $Subject -HTMLContent $HTMLContent.htmlcontent -TenantFilter $tenant -APIName 'Alerts'
53+
$UpdateLogs = $CurrentLog | ForEach-Object {
54+
if ($_.PSObject.Properties.Name -contains 'sentAsAlert') {
55+
$_.sentAsAlert = $true
56+
} else {
57+
$_ | Add-Member -MemberType NoteProperty -Name sentAsAlert -Value $true -Force
58+
}
59+
$_
60+
}
61+
if ($UpdateLogs) {
62+
Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force
63+
}
5364
}
5465
} else {
5566
$Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity)
5667
$Subject = "CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))"
5768
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'table' -CIPPURL $CIPPURL
5869
Send-CIPPAlert -Type 'email' -Title $Subject -HTMLContent $HTMLContent.htmlcontent -TenantFilter $tenant -APIName 'Alerts'
70+
$UpdateLogs = $CurrentLog | ForEach-Object {
71+
if ($_.PSObject.Properties.Name -contains 'sentAsAlert') {
72+
$_.sentAsAlert = $true
73+
} else {
74+
$_ | Add-Member -MemberType NoteProperty -Name sentAsAlert -Value $true -Force
75+
}
76+
$_
77+
}
78+
if ($UpdateLogs) {
79+
Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force
80+
}
5981
}
6082
}
6183
if ($CurrentStandardsLogs) {
@@ -88,7 +110,7 @@ function Push-SchedulerCIPPNotifications {
88110
if ($Currentlog) {
89111
$JSONContent = $Currentlog | ConvertTo-Json -Compress
90112
Send-CIPPAlert -Type 'webhook' -JSONContent $JSONContent -TenantFilter $Tenant -APIName 'Alerts'
91-
$UpdateLogs = $CurrentLog | ForEach-Object { $_.SentAsAlert = $true; $_ }
113+
$UpdateLogs = $CurrentLog | ForEach-Object { $_.sentAsAlert = $true; $_ }
92114
if ($UpdateLogs) { Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force }
93115
}
94116

Modules/CIPPCore/Public/GraphHelper/Write-LogMessage.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ function Write-LogMessage {
33
.FUNCTIONALITY
44
Internal
55
#>
6-
Param(
6+
param(
77
$message,
88
$tenant = 'None',
99
$API = 'None',
@@ -51,7 +51,7 @@ function Write-LogMessage {
5151
'Message' = [string]$message
5252
'Username' = [string]$username
5353
'Severity' = [string]$sev
54-
'SentAsAlert' = $false
54+
'sentAsAlert' = $false
5555
'PartitionKey' = [string]$PartitionKey
5656
'RowKey' = [string]([guid]::NewGuid()).ToString()
5757
'FunctionNode' = [string]$env:WEBSITE_SITE_NAME

0 commit comments

Comments
 (0)