Skip to content

Commit 1b7c61c

Browse files
updates html
1 parent 4176d85 commit 1b7c61c

File tree

5 files changed

+106
-101
lines changed

5 files changed

+106
-101
lines changed

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

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ function Write-StandardsAlert {
77
$object,
88
$tenant = 'None',
99
$standardName = 'None',
10-
$standardId = $null
10+
$standardId = $null,
11+
$message
1112
)
1213
$Table = Get-CIPPTable -tablename CippStandardsAlerts
1314
$JSONobject = $object | ConvertTo-Json -Depth 10 -Compress
@@ -16,11 +17,12 @@ function Write-StandardsAlert {
1617
'tenant' = [string]$tenant
1718
'standardName' = [string]$standardName
1819
'object' = [string]$JSONobject
20+
'message' = [string]$message
1921
'standardId' = [string]$standardId
2022
'sentAsAlert' = $false
2123
'PartitionKey' = [string]$PartitionKey
2224
'RowKey' = [string]([guid]::NewGuid()).ToString()
2325
}
2426
$Table.Entity = $TableRow
25-
Add-CIPPAzDataTableEntity @Table | Out-Null
27+
Add-CIPPAzDataTableEntity @Table -Force | Out-Null
2628
}

Modules/CIPPCore/Public/New-CIPPAlertTemplate.ps1

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ function New-CIPPAlertTemplate {
2828
$ButtonText = 'C heck logbook information'
2929
}
3030
if ($InputObject -eq 'standards') {
31-
#Edit to do nice compares, say which standard/tenant/template, etc etc. Make it a nice, easy, informative email per tenant.
32-
$DataHTML = $Data | Select-Object * -ExcludeProperty Etag, PartitionKey, TimeStamp | ConvertTo-Html | Out-String
33-
$IntroText = "<p>This is your standards email blabla, converted from json blabla.</p>$dataHTML"
31+
$DataHTML = foreach ($object in $data) {
32+
"<p>For the standard $($object.standardName) in template {{Template Name }} we've detected:</p> <li>$($object.message)</li>"
33+
if ($object.object) {
34+
$object.object = $object.object | ConvertFrom-Json
35+
$object.object = $object.object | Select-Object * -ExcludeProperty Etag, PartitionKey, TimeStamp
36+
($object.object.compare | ConvertTo-Html -Fragment | Out-String).Replace('<table>', ' <table class="table-modern">')
37+
}
38+
39+
}
40+
$IntroText = "<p>You're receiving this email because you've set your standards to alert when they are out of sync with your expected baseline.</p>$dataHTML"
3441
$ButtonUrl = "$CIPPURL/standards/list-standards"
3542
$ButtonText = 'Check Standards configuration'
3643
}
3744
if ($InputObject -eq 'auditlog') {
45+
$ButtonUrl = "$CIPPURL/identity/administration/users/user/bec?userId=$($data.ObjectId)&tenantFilter=$Tenant"
46+
$ButtonText = 'User Management'
47+
$AfterButtonText = '<p>If this is incorrect, use the user management screen to block the user and revoke the sessions</p>'
3848
switch ($Data.Operation) {
3949
'New-InboxRule' {
4050
# Test if the rule is a forwarding or redirect rule
@@ -225,6 +235,13 @@ function New-CIPPAlertTemplate {
225235
htmlcontent = $HTMLTemplate -f $Title, $IntroText, $ButtonUrl, $ButtonText, $AfterButtonText, $AuditLogLink
226236
}
227237
} elseif ($Format -eq 'json') {
238+
if ($InputObject -eq 'auditlog') {
239+
return [pscustomobject]@{
240+
title = $Title
241+
html = $IntroText
242+
data = $data
243+
}
244+
}
228245
return [pscustomobject]@{
229246
title = $Title
230247
buttonurl = $ButtonUrl

Modules/CIPPCore/Public/Standards/Invoke-CIPPStandardIntuneTemplate.ps1

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ function Invoke-CIPPStandardIntuneTemplate {
3535
$Table = Get-CippTable -tablename 'templates'
3636
$Filter = "PartitionKey eq 'IntuneTemplate'"
3737
$Request = @{body = $null }
38-
$TenantList = Get-Tenants -TenantFilter $tenantFilter
3938

4039
$CompareList = foreach ($Template in $Settings) {
4140
Write-Host "working on template: $($Template | ConvertTo-Json)"
@@ -50,37 +49,36 @@ function Invoke-CIPPStandardIntuneTemplate {
5049
$ExistingPolicy = Get-CIPPIntunePolicy -tenantFilter $Tenant -DisplayName $displayname -TemplateType $Request.body.Type
5150
if ($ExistingPolicy) {
5251
$RawJSON = Get-CIPPTextReplacement -Text $RawJSON -TenantFilter $Tenant
53-
5452
$JSONExistingPolicy = $ExistingPolicy.cippconfiguration | ConvertFrom-Json
5553
$JSONTemplate = $RawJSON | ConvertFrom-Json
5654
$Compare = Compare-CIPPIntuneObject -ReferenceObject $JSONTemplate -DifferenceObject $JSONExistingPolicy -compareType $Request.body.Type
57-
if ($Compare) {
58-
[PSCustomObject]@{
59-
MatchFailed = $true
60-
displayname = $displayname
61-
description = $description
62-
compare = $Compare
63-
rawJSON = $RawJSON
64-
body = $Request.body
65-
assignTo = $Template.AssignTo
66-
excludeGroup = $Template.excludeGroup
67-
remediate = $Template.remediate
68-
existingPolicyId = $ExistingPolicy.id
69-
}
70-
} else {
71-
[PSCustomObject]@{
72-
MatchFailed = $false
73-
displayname = $displayname
74-
description = $description
75-
compare = $Compare
76-
rawJSON = $RawJSON
77-
body = $Request.body
78-
assignTo = $Template.AssignTo
79-
excludeGroup = $Template.excludeGroup
80-
remediate = $Template.remediate
81-
existingPolicyId = $ExistingPolicy.id
55+
}
56+
if ($Compare) {
57+
[PSCustomObject]@{
58+
MatchFailed = $true
59+
displayname = $displayname
60+
description = $description
61+
compare = $Compare
62+
rawJSON = $RawJSON
63+
body = $Request.body
64+
assignTo = $Template.AssignTo
65+
excludeGroup = $Template.excludeGroup
66+
remediate = $Template.remediate
67+
existingPolicyId = $ExistingPolicy.id
68+
}
69+
} else {
70+
[PSCustomObject]@{
71+
MatchFailed = $false
72+
displayname = $displayname
73+
description = $description
74+
compare = $Compare
75+
rawJSON = $RawJSON
76+
body = $Request.body
77+
assignTo = $Template.AssignTo
78+
excludeGroup = $Template.excludeGroup
79+
remediate = $Template.remediate
80+
existingPolicyId = $ExistingPolicy.id
8281

83-
}
8482
}
8583
}
8684
}
@@ -104,13 +102,13 @@ function Invoke-CIPPStandardIntuneTemplate {
104102
foreach ($Template in $CompareList) {
105103
$AlertObj = $Template | Select-Object -Property displayname, description, compare, assignTo, excludeGroup, existingPolicyId
106104
if ($Template.compare) {
107-
Write-StandardsAlert -object $AlertObj -tenant $Tenant -standardName 'IntuneTemplate' -standardId $Settings.templateId
105+
Write-StandardsAlert -message "Template $($Template.displayname) does not match the expected configuration." -object $AlertObj -tenant $Tenant -standardName 'IntuneTemplate' -standardId $Settings.templateId
108106
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Template $($Template.displayname) does not match the expected configuration. We've generated an alert" -sev info
109107
} else {
110108
if ($Template.ExistingPolicyId) {
111109
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Template $($Template.displayname) has the correct configuration." -sev Info
112110
} else {
113-
Write-StandardsAlert -object $AlertObj -tenant $Tenant -standardName 'IntuneTemplate' -standardId $Settings.templateId
111+
Write-StandardsAlert -message "Template $($Template.displayname) is missing." -object $AlertObj -tenant $Tenant -standardName 'IntuneTemplate' -standardId $Settings.templateId
114112
Write-LogMessage -API 'Standards' -tenant $Tenant -message "Template $($Template.displayname) is missing." -sev info
115113
}
116114
}

TemplateEmail.html

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@
369369
color: #54595f;
370370
"
371371
>
372-
<p style="margin: 5px 0">Webhook received.</p>
373372
<p style="margin: 5px 0">{1}</p>
374373
</div>
375374
</td>
@@ -429,42 +428,7 @@
429428
{3}
430429
</a>
431430
</td>
432-
<td
433-
align="center"
434-
bgcolor="#54595f"
435-
role="presentation"
436-
style="
437-
border: none;
438-
border-radius: 30px;
439-
cursor: auto;
440-
mso-padding-alt: 10px 25px;
441-
background: #54595f;
442-
"
443-
valign="middle"
444-
>
445-
<a
446-
href="{5}"
447-
style="
448-
display: inline-block;
449-
background: #54595f;
450-
color: white;
451-
font-family: Nunito, Helvetica, Arial,
452-
sans-serif;
453-
font-size: 16px;
454-
font-weight: normal;
455-
line-height: 30px;
456-
margin: 0;
457-
text-decoration: none;
458-
text-transform: none;
459-
padding: 10px 25px;
460-
mso-padding-alt: 0px;
461-
border-radius: 30px;
462-
"
463-
target="_blank"
464-
>
465-
View Audit Log
466-
</a>
467-
</td>
431+
468432
</tr>
469433
</tbody>
470434
</table>

0 commit comments

Comments
 (0)