@@ -27,22 +27,40 @@ function Push-SchedulerCIPPNotifications {
2727 $Currentlog = Get-CIPPAzDataTableEntity @Table - Filter $Filter | Where-Object {
2828 $_.API -In $Settings -and $_.SentAsAlert -ne $true -and $_.Severity -In $severity
2929 }
30+ $StandardsTable = Get-CIPPTable - tablename CippStandardsAlerts
31+ $CurrentStandardsLogs = Get-CIPPAzDataTableEntity @StandardsTable - Filter $Filter | Where-Object {
32+ $_.SentAsAlert -ne $true
33+ }
3034 Write-Information " Alerts: $ ( $Currentlog.count ) found"
35+ Write-Information " Standards: $ ( $CurrentStandardsLogs.count ) found"
3136 # email try
3237 try {
33- if ($Config.email -like ' *@*' -and $null -ne $CurrentLog ) {
34- if ($config.onePerTenant ) {
35- foreach ($tenant in ($CurrentLog.Tenant | Sort-Object - Unique)) {
36- $Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object - Property tenant -EQ $tenant )
37- $Subject = " $ ( $Tenant ) : CIPP Alert: Alerts found starting at $ ( (Get-Date ).AddMinutes(-15 )) "
38+ if ($Config.email -like ' *@*' ) {
39+ # Normal logs
40+ if ($Currentlog ) {
41+ if ($config.onePerTenant ) {
42+ foreach ($tenant in ($CurrentLog.Tenant | Sort-Object - Unique)) {
43+ $Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object - Property tenant -EQ $tenant )
44+ $Subject = " $ ( $Tenant ) : CIPP Alert: Alerts found starting at $ ( (Get-Date ).AddMinutes(-15 )) "
45+ $HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' table'
46+ Send-CIPPAlert - Type ' email' - Title $Subject - HTMLContent $HTMLContent.htmlcontent - TenantFilter $tenant - APIName ' Alerts'
47+ }
48+ } else {
49+ $Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | ConvertTo-Html - frag)
50+ $Subject = " CIPP Alert: Alerts found starting at $ ( (Get-Date ).AddMinutes(-15 )) "
3851 $HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' table'
3952 Send-CIPPAlert - Type ' email' - Title $Subject - HTMLContent $HTMLContent.htmlcontent - TenantFilter $tenant - APIName ' Alerts'
4053 }
41- } else {
42- $Data = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | ConvertTo-Html - frag)
43- $Subject = " CIPP Alert: Alerts found starting at $ ( (Get-Date ).AddMinutes(-15 )) "
44- $HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' table'
45- Send-CIPPAlert - Type ' email' - Title $Subject - HTMLContent $HTMLContent.htmlcontent - TenantFilter $tenant - APIName ' Alerts'
54+ }
55+ if ($CurrentStandardsLogs ) {
56+ foreach ($tenant in ($CurrentLog.Tenant | Sort-Object - Unique)) {
57+ $Data = ($CurrentStandardsLogs | Where-Object - Property tenant -EQ $tenant )
58+ $Subject = " $ ( $Tenant ) : Standards are out of sync for $tenant "
59+ $HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' standards'
60+ Send-CIPPAlert - Type ' email' - Title $Subject - HTMLContent $HTMLContent.htmlcontent - TenantFilter $tenant - APIName ' Alerts'
61+ $updateStandards = $CurrentStandardsLogs | ForEach-Object { $_.SentAsAlert = $true ; $_ }
62+ if ($updateStandards ) { Add-CIPPAzDataTableEntity @StandardsTable - Entity $updateStandards - Force }
63+ }
4664 }
4765 }
4866 } catch {
@@ -53,17 +71,22 @@ function Push-SchedulerCIPPNotifications {
5371 try {
5472 Write-Information $ ($config | ConvertTo-Json )
5573 Write-Information $config.webhook
56- if ($Config.webhook -ne ' ' -and $null -ne $CurrentLog ) {
57- $JSONContent = $Currentlog | ConvertTo-Json - Compress
58- Send-CIPPAlert - Type ' webhook' - JSONContent $JSONContent - TenantFilter $Tenant - APIName ' Alerts'
59- }
74+ if ($Config.webhook -ne ' ' -and $null ) {
75+ if ($Currentlog ) {
76+ $JSONContent = $Currentlog | ConvertTo-Json - Compress
77+ Send-CIPPAlert - Type ' webhook' - JSONContent $JSONContent - TenantFilter $Tenant - APIName ' Alerts'
78+ $UpdateLogs = $CurrentLog | ForEach-Object { $_.SentAsAlert = $true ; $_ }
79+ if ($UpdateLogs ) { Add-CIPPAzDataTableEntity @Table - Entity $UpdateLogs - Force }
80+ }
81+
82+ if ($CurrentStandardsLogs ) {
83+ $JSONContent = New-CIPPAlertTemplate - Data $Data - Format ' json' - InputObject ' table'
84+ $CurrentStandardsLogs | ConvertTo-Json - Compress
85+ Send-CIPPAlert - Type ' webhook' - JSONContent $JSONContent - TenantFilter $Tenant - APIName ' Alerts'
86+ $updateStandards = $CurrentStandardsLogs | ForEach-Object { $_.SentAsAlert = $true ; $_ }
87+ if ($updateStandards ) { Add-CIPPAzDataTableEntity @StandardsTable - Entity $updateStandards - Force }
88+ }
6089
61- $UpdateLogs = $CurrentLog | ForEach-Object {
62- $_.SentAsAlert = $true
63- $_
64- }
65- if ($UpdateLogs ) {
66- Add-CIPPAzDataTableEntity @Table - Entity $UpdateLogs - Force
6790 }
6891 } catch {
6992 Write-Information " Could not send alerts to webhook $ ( $config.webhook ) : $ ( $_.Exception.message ) "
@@ -77,20 +100,21 @@ function Push-SchedulerCIPPNotifications {
77100 $HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' table'
78101 $Title = " $tenant CIPP Alert: Alerts found starting at $ ( (Get-Date ).AddMinutes(-15 )) "
79102 Send-CIPPAlert - Type ' psa' - Title $Title - HTMLContent $HTMLContent.htmlcontent - TenantFilter $tenant - APIName ' Alerts'
80-
81- $UpdateLogs = $CurrentLog | ForEach-Object {
82- $_.SentAsAlert = $true
83- $_
84- }
85- if ($UpdateLogs ) {
86- Add-CIPPAzDataTableEntity @Table - Entity $UpdateLogs - Force
87- }
103+ $UpdateLogs = $CurrentLog | ForEach-Object { $_.SentAsAlert = $true ; $_ }
104+ if ($UpdateLogs ) { Add-CIPPAzDataTableEntity @Table - Entity $UpdateLogs - Force }
105+ }
106+ foreach ($standardsTenant in ($CurrentStandardsLogs.Tenant | Sort-Object - Unique)) {
107+ $Data = ($CurrentStandardsLogs | Where-Object - Property tenant -EQ $standardsTenant )
108+ $Subject = " $ ( $standardsTenant ) : Standards are out of sync for $standardsTenant "
109+ $HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' standards'
110+ Send-CIPPAlert - Type ' psa' - Title $Subject - HTMLContent $HTMLContent.htmlcontent - TenantFilter $standardsTenant - APIName ' Alerts'
111+ $updateStandards = $CurrentStandardsLogs | ForEach-Object { $_.SentAsAlert = $true ; $_ }
112+ if ($updateStandards ) { Add-CIPPAzDataTableEntity @StandardsTable - Entity $updateStandards - Force }
88113 }
89114 } catch {
90115 Write-Information " Could not send alerts to ticketing system: $ ( $_.Exception.message ) "
91116 Write-LogMessage - API ' Alerts' - tenant $Tenant - message " Could not send alerts to ticketing system: $ ( $_.Exception.message ) " - sev Error
92117 }
93118 }
94119
95-
96120}
0 commit comments