manifests/collectors/Monitor/MetricAlertRules.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Monitor/MetricAlertRules.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/metricalerts'
    )

    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'}
 
                # Parse criteria
                $criteria = $data.criteria
                $criteriaType = if ($criteria.'odata.type') {
                    $criteria.'odata.type' -replace 'Microsoft.Azure.Monitor.', ''
                } else { 'SingleResourceMultipleMetricCriteria' }
 
                # Parse conditions
                $conditions = @()
                if ($criteria.allOf) {
                    foreach ($condition in $criteria.allOf) {
                        $metricName = $condition.metricName
                        $operator = $condition.operator
                        $threshold = $condition.threshold
                        $timeAggregation = $condition.timeAggregation
                        $conditions += "$metricName $operator $threshold ($timeAggregation)"
                    }
                }
                $conditionsStr = if ($conditions.Count -gt 0) { $conditions -join '; ' } else { 'N/A' }
 
                # Parse target resources
                $targetResources = @()
                if ($data.scopes) {
                    foreach ($scope in $data.scopes) {
                        $resourceName = ($scope -split '/')[-1]
                        $targetResources += $resourceName
                    }
                }
                $targetStr = if ($targetResources.Count -gt 0) { $targetResources -join ', ' } else { 'N/A' }
 
                # Parse action groups
                $actionGroups = @()
                if ($data.actions) {
                    foreach ($action in $data.actions) {
                        if ($action.actionGroupId) {
                            $agName = ($action.actionGroupId -split '/')[-1]
                            $actionGroups += $agName
                        }
                    }
                }
                $actionGroupStr = if ($actionGroups.Count -gt 0) { $actionGroups -join ', ' } else { 'None' }
 
                # Get severity
                $severity = switch ($data.severity) {
                    0 { 'Critical' }
                    1 { 'Error' }
                    2 { 'Warning' }
                    3 { 'Informational' }
                    4 { 'Verbose' }
                    default { $data.severity }
                }
 
                # Parse evaluation frequency and window
                $evaluationFrequency = if ($data.evaluationFrequency) {
                    $data.evaluationFrequency
                } else { 'PT1M' }
                $windowSize = if ($data.windowSize) {
                    $data.windowSize
                } else { 'PT5M' }
 
                # Get enabled status
                $enabled = if ($data.enabled -eq $true) { 'Enabled' } else { 'Disabled' }
                $autoMitigate = if ($data.autoMitigate -eq $true) { 'Yes' } else { 'No' }
'@


    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 = 'Alert Rule Name'
            Expression = '$1.NAME'
        }
        @{
            Name = 'Description'
            Expression = 'if ($data.description) { $data.description } else { ''N/A'' }'
        }
        @{
            Name = 'Location'
            Expression = '$1.LOCATION'
        }
        @{
            Name = 'Status'
            Expression = '$enabled'
        }
        @{
            Name = 'Severity'
            Expression = '$severity'
        }
        @{
            Name = 'Criteria Type'
            Expression = '$criteriaType'
        }
        @{
            Name = 'Conditions'
            Expression = '$conditionsStr'
        }
        @{
            Name = 'Target Resources'
            Expression = '$targetStr'
        }
        @{
            Name = 'Target Resource Type'
            Expression = 'if ($data.targetResourceType) { $data.targetResourceType } else { ''N/A'' }'
        }
        @{
            Name = 'Evaluation Frequency'
            Expression = '$evaluationFrequency'
        }
        @{
            Name = 'Window Size'
            Expression = '$windowSize'
        }
        @{
            Name = 'Auto Mitigate'
            Expression = '$autoMitigate'
        }
        @{
            Name = 'Action Groups'
            Expression = '$actionGroupStr'
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
        @{
            Name = 'Tag Name'
            Expression = '[string]$Tag.Name'
        }
        @{
            Name = 'Tag Value'
            Expression = '[string]$Tag.Value'
        }
    )

    Export = @{
        WorksheetName = 'Metric Alerts'
        TableNamePrefix = 'MetricAlertsTable_'
        Columns = @(
            'Subscription'
            'Resource Group'
            'Alert Rule Name'
            'Description'
            'Location'
            'Status'
            'Severity'
            'Criteria Type'
            'Conditions'
            'Target Resources'
            'Target Resource Type'
            'Evaluation Frequency'
            'Window Size'
            'Auto Mitigate'
            'Action Groups'
            'Resource U'
        )
        TagColumns = @(
            'Tag Name'
            'Tag Value'
        )
        TagColumnsBefore = 'Resource U'
        NumberFormat = '0'
        ConditionalText = @()
    }

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