Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ictsinfx committed May 2, 2024
2 parents 6df5698 + 3371bf5 commit 3288687
Show file tree
Hide file tree
Showing 261 changed files with 1,173 additions and 41,089 deletions.
9 changes: 0 additions & 9 deletions BestPracticeAnalyser_All/function.json

This file was deleted.

9 changes: 0 additions & 9 deletions BestPracticeAnalyser_GetQueue/function.json

This file was deleted.

10 changes: 0 additions & 10 deletions BestPracticeAnalyser_GetQueue/run.ps1

This file was deleted.

9 changes: 0 additions & 9 deletions BestPracticeAnalyser_Orchestration/function.json

This file was deleted.

21 changes: 0 additions & 21 deletions BestPracticeAnalyser_Orchestration/run.ps1

This file was deleted.

46 changes: 33 additions & 13 deletions BestPracticeAnalyser_OrchestrationStarter/run.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
using namespace System.Net

param($Request, $TriggerMetadata)
if ($CurrentlyRunning) {
$Results = [pscustomobject]@{'Results' = 'Already running. Please wait for the current instance to finish' }
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Attempted to start analysis but an instance was already running.' -sev Info

if ($Request.Query.TenantFilter) {
$TenantList = @($Request.Query.TenantFilter)
$Name = "Best Practice Analyser ($($Request.Query.TenantFilter))"
} else {
$InputObject = @{
TenantFilter = $Request.Query.TenantFilter
$TenantList = Get-Tenants
$Name = 'Best Practice Analyser (All Tenants)'
}
$CippRoot = (Get-Item $PSScriptRoot).Parent.FullName
$TemplatesLoc = Get-ChildItem "$CippRoot\Config\*.BPATemplate.json"
$Templates = $TemplatesLoc | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
$Template.Name
}

$BPAReports = foreach ($Tenant in $TenantList) {
foreach ($Template in $Templates) {
[PSCustomObject]@{
FunctionName = 'BPACollectData'
Tenant = $Tenant.defaultDomainName
Template = $Template
QueueName = '{0} - {1}' -f $Template, $Tenant.defaultDomainName
}
}
$InstanceId = Start-NewOrchestration -FunctionName 'BestPracticeAnalyser_Orchestration' -InputObject $InputObject
Write-Host "Started orchestration with ID = '$InstanceId'"
$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Started retrieving best practice information' -sev Info
$Results = [pscustomobject]@{'Results' = 'Started running analysis' }
}
Write-Host ($Orchestrator | ConvertTo-Json)

$Queue = New-CippQueueEntry -Name $Name -TotalTasks ($BPAReports | Measure-Object).Count
$BPAReports = $BPAReports | Select-Object *, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
$InputObject = [PSCustomObject]@{
Batch = @($BPAReports)
OrchestratorName = 'BPAOrchestrator'
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)

$Results = [pscustomobject]@{'Results' = 'BPA started' }
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $results
Body = $Results
})
45 changes: 29 additions & 16 deletions BestPracticeAnalyser_OrchestrationStarterTimer/run.ps1
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
param($Timer)

