Skip to content

Commit 79fd452

Browse files
authored
Merge pull request #501 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 4c2143f + 9b14648 commit 79fd452

File tree

12 files changed

+99
-21
lines changed

12 files changed

+99
-21
lines changed

Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ function Add-CIPPScheduledTask {
184184
AdditionalProperties = [string]$AdditionalProperties
185185
Hidden = [bool]$Hidden
186186
Results = 'Planned'
187+
AlertComment = [string]$task.AlertComment
187188
}
188189
# Always store DesiredStartTime if provided
189190
if ($DesiredStartTime) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Get-CIPPAlertMXRecordChanged {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
param (
8+
[Parameter(Mandatory)]
9+
$TenantFilter,
10+
[Alias('input')]
11+
$InputValue
12+
)
13+
14+
try {
15+
$DomainData = Get-CIPPDomainAnalyser -TenantFilter $TenantFilter
16+
$CacheTable = Get-CippTable -tablename 'CacheMxRecords'
17+
$PreviousResults = Get-CIPPAzDataTableEntity @CacheTable -Filter "PartitionKey eq '$TenantFilter'"
18+
19+
$ChangedDomains = foreach ($Domain in $DomainData) {
20+
$PreviousDomain = $PreviousResults | Where-Object { $_.Domain -eq $Domain.Domain }
21+
if ($PreviousDomain -and $PreviousDomain.ActualMXRecords -ne $Domain.ActualMXRecords) {
22+
"$($Domain.Domain): MX records changed from [$($PreviousDomain.ActualMXRecords -join ', ')] to [$($Domain.ActualMXRecords -join ', ')]"
23+
}
24+
}
25+
26+
if ($ChangedDomains) {
27+
Write-AlertTrace -cmdletName $MyInvocation.MyCommand -tenantFilter $TenantFilter -data $ChangedDomains
28+
}
29+
30+
# Update cache with current data
31+
foreach ($Domain in $DomainData) {
32+
$CacheEntity = @{
33+
PartitionKey = $TenantFilter
34+
RowKey = $Domain.Domain
35+
Domain = $Domain.Domain
36+
ActualMXRecords = $Domain.ActualMXRecords
37+
LastRefresh = $Domain.LastRefresh
38+
MailProvider = $Domain.MailProvider
39+
}
40+
Add-CIPPAzDataTableEntity @CacheTable -Entity $CacheEntity -Force
41+
}
42+
} catch {
43+
Write-LogMessage -message "Failed to check MX record changes: $($_.Exception.Message)" -API 'MX Record Alert' -tenant $TenantFilter -sev Error
44+
}
45+
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Applications/Push-UploadApplication.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function Push-UploadApplication {
6464

6565
foreach ($tenant in $tenants) {
6666
try {
67-
$ApplicationList = (New-GraphGetRequest -Uri $baseuri -tenantid $tenant) | Where-Object { $_.DisplayName -eq $ChocoApp.Applicationname }
67+
$ApplicationList = New-GraphGetRequest -Uri $baseuri -tenantid $tenant | Where-Object { $_.DisplayName -eq $ChocoApp.Applicationname -and ($_.'@odata.type' -eq '#microsoft.graph.win32LobApp' -or $_.'@odata.type' -eq '#microsoft.graph.winGetApp') }
6868
if ($ApplicationList.displayname.count -ge 1) {
6969
Write-LogMessage -api 'AppUpload' -tenant $tenant -message "$($ChocoApp.Applicationname) exists. Skipping this application" -Sev 'Info'
7070
continue

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ function Push-ExecScheduledCommand {
147147
$TableDesign = '<style>table.blueTable{border:1px solid #1C6EA4;background-color:#EEE;width:100%;text-align:left;border-collapse:collapse}table.blueTable td,table.blueTable th{border:1px solid #AAA;padding:3px 2px}table.blueTable tbody td{font-size:13px}table.blueTable tr:nth-child(even){background:#D0E4F5}table.blueTable thead{background:#1C6EA4;background:-moz-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:-webkit-linear-gradient(top,#5592bb 0,#327cad 66%,#1C6EA4 100%);background:linear-gradient(to bottom,#5592bb 0,#327cad 66%,#1C6EA4 100%);border-bottom:2px solid #444}table.blueTable thead th{font-size:15px;font-weight:700;color:#FFF;border-left:2px solid #D0E4F5}table.blueTable thead th:first-child{border-left:none}table.blueTable tfoot{font-size:14px;font-weight:700;color:#FFF;background:#D0E4F5;background:-moz-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:-webkit-linear-gradient(top,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);background:linear-gradient(to bottom,#dcebf7 0,#d4e6f6 66%,#D0E4F5 100%);border-top:2px solid #444}table.blueTable tfoot td{font-size:14px}table.blueTable tfoot .links{text-align:right}table.blueTable tfoot .links a{display:inline-block;background:#1C6EA4;color:#FFF;padding:2px 8px;border-radius:5px}</style>'
148148
$FinalResults = if ($results -is [array] -and $results[0] -is [string]) { $Results | ConvertTo-Html -Fragment -Property @{ l = 'Text'; e = { $_ } } } else { $Results | ConvertTo-Html -Fragment }
149149
$HTML = $FinalResults -replace '<table>', "This alert is for tenant $Tenant. <br /><br /> $TableDesign<table class=blueTable>" | Out-String
150+
151+
# Add alert comment if available
152+
if ($task.AlertComment) {
153+
$HTML += "<div style='background-color: #f8f9fa; border-left: 4px solid #007bff; padding: 15px; margin: 15px 0;'><h4 style='margin-top: 0; color: #007bff;'>Alert Information</h4><p style='margin-bottom: 0;'>$($task.AlertComment)</p></div>"
154+
}
155+
150156
$title = "$TaskType - $Tenant - $($task.Name)"
151157
Write-Information 'Scheduler: Sending the results to the target.'
152158
Write-Information "The content of results is: $Results"
@@ -155,10 +161,11 @@ function Push-ExecScheduledCommand {
155161
'*email*' { Send-CIPPAlert -Type 'email' -Title $title -HTMLContent $HTML -TenantFilter $Tenant }
156162
'*webhook*' {
157163
$Webhook = [PSCustomObject]@{
158-
'tenantId' = $TenantInfo.customerId
159-
'Tenant' = $Tenant
160-
'TaskInfo' = $Item.TaskInfo
161-
'Results' = $Results
164+
'tenantId' = $TenantInfo.customerId
165+
'Tenant' = $Tenant
166+
'TaskInfo' = $Item.TaskInfo
167+
'Results' = $Results
168+
'AlertComment' = $task.AlertComment
162169
}
163170
Send-CIPPAlert -Type 'webhook' -Title $title -TenantFilter $Tenant -JSONContent $($Webhook | ConvertTo-Json -Depth 20)
164171
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Alerts/Invoke-AddAlert.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Function Invoke-AddAlert {
2222
type = $Request.Body.logbook.value
2323
RowKey = $RowKey
2424
PartitionKey = 'Webhookv2'
25+
AlertComment = [string]$Request.Body.AlertComment
2526
}
2627
$WebhookTable = Get-CippTable -TableName 'WebhookRules'
2728
Add-CIPPAzDataTableEntity @WebhookTable -Entity $CompleteObject -Force

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Alerts/Invoke-ListAlertsQueue.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ function Invoke-ListAlertsQueue {
3232
RowKey = $Task.RowKey
3333
PartitionKey = $Task.PartitionKey
3434
RepeatsEvery = 'When received'
35+
AlertComment = $Task.AlertComment
3536
RawAlert = @{
3637
Conditions = @($Conditions)
3738
Actions = @($($Task.Actions | ConvertFrom-Json -Depth 10 -ErrorAction SilentlyContinue))
3839
Tenants = @($Tenants)
3940
type = $Task.type
4041
RowKey = $Task.RowKey
4142
PartitionKey = $Task.PartitionKey
42-
43+
AlertComment = $Task.AlertComment
4344
}
4445
}
4546

@@ -101,6 +102,7 @@ function Invoke-ListAlertsQueue {
101102
LogType = 'Scripted'
102103
EventType = 'Scheduled Task'
103104
RepeatsEvery = $Task.Recurrence
105+
AlertComment = $Task.AlertComment
104106
RawAlert = $Task
105107
}
106108

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Conditional/Invoke-ExecNamedLocation.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function Invoke-ExecNamedLocation {
1818
$NamedLocationId = $Request.Body.namedLocationId ?? $Request.Query.namedLocationId
1919
$Change = $Request.Body.change ?? $Request.Query.change
2020
$Content = $Request.Body.input ?? $Request.Query.input
21+
if ($content.value) { $content = $content.value }
2122

2223
try {
2324
$results = Set-CIPPNamedLocation -NamedLocationId $NamedLocationId -TenantFilter $TenantFilter -Change $Change -Content $Content -Headers $Headers

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-AddStandardsTemplate.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ function Invoke-AddStandardsTemplate {
1010

1111
$APIName = $Request.Params.CIPPEndpoint
1212
$Headers = $Request.Headers
13-
13+
if ($Request.Body.tenantFilter -eq 'tenantFilter') {
14+
throw 'Invalid Tenant Selection. A standard must be assigned to at least 1 tenant.'
15+
}
1416

1517
$GUID = $Request.body.GUID ? $request.body.GUID : (New-Guid).GUID
1618
#updatedBy = $request.headers.'x-ms-client-principal'

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ExecUpdateDriftDeviation.ps1

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ function Invoke-ExecUpdateDriftDeviation {
4242
if ($Deviation.status -eq 'DeniedRemediate') {
4343
$Setting = $Deviation.standardName -replace 'standards.', ''
4444
$StandardTemplate = Get-CIPPTenantAlignment -TenantFilter $TenantFilter | Where-Object -Property standardType -EQ 'drift'
45-
$StandardTemplate = $StandardTemplate.standardSettings.$Setting
46-
47-
$StandardTemplate.standards.$Setting | Add-Member -MemberType NoteProperty -Name 'remediate' -Value $true -Force
48-
$StandardTemplate.standards.$Setting | Add-Member -MemberType NoteProperty -Name 'report' -Value $true -Force
49-
45+
if ($Setting -like '*IntuneTemplate*') {
46+
$Setting = 'IntuneTemplate'
47+
$TemplateId = $Deviation.standardName.split('.') | Select-Object -Last 1
48+
$StandardTemplate = $StandardTemplate.standardSettings.IntuneTemplate | Where-Object { $_.TemplateList.value -eq $TemplateId }
49+
$StandardTemplate | Add-Member -MemberType NoteProperty -Name 'remediate' -Value $true -Force
50+
$StandardTemplate | Add-Member -MemberType NoteProperty -Name 'report' -Value $true -Force
51+
$Settings = $StandardTemplate
52+
} else {
53+
$StandardTemplate = $StandardTemplate.standardSettings.$Setting
54+
$StandardTemplate.standards.$Setting | Add-Member -MemberType NoteProperty -Name 'remediate' -Value $true -Force
55+
$StandardTemplate.standards.$Setting | Add-Member -MemberType NoteProperty -Name 'report' -Value $true -Force
56+
$Settings = $StandardTemplate.standards.$Setting
57+
}
5058
$TaskBody = @{
5159
TenantFilter = $TenantFilter
5260
Name = "One Off Drift Remediation: $Setting - $TenantFilter"
@@ -57,7 +65,7 @@ function Invoke-ExecUpdateDriftDeviation {
5765

5866
Parameters = [pscustomobject]@{
5967
Tenant = $TenantFilter
60-
Settings = $StandardTemplate.standards.$Setting
68+
Settings = $Settings
6169
}
6270
ScheduledTime = '0'
6371
PostExecution = @{

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ function Write-AlertTrace {
77
$cmdletName,
88
$data,
99
$tenantFilter,
10-
[string]$PartitionKey = (Get-Date -UFormat '%Y%m%d').ToString()
10+
[string]$PartitionKey = (Get-Date -UFormat '%Y%m%d').ToString(),
11+
[string]$AlertComment = $null
1112
)
1213
$Table = Get-CIPPTable -tablename AlertLastRun
1314
#Get current row and compare the $logData object. If it's the same, don't write it.
@@ -23,6 +24,7 @@ function Write-AlertTrace {
2324
'CmdletName' = "$cmdletName"
2425
'Tenant' = "$tenantFilter"
2526
'LogData' = [string]$LogData
27+
'AlertComment' = [string]$AlertComment
2628
}
2729
$Table.Entity = $TableRow
2830
Add-CIPPAzDataTableEntity @Table -Force | Out-Null
@@ -36,6 +38,7 @@ function Write-AlertTrace {
3638
'CmdletName' = "$cmdletName"
3739
'Tenant' = "$tenantFilter"
3840
'LogData' = [string]$LogData
41+
'AlertComment' = [string]$AlertComment
3942
}
4043
$Table.Entity = $TableRow
4144
Add-CIPPAzDataTableEntity @Table -Force | Out-Null

0 commit comments

Comments
 (0)