manifests/collectors/Monitor/ResourceDiagnosticSettings.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Monitor/ResourceDiagnosticSettings.ps1 (AB#5660).
# Field expressions are copied verbatim from the original collector and evaluate in an
# equivalent scope -- see docs/design/decisions/declarative-collectors.md.
# Review before trusting; regenerate rather than hand-patch if the source collector changes.
#
@{
    ResourceTypes = @(
        'microsoft.insights/diagnosticsettings'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = $null

    FilterPreamble = ''

    RowLoopVariable = '1'

    Preamble = @'
$ResUCount = 1
            $sub1 = $SUB | Where-Object { $_.Id -eq $1.subscriptionId }
            $data = $1.PROPERTIES
            $Tags = if (![string]::IsNullOrEmpty($1.tags.psobject.properties)) { $1.tags.psobject.properties } else { '0' }
 
            # Parent resource name from ID (diagnostic settings are child resources)
            $parentResourceId = $1.id -replace '/providers/microsoft.insights/diagnosticsettings/[^/]+$', ''
            $parentResourceName = ($parentResourceId -split '/')[-1]
            $parentResourceType = if ($parentResourceId -match '/providers/([^/]+/[^/]+)/') { $matches[1] } else { 'Unknown' }
 
            # Enabled log categories
            $enabledLogs = @()
            $disabledLogs = @()
            if ($data.logs) {
                foreach ($log in $data.logs) {
                    if ($log.enabled) { $enabledLogs += $log.category } else { $disabledLogs += $log.category }
                }
            }
 
            # Enabled metric categories
            $enabledMetrics = @()
            if ($data.metrics) {
                foreach ($metric in $data.metrics) {
                    if ($metric.enabled) { $enabledMetrics += $metric.category }
                }
            }
 
            # Destinations
            $destLAW = if ($data.workspaceId) { ($data.workspaceId -split '/')[-1] } else { 'None' }
            $destStorage = if ($data.storageAccountId) { ($data.storageAccountId -split '/')[-1] } else { 'None' }
            $destEventHub = if ($data.eventHubName) { $data.eventHubName } elseif ($data.eventHubAuthorizationRuleId) { ($data.eventHubAuthorizationRuleId -split '/')[-3] } else { 'None' }
            $destPartner = if ($data.marketplacePartnerId) { $data.marketplacePartnerId } else { 'None' }
'@


    AdditionalRowLoops = @()

    TagLoop = @{
        Variable = 'Tag'
        Source = '$Tags'
        Preamble = ''
    }

    Fields = @(
        @{
            Name = 'ID'
            Expression = '$1.id'
        }
        @{
            Name = 'Subscription'
            Expression = '$sub1.Name'
        }
        @{
            Name = 'Resource Group'
            Expression = '$1.RESOURCEGROUP'
        }
        @{
            Name = 'Diagnostic Setting Name'
            Expression = '$1.NAME'
        }
        @{
            Name = 'Parent Resource Name'
            Expression = '$parentResourceName'
        }
        @{
            Name = 'Parent Resource Type'
            Expression = '$parentResourceType'
        }
        @{
            Name = 'Enabled Log Categories'
            Expression = '$enabledLogs -join '', '''
        }
        @{
            Name = 'Disabled Log Categories'
            Expression = '$disabledLogs -join '', '''
        }
        @{
            Name = 'Enabled Metric Categories'
            Expression = '$enabledMetrics -join '', '''
        }
        @{
            Name = 'Destination: Log Analytics'
            Expression = '$destLAW'
        }
        @{
            Name = 'Destination: Storage'
            Expression = '$destStorage'
        }
        @{
            Name = 'Destination: Event Hub'
            Expression = '$destEventHub'
        }
        @{
            Name = 'Destination: Partner'
            Expression = '$destPartner'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
        @{
            Name = 'Tag Name'
            Expression = '[string]$Tag.Name'
        }
        @{
            Name = 'Tag Value'
            Expression = '[string]$Tag.Value'
        }
    )

    Export = @{
        WorksheetName = 'Resource Diagnostic Settings'
        TableNamePrefix = 'ResDiagSettTable_'
        Columns = @(
            'Subscription'
            'Resource Group'
            'Diagnostic Setting Name'
            'Parent Resource Name'
            'Parent Resource Type'
            'Enabled Log Categories'
            'Disabled Log Categories'
            'Enabled Metric Categories'
            'Destination: Log Analytics'
            'Destination: Storage'
            'Destination: Event Hub'
            'Destination: Partner'
            'Resource U'
        )
        TagColumns = @()
        TagColumnsBefore = $null
        NumberFormat = '0'
        ConditionalText = @()
    }

    SourceCollector = 'Modules/Public/InventoryModules/Monitor/ResourceDiagnosticSettings.ps1'
}