if ($env:DEV_SKIP_BPA_TIMER) {
if ($env:DEV_SKIP_BPA_TIMER) {
Write-Host 'Skipping BPA timer'
exit 0
exit 0
}

try {
$CurrentlyRunning = Get-Item 'Cache_BestPracticeAnalyser\CurrentlyRunning.txt' -ErrorAction SilentlyContinue | Where-Object -Property LastWriteTime -GT (Get-Date).AddHours(-24)
if ($CurrentlyRunning) {
$Results = [pscustomobject]@{'Results' = 'Already running. Please wait for the current instance to finish' }
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Attempted to start analysis but an instance was already running.' -sev Info
}
else {
$InstanceId = Start-NewOrchestration -FunctionName 'BestPracticeAnalyser_Orchestration'
Write-Host "Started orchestration with ID = '$InstanceId'"
$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Timer -InstanceId $InstanceId
Write-LogMessage -API 'BestPracticeAnalyser' -message 'Started retrieving best practice information' -sev Info
$Results = [pscustomobject]@{'Results' = 'Started running analysis' }
$TenantList = Get-Tenants

$CippRoot = (Get-Item $PSScriptRoot).Parent.FullName
$TemplatesLoc = Get-ChildItem "$CippRoot\Config\*.BPATemplate.json"
$Templates = $TemplatesLoc | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
$Template.Name
}

$BPAReports = foreach ($Tenant in $TenantList) {
foreach ($Template in $Templates) {
[PSCustomObject]@{
FunctionName = 'BPACollectData'
Tenant = $Tenant.defaultDomainName
Template = $Template
QueueName = '{0} - {1}' -f $Template, $Tenant.defaultDomainName
}
}
Write-Host ($Orchestrator | ConvertTo-Json)
}
catch { Write-Host "BestPracticeAnalyser_OrchestratorStarterTimer Exception $($_.Exception.Message)" }

$Queue = New-CippQueueEntry -Name 'Best Practice Analyser' -TotalTasks ($BPAReports | Measure-Object).Count
$BPAReports = $BPAReports | Select-Object *, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
$InputObject = [PSCustomObject]@{
Batch = @($BPAReports)
OrchestratorName = 'BPAOrchestrator'
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
33 changes: 33 additions & 0 deletions Config/CIPPTenantFeatures.BPATemplate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "CIPP Tenant Feature Licensing",
"style": "Table",
"Fields": [
{
"name": "AssignedPlans",
"UseExistingInfo": false,
"ExtractFields": ["AADPremiumService", "exchange", "SharePoint"],
"FrontendFields": [
{
"name": "Entra ID Premium",
"value": "AssignedPlans.AADPremiumService",
"formatter": "bool"
},
{
"name": "Exchange",
"value": "AssignedPlans.exchange",
"formatter": "bool"
},
{
"name": "SharePoint",
"value": "AssignedPlans.SharePoint",
"formatter": "bool"
}
],
"desc": "Entra ID Premium Status",
"StoreAs": "JSON",
"API": "CIPPFunction",
"Command": "Get-CIPPTenantCapabilities",
"Parameters": {}
}
]
}
10 changes: 3 additions & 7 deletions Modules/CIPPCore/Public/Add-CIPPBPAField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ function Add-CIPPBPAField {
$Table = Get-CippTable -tablename 'cachebpav2'
$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Tenant
$CurrentContentsObject = (Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$BPAName' and PartitionKey eq '$($TenantName.customerId)'")
Write-Host "Adding $FieldName to $BPAName for $Tenant. content is $($CurrentContents.RowKey)"
Write-Information "Adding $FieldName to $BPAName for $Tenant. content is $FieldValue"
if ($CurrentContentsObject.RowKey) {
$CurrentContents = @{}
$CurrentContentsObject.PSObject.Properties | ForEach-Object {
$CurrentContents[$_.Name] = $_.Value
$CurrentContentsObject.PSObject.Properties.Name | ForEach-Object {
$CurrentContents[$_] = $CurrentContentsObject.$_
}
$Result = $CurrentContents
} else {
Expand All @@ -30,16 +30,12 @@ function Add-CIPPBPAField {
$Result["$fieldName"] = [bool]$FieldValue
}
'JSON' {

if ($FieldValue -eq $null) { $JsonString = '{}' } else { $JsonString = (ConvertTo-Json -Depth 15 -InputObject $FieldValue -Compress) }
$Result[$fieldName] = [string]$JsonString
}
'string' {
$Result[$fieldName], [string]$FieldValue
}
'percentage' {

}
}
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
}
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/CippQueue/Invoke-ListCippQueue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Invoke-ListCippQueue {
}

if ($Tasks) {
if ($Tasks.Status -notcontains 'Running' -and ($TaskStatus.Completed + $TaskStatus.Failed) -eq $Queue.TotalTasks) {
if ($Tasks.Status -notcontains 'Running' -and ($TaskStatus.Completed + $TaskStatus.Failed) -ge $Queue.TotalTasks) {
if ($Tasks.Status -notcontains 'Failed') {
$Queue.Status = 'Completed'
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
param($tenant)
function Push-BPACollectData {
<#
.FUNCTIONALITY
Entrypoint
#>
param($Item)

$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $tenant
$CippRoot = (Get-Item $PSScriptRoot).Parent.FullName
$TemplatesLoc = Get-ChildItem "$CippRoot\Config\*.BPATemplate.json"
$Templates = $TemplatesLoc | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
[PSCustomObject]@{
Data = $Template
Name = $Template.Name
Style = $Template.Style
$TenantName = Get-Tenants | Where-Object -Property defaultDomainName -EQ $Item.Tenant
$CippRoot = (Get-Item $PSScriptRoot).Parent.Parent.Parent.Parent.Parent.Parent.FullName
$TemplatesLoc = Get-ChildItem "$CippRoot\Config\*.BPATemplate.json"
$Templates = $TemplatesLoc | ForEach-Object {
$Template = $(Get-Content $_) | ConvertFrom-Json
[PSCustomObject]@{
Data = $Template
Name = $Template.Name
Style = $Template.Style
}
}
}
$Table = Get-CippTable -tablename 'cachebpav2'
$AddRow = foreach ($Template in $templates) {
# Build up the result object that will be passed back to the durable function
$Table = Get-CippTable -tablename 'cachebpav2'

$Template = $Templates | Where-Object -Property Name -EQ -Value $Item.Template
# Build up the result object that will be stored in tables
$Result = @{
Tenant = "$($TenantName.displayName)"
GUID = "$($TenantName.customerId)"
Expand All @@ -33,7 +39,7 @@ $AddRow = foreach ($Template in $templates) {
}
if ($Field.parameters.psobject.properties.name) {
$field.Parameters | ForEach-Object {
Write-Host "Doing: $($_.psobject.properties.name) with value $($_.psobject.properties.value)"
Write-Information "Doing: $($_.psobject.properties.name) with value $($_.psobject.properties.value)"
$paramsField[$_.psobject.properties.name] = $_.psobject.properties.value
}
}
Expand Down Expand Up @@ -69,7 +75,7 @@ $AddRow = foreach ($Template in $templates) {
}
}
} catch {
Write-Host "Error getting $($field.Name) in $($field.api) for $($TenantName.displayName) with GUID $($TenantName.customerId). Error: $($_.Exception.Message)"
Write-Information "Error getting $($field.Name) in $($field.api) for $($TenantName.displayName) with GUID $($TenantName.customerId). Error: $($_.Exception.Message)"
Write-LogMessage -API 'BPA' -tenant $tenant -message "Error getting $($field.Name) for $($TenantName.displayName) with GUID $($TenantName.customerId). Error: $($_.Exception.Message)" -sev Error
$fieldinfo = 'FAILED'
$field.StoreAs = 'string'
Expand Down Expand Up @@ -108,7 +114,6 @@ $AddRow = foreach ($Template in $templates) {
Add-CIPPAzDataTableEntity @Table -Entity $Result -Force
} catch {
Write-LogMessage -API 'BPA' -tenant $tenant -message "Error getting saving data for $($template.Name) - $($TenantName.customerId). Error: $($_.Exception.Message)" -LogData (Get-CippException -Exception $_) -sev Error

}
}
}
Loading

0 comments on commit 3288687

Please sign in to comment.