@@ -27,22 +27,40 @@ function Push-SchedulerCIPPNotifications {
27
27
$Currentlog = Get-CIPPAzDataTableEntity @Table - Filter $Filter | Where-Object {
28
28
$_.API -In $Settings -and $_.SentAsAlert -ne $true -and $_.Severity -In $severity
29
29
}
30
+ $StandardsTable = Get-CIPPTable - tablename CippStandardsAlerts
31
+ $CurrentStandardsLogs = Get-CIPPAzDataTableEntity @StandardsTable - Filter $Filter | Where-Object {
32
+ $_.SentAsAlert -ne $true
33
+ }
30
34
Write-Information " Alerts: $ ( $Currentlog.count ) found"
35
+ Write-Information " Standards: $ ( $CurrentStandardsLogs.count ) found"
31
36
# email try
32
37
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 )) "
38
51
$HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' table'
39
52
Send-CIPPAlert - Type ' email' - Title $Subject - HTMLContent $HTMLContent.htmlcontent - TenantFilter $tenant - APIName ' Alerts'
40
53
}
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
+ }
46
64
}
47
65
}
48
66
} catch {
@@ -53,17 +71,22 @@ function Push-SchedulerCIPPNotifications {
53
71
try {
54
72
Write-Information $ ($config | ConvertTo-Json )
55
73
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
+ }
60
89
61
- $UpdateLogs = $CurrentLog | ForEach-Object {
62
- $_.SentAsAlert = $true
63
- $_
64
- }
65
- if ($UpdateLogs ) {
66
- Add-CIPPAzDataTableEntity @Table - Entity $UpdateLogs - Force
67
90
}
68
91
} catch {
69
92
Write-Information " Could not send alerts to webhook $ ( $config.webhook ) : $ ( $_.Exception.message ) "
@@ -77,20 +100,21 @@ function Push-SchedulerCIPPNotifications {
77
100
$HTMLContent = New-CIPPAlertTemplate - Data $Data - Format ' html' - InputObject ' table'
78
101
$Title = " $tenant CIPP Alert: Alerts found starting at $ ( (Get-Date ).AddMinutes(-15 )) "
79
102
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 }
88
113
}
89
114
} catch {
90
115
Write-Information " Could not send alerts to ticketing system: $ ( $_.Exception.message ) "
91
116
Write-LogMessage - API ' Alerts' - tenant $Tenant - message " Could not send alerts to ticketing system: $ ( $_.Exception.message ) " - sev Error
92
117
}
93
118
}
94
119
95
-
96
120
}
0 commit comments