diff --git a/ExecNotificationConfig/run.ps1 b/ExecNotificationConfig/run.ps1 index 959818c8b535..e4cbc4066c97 100644 --- a/ExecNotificationConfig/run.ps1 +++ b/ExecNotificationConfig/run.ps1 @@ -22,6 +22,7 @@ $results = try { 'webhook' = "$($Request.Body.Webhook)" 'onePerTenant' = [boolean]$Request.Body.onePerTenant 'sendtoIntegration' = [boolean]$Request.Body.sendtoIntegration + 'includeTenantId' = [boolean]$Request.Body.includeTenantId 'PartitionKey' = 'CippNotifications' 'RowKey' = 'CippNotifications' } diff --git a/GraphHelper.psm1 b/GraphHelper.psm1 index 7cf967bd4c6d..0fdc7a966f2c 100644 --- a/GraphHelper.psm1 +++ b/GraphHelper.psm1 @@ -116,7 +116,7 @@ function Get-GraphToken($tenantid, $scope, $AsApp, $AppID, $refreshToken, $Retur } } -function Write-LogMessage ($message, $tenant = 'None', $API = 'None', $user, $sev) { +function Write-LogMessage ($message, $tenant = 'None', $API = 'None', $tenantId = $null, $user, $sev) { try { $username = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($user)) | ConvertFrom-Json).userDetails } @@ -143,6 +143,12 @@ function Write-LogMessage ($message, $tenant = 'None', $API = 'None', $user, $se 'PartitionKey' = $PartitionKey 'RowKey' = ([guid]::NewGuid()).ToString() } + + if($tenantId) + { + $TableRow.Add('TenantID', [string]$tenantId) + } + $Table.Entity = $TableRow Add-AzDataTableEntity @Table | Out-Null } diff --git a/ListNotificationConfig/run.ps1 b/ListNotificationConfig/run.ps1 index 82e382843126..a33c2f38c3ba 100644 --- a/ListNotificationConfig/run.ps1 +++ b/ListNotificationConfig/run.ps1 @@ -15,7 +15,7 @@ if ($Config) { $Config = @{} } #$config | Add-Member -NotePropertyValue @() -NotePropertyName 'logsToInclude' -Force -$config.logsToInclude = @(([pscustomobject]$config | Select-Object * -ExcludeProperty schedule, type, tenantid, onepertenant, sendtoIntegration, partitionkey, rowkey, tenant, ETag, email, logsToInclude, Severity, Alert, Info, Error, timestamp, webhook).psobject.properties.name) +$config.logsToInclude = @(([pscustomobject]$config | Select-Object * -ExcludeProperty schedule, type, tenantid, onepertenant, sendtoIntegration, partitionkey, rowkey, tenant, ETag, email, logsToInclude, Severity, Alert, Info, Error, timestamp, webhook, includeTenantId).psobject.properties.name) if (!$config.logsToInclude) { $config.logsToInclude = @('None') } diff --git a/Scheduler_Alert/run.ps1 b/Scheduler_Alert/run.ps1 index 524cc8c8d993..b28645c4a386 100644 --- a/Scheduler_Alert/run.ps1 +++ b/Scheduler_Alert/run.ps1 @@ -11,6 +11,9 @@ try { } $Alerts = Get-AzDataTableEntity @Table -Filter $Filter + $ConfigFilter = "RowKey eq 'CippNotifications' and PartitionKey eq 'CippNotifications'" + $Config = [pscustomobject](Get-AzDataTableEntity @Table -Filter $ConfigFilter) + $DeltaTable = Get-CIPPTable -Table DeltaCompare $LastRunTable = Get-CIPPTable -Table AlertLastRun @@ -378,7 +381,12 @@ try { $ShippedAlerts | ForEach-Object { if ($_ -notin $currentlog.Message) { - Write-LogMessage -message $_ -API 'Alerts' -tenant $tenant.tenant -sev Alert + if ($Config.includeTenantId) { + Write-LogMessage -message $_ -API 'Alerts' -tenant $tenant.tenant -sev Alert -tenantid $Tenant.tenantid + } + else { + Write-LogMessage -message $_ -API 'Alerts' -tenant $tenant.tenant -sev Alert + } } } [PSCustomObject]@{