diff --git a/Modules/CIPPCore/Public/Entrypoints/Push-SchedulerAlert.ps1 b/Modules/CIPPCore/Public/Entrypoints/Push-SchedulerAlert.ps1
new file mode 100644
index 000000000000..d9800f40a34a
--- /dev/null
+++ b/Modules/CIPPCore/Public/Entrypoints/Push-SchedulerAlert.ps1
@@ -0,0 +1,43 @@
+function Push-SchedulerAlert {
+ param (
+ $QueueItem, $TriggerMetadata
+ )
+ $Tenant = $QueueItem
+ try {
+ $Table = Get-CIPPTable -Table SchedulerConfig
+ if ($Tenant.tag -eq 'AllTenants') {
+ $Filter = "RowKey eq 'AllTenants' and PartitionKey eq 'Alert'"
+ } else {
+ $Filter = "RowKey eq '{0}' and PartitionKey eq 'Alert'" -f $Tenant.tenantid
+ }
+ $Alerts = Get-CIPPAzDataTableEntity @Table -Filter $Filter
+
+
+ $IgnoreList = @('Etag', 'PartitionKey', 'Timestamp', 'RowKey', 'tenantid', 'tenant', 'type')
+ $alertList = $Alerts | Select-Object * -ExcludeProperty $IgnoreList
+ foreach ($task in ($AlertList.psobject.members | Where-Object { $_.MemberType -EQ 'NoteProperty' -and $_.value -eq $True }).name) {
+ $QueueItem = [pscustomobject]@{
+ tenant = $tenant.tenant
+ tenantid = $tenant.tenantid
+ FunctionName = "CIPPAlert$($Task)"
+ }
+ Push-OutputBinding -Name QueueItemOut -Value $QueueItem
+ }
+
+ $Table = Get-CIPPTable
+ $PartitionKey = Get-Date -UFormat '%Y%m%d'
+ $Filter = "PartitionKey eq '{0}' and Tenant eq '{1}'" -f $PartitionKey, $tenant.tenant
+ $currentlog = Get-CIPPAzDataTableEntity @Table -Filter $Filter
+
+ $AlertsTable = Get-CIPPTable -Table cachealerts
+ $CurrentAlerts = (Get-CIPPAzDataTableEntity @AlertsTable -Filter $Filter)
+ $CurrentAlerts | ForEach-Object {
+ if ($_.Message -notin $currentlog.Message) { Write-LogMessage -message $_.Message -API 'Alerts' -tenant $tenant.tenant -sev Alert -tenantid $Tenant.tenantid }
+ Remove-AzDataTableEntity @AlertsTable -Entity $_ | Out-Null
+ }
+
+ } catch {
+ $Message = 'Exception on line {0} - {1}' -f $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message
+ Write-LogMessage -message $Message -API 'Alerts' -tenant $tenant.tenant -sev Error
+ }
+}
\ No newline at end of file
diff --git a/Modules/CIPPCore/Public/Entrypoints/Push-SchedulerCIPPNotifications.ps1 b/Modules/CIPPCore/Public/Entrypoints/Push-SchedulerCIPPNotifications.ps1
new file mode 100644
index 000000000000..3ec9e8b7d9a2
--- /dev/null
+++ b/Modules/CIPPCore/Public/Entrypoints/Push-SchedulerCIPPNotifications.ps1
@@ -0,0 +1,164 @@
+function Push-SchedulerCIPPNotifications {
+ param (
+ $QueueItem, $TriggerMetadata
+ )
+
+ $Table = Get-CIPPTable -TableName SchedulerConfig
+ $Filter = "RowKey eq 'CippNotifications' and PartitionKey eq 'CippNotifications'"
+ $Config = [pscustomobject](Get-CIPPAzDataTableEntity @Table -Filter $Filter)
+
+ $Settings = [System.Collections.ArrayList]@('Alerts')
+ $Config.psobject.properties.name | ForEach-Object { $settings.add($_) }
+ $severity = $Config.Severity -split ','
+ Write-Host "Our Severity table is: $severity"
+ if (!$severity) {
+ $severity = [System.Collections.ArrayList]@('Info', 'Error', 'Warning', 'Critical', 'Alert')
+ }
+ Write-Host "Our Severity table is: $severity"
+ $Table = Get-CIPPTable
+ $PartitionKey = Get-Date -UFormat '%Y%m%d'
+ $Filter = "PartitionKey eq '{0}'" -f $PartitionKey
+ $Currentlog = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object {
+ $_.API -In $Settings -and $_.SentAsAlert -ne $true -and $_.Severity -In $severity
+ }
+ Write-Host ($Currentlog).count
+ #email try
+ try {
+ if ($config.onePerTenant) {
+ if ($Config.email -like '*@*' -and $null -ne $CurrentLog) {
+ $JSONRecipients = $Config.email.split(',').trim() | ForEach-Object { if ($_ -like '*@*') { '{ "EmailAddress": { "Address": "' + $_ + '" } }, ' } }
+ $JSONRecipients = ([string]$JSONRecipients).Substring(0, ([string]$JSONRecipients).Length - 1)
+ foreach ($tenant in ($CurrentLog.Tenant | Sort-Object -Unique)) {
+ $HTMLLog = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object -Property tenant -EQ $tenant | ConvertTo-Html -frag) -replace '
', '' | Out-String
+ $JSONBody = @"
+ {
+ "message": {
+ "subject": "$($Tenant): CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))",
+ "body": {
+ "contentType": "HTML",
+ "content": "You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log:
+
+
+ $($HTMLLog)
+
+ "
+ },
+ "toRecipients": [
+ $($JSONRecipients)
+ ]
+ },
+ "saveToSentItems": "false"
+ }
+"@
+ New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -type POST -body ($JSONBody)
+ Write-LogMessage -API 'Alerts' -message "Sent alerts to: $($JSONRecipients)" -tenant $Tenant -sev Debug
+ }
+ }
+ } else {
+ if ($Config.email -like '*@*' -and $null -ne $CurrentLog) {
+ $JSONRecipients = $Config.email.split(',').trim() | ForEach-Object { if ($_ -like '*@*') { '{ "EmailAddress": { "Address": "' + $_ + '" } }, ' } }
+ $JSONRecipients = ([string]$JSONRecipients).Substring(0, ([string]$JSONRecipients).Length - 1)
+ $HTMLLog = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | ConvertTo-Html -frag) -replace '', '' | Out-String
+ $JSONBody = @"
+ {
+ "message": {
+ "subject": "CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))",
+ "body": {
+ "contentType": "HTML",
+ "content": "You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log:
+
+
+ $($HTMLLog)
+
+ "
+ },
+ "toRecipients": [
+ $($JSONRecipients)
+ ]
+ },
+ "saveToSentItems": "false"
+ }
+"@
+ New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -type POST -body ($JSONBody)
+ Write-LogMessage -API 'Alerts' -message "Sent alerts to: $($Config.email)" -tenant 'All Tenants' -sev Debug
+ }
+ }
+ } catch {
+ Write-Host "Could not send alerts to email: $($_.Exception.message)"
+ Write-LogMessage -API 'Alerts' -message "Could not send alerts to: $($_.Exception.message)" -tenant 'All Tenants' -sev error
+ }
+
+
+ try {
+ Write-Host $($config | ConvertTo-Json)
+ Write-Host $config.webhook
+ if ($Config.webhook -ne '' -and $null -ne $CurrentLog) {
+ switch -wildcard ($config.webhook) {
+
+ '*webhook.office.com*' {
+ $Log = $Currentlog | ConvertTo-Html -frag | Out-String
+ $JSonBody = "{`"text`": `"You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log.
$Log`"}"
+ Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
+ }
+
+ '*slack.com*' {
+ $Log = $Currentlog | ForEach-Object {
+ $JSonBody = @"
+ {"blocks":[{"type":"header","text":{"type":"plain_text","text":"New Alert from CIPP","emoji":true}},{"type":"section","fields":[{"type":"mrkdwn","text":"*DateTime:*\n$($_.Timestamp)"},{"type":"mrkdwn","text":"*Tenant:*\n$($_.Tenant)"},{"type":"mrkdwn","text":"*API:*\n$($_.API)"},{"type":"mrkdwn","text":"*User:*\n$($_.Username)."}]},{"type":"section","text":{"type":"mrkdwn","text":"*Message:*\n$($_.Message)"}}]}
+"@
+ Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
+ }
+ }
+
+ '*discord.com*' {
+ $Log = $Currentlog | ConvertTo-Html -frag | Out-String
+ $JSonBody = "{`"content`": `"You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log. $Log`"}"
+ Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
+ }
+ default {
+ $Log = $Currentlog | ConvertTo-Json -Compress
+ $JSonBody = $Log
+ Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
+ }
+ }
+ Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Sent Webhook to $($config.webhook)" -sev Debug
+ }
+
+ $UpdateLogs = $CurrentLog | ForEach-Object {
+ $_.SentAsAlert = $true
+ $_
+ }
+ if ($UpdateLogs) {
+ Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force
+ }
+ } catch {
+ Write-Host "Could not send alerts to webhook: $($_.Exception.message)"
+ Write-LogMessage -API 'Alerts' -message "Could not send alerts to : $($_.Exception.message)" -tenant $Tenant -sev error
+ }
+
+ if ($config.sendtoIntegration) {
+ try {
+ foreach ($tenant in ($CurrentLog.Tenant | Sort-Object -Unique)) {
+ $HTMLLog = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object -Property tenant -EQ $tenant | ConvertTo-Html -frag) -replace '', '' | Out-String
+ $Alert = @{
+ TenantId = $Tenant
+ AlertText = " $($htmllog)"
+ AlertTitle = "$tenant CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))"
+ }
+ New-CippExtAlert -Alert $Alert
+ $UpdateLogs = $CurrentLog | ForEach-Object {
+ $_.SentAsAlert = $true
+ $_
+ }
+ if ($UpdateLogs) {
+ Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force
+ }
+ }
+ } catch {
+ Write-Host "Could not send alerts to ticketing system: $($_.Exception.message)"
+ Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Could not send alerts to ticketing system: $($_.Exception.message)" -sev Error
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/Modules/CIPPCore/Public/Entrypoints/Push-Schedulerwebhookcreation.ps1 b/Modules/CIPPCore/Public/Entrypoints/Push-Schedulerwebhookcreation.ps1
new file mode 100644
index 000000000000..82e1a47d55c5
--- /dev/null
+++ b/Modules/CIPPCore/Public/Entrypoints/Push-Schedulerwebhookcreation.ps1
@@ -0,0 +1,7 @@
+function Push-Schedulerwebhookcreation
+ {
+ param (
+ $QueueItem, $TriggerMetadata
+ )
+
+}
\ No newline at end of file
diff --git a/Scheduler_Alert/function.json b/Scheduler_Alert/function.json
deleted file mode 100644
index b8758df62b9d..000000000000
--- a/Scheduler_Alert/function.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "bindings": [
- {
- "name": "tenant",
- "direction": "in",
- "type": "activityTrigger"
- },
- {
- "type": "queue",
- "direction": "out",
- "name": "QueueItem",
- "queueName": "CIPPGenericQueue"
- }
- ]
-}
diff --git a/Scheduler_Alert/run.ps1 b/Scheduler_Alert/run.ps1
deleted file mode 100644
index 1a7cca3527e3..000000000000
--- a/Scheduler_Alert/run.ps1
+++ /dev/null
@@ -1,46 +0,0 @@
-param($tenant)
-
-try {
-
- $Table = Get-CIPPTable -Table SchedulerConfig
- if ($Tenant.tag -eq 'AllTenants') {
- $Filter = "RowKey eq 'AllTenants' and PartitionKey eq 'Alert'"
- } else {
- $Filter = "RowKey eq '{0}' and PartitionKey eq 'Alert'" -f $Tenant.tenantid
- }
- $Alerts = Get-CIPPAzDataTableEntity @Table -Filter $Filter
-
-
- $IgnoreList = @('Etag', 'PartitionKey', 'Timestamp', 'RowKey', 'tenantid', 'tenant', 'type')
- $alertList = $Alerts | Select-Object * -ExcludeProperty $IgnoreList
- foreach ($task in ($AlertList.psobject.members | Where-Object { $_.MemberType -EQ 'NoteProperty' -and $_.value -eq $True }).name) {
- $QueueItem = [pscustomobject]@{
- tenant = $tenant.tenant
- tenantid = $tenant.tenantid
- FunctionName = "CIPPAlert$($Task)"
- }
- Push-OutputBinding -Name QueueItem -Value $QueueItem
- }
-
- $Table = Get-CIPPTable
- $PartitionKey = Get-Date -UFormat '%Y%m%d'
- $Filter = "PartitionKey eq '{0}' and Tenant eq '{1}'" -f $PartitionKey, $tenant.tenant
- $currentlog = Get-CIPPAzDataTableEntity @Table -Filter $Filter
-
- $AlertsTable = Get-CIPPTable -Table cachealerts
- $CurrentAlerts = (Get-CIPPAzDataTableEntity @AlertsTable -Filter $Filter)
- $CurrentAlerts | ForEach-Object {
- if ($_.Message -notin $currentlog.Message) { Write-LogMessage -message $_.Message -API 'Alerts' -tenant $tenant.tenant -sev Alert -tenantid $Tenant.tenantid }
- Remove-AzDataTableEntity @AlertsTable -Entity $_ | Out-Null
- }
-
- [PSCustomObject]@{
- ReturnedValues = $true
- }
-} catch {
- $Message = 'Exception on line {0} - {1}' -f $_.InvocationInfo.ScriptLineNumber, $_.Exception.Message
- Write-LogMessage -message $Message -API 'Alerts' -tenant $tenant.tenant -sev Error
- [PSCustomObject]@{
- ReturnedValues = $false
- }
-}
diff --git a/Scheduler_CIPPNotifications/function.json b/Scheduler_CIPPNotifications/function.json
deleted file mode 100644
index 2d4ea9094b24..000000000000
--- a/Scheduler_CIPPNotifications/function.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "bindings": [
- {
- "name": "tenant",
- "direction": "in",
- "type": "activityTrigger"
- }
- ]
-}
\ No newline at end of file
diff --git a/Scheduler_CIPPNotifications/run.ps1 b/Scheduler_CIPPNotifications/run.ps1
deleted file mode 100644
index 512f015f0fc9..000000000000
--- a/Scheduler_CIPPNotifications/run.ps1
+++ /dev/null
@@ -1,164 +0,0 @@
-param($tenant)
-
-
-$Table = Get-CIPPTable -TableName SchedulerConfig
-$Filter = "RowKey eq 'CippNotifications' and PartitionKey eq 'CippNotifications'"
-$Config = [pscustomobject](Get-CIPPAzDataTableEntity @Table -Filter $Filter)
-
-$Settings = [System.Collections.ArrayList]@('Alerts')
-$Config.psobject.properties.name | ForEach-Object { $settings.add($_) }
-$severity = $Config.Severity -split ','
-Write-Host "Our Severity table is: $severity"
-if (!$severity) {
- $severity = [System.Collections.ArrayList]@('Info', 'Error', 'Warning', 'Critical', 'Alert')
-}
-Write-Host "Our Severity table is: $severity"
-$Table = Get-CIPPTable
-$PartitionKey = Get-Date -UFormat '%Y%m%d'
-$Filter = "PartitionKey eq '{0}'" -f $PartitionKey
-$Currentlog = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object {
- $_.API -In $Settings -and $_.SentAsAlert -ne $true -and $_.Severity -In $severity
-}
-Write-Host ($Currentlog).count
-#email try
-try {
- if ($config.onePerTenant) {
- if ($Config.email -like '*@*' -and $null -ne $CurrentLog) {
- $JSONRecipients = $Config.email.split(',').trim() | ForEach-Object { if ($_ -like '*@*') { '{ "EmailAddress": { "Address": "' + $_ + '" } }, ' } }
- $JSONRecipients = ([string]$JSONRecipients).Substring(0, ([string]$JSONRecipients).Length - 1)
- foreach ($tenant in ($CurrentLog.Tenant | Sort-Object -Unique)) {
- $HTMLLog = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object -Property tenant -EQ $tenant | ConvertTo-Html -frag) -replace '', '' | Out-String
- $JSONBody = @"
- {
- "message": {
- "subject": "$($Tenant): CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))",
- "body": {
- "contentType": "HTML",
- "content": "You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log:
-
-
- $($HTMLLog)
-
- "
- },
- "toRecipients": [
- $($JSONRecipients)
- ]
- },
- "saveToSentItems": "false"
- }
-"@
- New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -type POST -body ($JSONBody)
- Write-LogMessage -API 'Alerts' -message "Sent alerts to: $($JSONRecipients)" -tenant $Tenant -sev Debug
- }
- }
- } else {
- if ($Config.email -like '*@*' -and $null -ne $CurrentLog) {
- $JSONRecipients = $Config.email.split(',').trim() | ForEach-Object { if ($_ -like '*@*') { '{ "EmailAddress": { "Address": "' + $_ + '" } }, ' } }
- $JSONRecipients = ([string]$JSONRecipients).Substring(0, ([string]$JSONRecipients).Length - 1)
- $HTMLLog = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | ConvertTo-Html -frag) -replace '', '' | Out-String
- $JSONBody = @"
- {
- "message": {
- "subject": "CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))",
- "body": {
- "contentType": "HTML",
- "content": "You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log:
-
-
- $($HTMLLog)
-
- "
- },
- "toRecipients": [
- $($JSONRecipients)
- ]
- },
- "saveToSentItems": "false"
- }
-"@
- New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -type POST -body ($JSONBody)
- Write-LogMessage -API 'Alerts' -message "Sent alerts to: $($Config.email)" -tenant 'All Tenants' -sev Debug
- }
- }
-} catch {
- Write-Host "Could not send alerts to email: $($_.Exception.message)"
- Write-LogMessage -API 'Alerts' -message "Could not send alerts to: $($_.Exception.message)" -tenant 'All Tenants' -sev error
-}
-
-
-try {
- Write-Host $($config | ConvertTo-Json)
- Write-Host $config.webhook
- if ($Config.webhook -ne '' -and $null -ne $CurrentLog) {
- switch -wildcard ($config.webhook) {
-
- '*webhook.office.com*' {
- $Log = $Currentlog | ConvertTo-Html -frag | Out-String
- $JSonBody = "{`"text`": `"You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log.
$Log`"}"
- Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
- }
-
- '*slack.com*' {
- $Log = $Currentlog | ForEach-Object {
- $JSonBody = @"
- {"blocks":[{"type":"header","text":{"type":"plain_text","text":"New Alert from CIPP","emoji":true}},{"type":"section","fields":[{"type":"mrkdwn","text":"*DateTime:*\n$($_.Timestamp)"},{"type":"mrkdwn","text":"*Tenant:*\n$($_.Tenant)"},{"type":"mrkdwn","text":"*API:*\n$($_.API)"},{"type":"mrkdwn","text":"*User:*\n$($_.Username)."}]},{"type":"section","text":{"type":"mrkdwn","text":"*Message:*\n$($_.Message)"}}]}
-"@
- Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
- }
- }
-
- '*discord.com*' {
- $Log = $Currentlog | ConvertTo-Html -frag | Out-String
- $JSonBody = "{`"content`": `"You've setup your alert policies to be alerted whenever specific events happen. We've found some of these events in the log. $Log`"}"
- Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
- }
- default {
- $Log = $Currentlog | ConvertTo-Json -Compress
- $JSonBody = $Log
- Invoke-RestMethod -Uri $config.webhook -Method POST -ContentType 'Application/json' -Body $JSONBody
- }
- }
- Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Sent Webhook to $($config.webhook)" -sev Debug
- }
-
- $UpdateLogs = $CurrentLog | ForEach-Object {
- $_.SentAsAlert = $true
- $_
- }
- if ($UpdateLogs) {
- Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force
- }
-} catch {
- Write-Host "Could not send alerts to webhook: $($_.Exception.message)"
- Write-LogMessage -API 'Alerts' -message "Could not send alerts to : $($_.Exception.message)" -tenant $Tenant -sev error
-}
-
-if ($config.sendtoIntegration) {
- try {
- foreach ($tenant in ($CurrentLog.Tenant | Sort-Object -Unique)) {
- $HTMLLog = ($CurrentLog | Select-Object Message, API, Tenant, Username, Severity | Where-Object -Property tenant -EQ $tenant | ConvertTo-Html -frag) -replace '', '' | Out-String
- $Alert = @{
- TenantId = $Tenant
- AlertText = " $($htmllog)"
- AlertTitle = "$tenant CIPP Alert: Alerts found starting at $((Get-Date).AddMinutes(-15))"
- }
- New-CippExtAlert -Alert $Alert
- $UpdateLogs = $CurrentLog | ForEach-Object {
- $_.SentAsAlert = $true
- $_
- }
- if ($UpdateLogs) {
- Add-CIPPAzDataTableEntity @Table -Entity $UpdateLogs -Force
- }
- }
- } catch {
- Write-Host "Could not send alerts to ticketing system: $($_.Exception.message)"
- Write-LogMessage -API 'Alerts' -tenant $Tenant -message "Could not send alerts to ticketing system: $($_.Exception.message)" -sev Error
- }
-}
-
-
-[PSCustomObject]@{
- ReturnedValues = $true
-}
diff --git a/Scheduler_Extensions/run.ps1 b/Scheduler_Extensions/run.ps1
index c6ce09744cbd..66af8649ebf7 100644
--- a/Scheduler_Extensions/run.ps1
+++ b/Scheduler_Extensions/run.ps1
@@ -6,7 +6,7 @@ $Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-AzDataTableEntity @Table).config | ConvertFrom-Json)
-Write-Host "Started Scheduler for Extensions"
+Write-Host 'Started Scheduler for Extensions'
# NinjaOne Extension
if ($Configuration.NinjaOne.Enabled -eq $True) {
@@ -42,7 +42,7 @@ if ($Configuration.NinjaOne.Enabled -eq $True) {
$TenantsToProcess = Get-AzDataTableEntity @CIPPMapping -Filter $Filter | Where-Object { $Null -ne $_.NinjaOne -and $_.NinjaOne -ne '' }
if ($Null -eq $LastRunTime -or $LastRunTime -le (Get-Date).addhours(-25) -or $TimeSetting -eq $CurrentInterval) {
- Write-Host "Executing"
+ Write-Host 'Executing'
foreach ($Tenant in $TenantsToProcess | Sort-Object lastEndTime) {
Push-OutputBinding -Name NinjaProcess -Value @{
'NinjaAction' = 'SyncTenant'
@@ -55,7 +55,7 @@ if ($Configuration.NinjaOne.Enabled -eq $True) {
$AddObject = @{
PartitionKey = 'NinjaConfig'
RowKey = 'NinjaLastRunTime'
- 'SettingValue' = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffK")
+ 'SettingValue' = (Get-Date).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffK')
}
Add-AzDataTableEntity @Table -Entity $AddObject -Force
@@ -76,7 +76,7 @@ if ($Configuration.NinjaOne.Enabled -eq $True) {
$_ | Add-Member -NotePropertyName lastStartTime -NotePropertyValue $Null -Force
}
}
- $CatchupTenants = $TenantsToProcess | where-object { (((($_.lastEndTime -eq $Null) -or ($_.lastStartTime -gt $_.lastEndTime)) -and ($_.lastStartTime -lt (Get-Date).AddMinutes(-30)))) -or ($_.lastStartTime -lt $LastRunTime) }
+ $CatchupTenants = $TenantsToProcess | Where-Object { (((($_.lastEndTime -eq $Null) -or ($_.lastStartTime -gt $_.lastEndTime)) -and ($_.lastStartTime -lt (Get-Date).AddMinutes(-30)))) -or ($_.lastStartTime -lt $LastRunTime) }
foreach ($Tenant in $CatchupTenants) {
Push-OutputBinding -Name NinjaProcess -Value @{
'NinjaAction' = 'SyncTenant'
@@ -84,8 +84,8 @@ if ($Configuration.NinjaOne.Enabled -eq $True) {
}
Start-Sleep -Seconds 1
}
- if (($CatchupTenants | Measure-Object).count -gt 0){
- Write-LogMessage -API 'NinjaOneSync' -user 'CIPP' -message "NinjaOne Synchronization Catchup Queued for $(($CatchupTenants | Measure-Object).count) Tenants" -Sev 'Info'
+ if (($CatchupTenants | Measure-Object).count -gt 0) {
+ Write-LogMessage -API 'NinjaOneSync' -user 'CIPP' -message "NinjaOne Synchronization Catchup Queued for $(($CatchupTenants | Measure-Object).count) Tenants" -Sev 'Info'
}
}
diff --git a/Scheduler_GetQueue/function.json b/Scheduler_GetQueue/function.json
index b31f1ad21352..f9f3ccb2d877 100644
--- a/Scheduler_GetQueue/function.json
+++ b/Scheduler_GetQueue/function.json
@@ -1,9 +1,16 @@
{
"bindings": [
{
- "name": "name",
- "type": "activityTrigger",
- "direction": "in"
+ "name": "Timer",
+ "schedule": "0 */1 * * * *",
+ "direction": "in",
+ "type": "timerTrigger"
+ },
+ {
+ "type": "queue",
+ "direction": "out",
+ "name": "QueueItem",
+ "queueName": "CIPPGenericQueue"
}
]
-}
\ No newline at end of file
+}
diff --git a/Scheduler_GetQueue/run.ps1 b/Scheduler_GetQueue/run.ps1
index 3d495bd85264..f14ccc274dd4 100644
--- a/Scheduler_GetQueue/run.ps1
+++ b/Scheduler_GetQueue/run.ps1
@@ -1,9 +1,9 @@
-param($name)
+param($Timer)
$Table = Get-CIPPTable -TableName SchedulerConfig
$Tenants = Get-CIPPAzDataTableEntity @Table | Where-Object -Property PartitionKey -NE 'WebhookAlert'
-$object = foreach ($Tenant in $Tenants) {
+$Tasks = foreach ($Tenant in $Tenants) {
if ($Tenant.tenant -ne 'AllTenants') {
[pscustomobject]@{
Tenant = $Tenant.tenant
@@ -23,6 +23,19 @@ $object = foreach ($Tenant in $Tenants) {
}
}
}
-}
+}
-$object
\ No newline at end of file
+foreach ($Task in $Tasks) {
+ $QueueItem = [pscustomobject]@{
+ Tenant = $task.tenant
+ Tenantid = $task.tenantid
+ Tag = $task.tag
+ Type = $task.type
+ FunctionName = "Scheduler$($Task.Type)"
+ }
+ try {
+ Push-OutputBinding -Name QueueItem -Value $QueueItem
+ } catch {
+ Write-Host "Could not launch queue item for $($Task.tenant): $($_.Exception.Message)"
+ }
+}
\ No newline at end of file
diff --git a/Scheduler_Orchestration/function.json b/Scheduler_Orchestration/function.json
deleted file mode 100644
index 7326b39c184d..000000000000
--- a/Scheduler_Orchestration/function.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "bindings": [
- {
- "name": "Context",
- "type": "orchestrationTrigger",
- "direction": "in"
- }
- ]
-}
\ No newline at end of file
diff --git a/Scheduler_Orchestration/run.ps1 b/Scheduler_Orchestration/run.ps1
deleted file mode 100644
index 0014b630fe38..000000000000
--- a/Scheduler_Orchestration/run.ps1
+++ /dev/null
@@ -1,32 +0,0 @@
-param($Context)
-
-$DurableRetryOptions = @{
- FirstRetryInterval = (New-TimeSpan -Seconds 5)
- MaxNumberOfAttempts = 3
- BackoffCoefficient = 2
-}
-$RetryOptions = New-DurableRetryOptions @DurableRetryOptions
-
-try {
- $Batch = Invoke-ActivityFunction -FunctionName 'Scheduler_GetQueue' -Input 'LetsGo'
- if (($Batch | Measure-Object).Count -gt 0) {
-
- $ParallelTasks = foreach ($Item in $Batch) {
- try {
- Invoke-DurableActivity -FunctionName "Scheduler_$($item['Type'])" -Input $item -NoWait -RetryOptions $RetryOptions -ErrorAction Stop
- }
- catch {
- Write-Host 'Could not start:'
- Write-Host ($item | ConvertTo-Json)
- }
- }
- $Outputs = Wait-ActivityFunction -Task $ParallelTasks
- if (-not $Outputs['DataReturned']) {
- Write-Host 'Errors detected'
- }
- }
-}
-catch {}
-finally {
- Write-LogMessage -API 'Scheduler' -tenant $tenant -message 'Scheduler Ran.' -sev Debug
-}
\ No newline at end of file
diff --git a/Scheduler_Timer/function.json b/Scheduler_Timer/function.json
deleted file mode 100644
index 56e4cf0cfda1..000000000000
--- a/Scheduler_Timer/function.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "bindings": [
- {
- "name": "Timer",
- "schedule": "0 0 * * * *",
- "direction": "in",
- "type": "timerTrigger"
- },
- {
- "name": "starter",
- "type": "durableClient",
- "direction": "in"
- }
- ]
-}
diff --git a/Scheduler_Timer/run.ps1 b/Scheduler_Timer/run.ps1
deleted file mode 100644
index f62c2909b58d..000000000000
--- a/Scheduler_Timer/run.ps1
+++ /dev/null
@@ -1,8 +0,0 @@
-using namespace System.Net
-
-param($Timer)
-
-$InstanceId = Start-NewOrchestration -FunctionName 'Scheduler_Orchestration'
-Write-Host "Started orchestration with ID = '$InstanceId'"
-New-OrchestrationCheckStatusResponse -Request $timer -InstanceId $InstanceId
-
diff --git a/Z_CIPPQueueTrigger/function.json b/Z_CIPPQueueTrigger/function.json
index c048325fc313..4d818463ea75 100644
--- a/Z_CIPPQueueTrigger/function.json
+++ b/Z_CIPPQueueTrigger/function.json
@@ -7,6 +7,12 @@
"type": "queueTrigger",
"direction": "in",
"queueName": "CIPPGenericQueue"
+ },
+ {
+ "type": "queue",
+ "direction": "out",
+ "name": "QueueItemOut",
+ "queueName": "CIPPGenericQueue"
}
]
}