manifests/collectors/Networking/NetworkWatchers.psd1

#
# GENERATED by scripts/ConvertTo-ScoutCollectorDefinition.ps1 from Modules/Public/InventoryModules/Networking/NetworkWatchers.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.network/networkwatchers'
    )

    ResourceTypeMatching = 'Grouped'

    AdditionalFilter = $null

    FilterPreamble = ''

    RowLoopVariable = '1'

    Preamble = @'
$ResUCount = 1
                # An EMPTY $sub1 is not $null -- the match is empty for any resource whose subscription
                # is outside the requested scope -- and reading .Name off an empty collection throws
                # under StrictMode (AB#5671). Resolved once here, as VirtualMachine.ps1 already does.
                $sub1 = $SUB | Where-Object { $_.Id -eq $1.subscriptionId }
                # The else arm is $null, NOT '': with StrictMode off $sub1.Name on an unmatched ($null)
                # $sub1 evaluated to $null, and the ~110 collectors that still read $sub1.Name directly
                # emit $null here. '' was a silent behaviour change -- the declarative equivalence proof
                # caught it on 11 collectors, and it would have been invisible on the rest (AB#5659).
                $SubscriptionName = if ($sub1) { @($sub1)[0].Name } else { $null }
                $data = $1.PROPERTIES
                # AB#5671: an untagged resource's Resource Graph row OMITS the tags property rather
                # than carrying an empty object, so the raw read throws under StrictMode -- and so
                # does psobject.properties on a $null. The historic '0' sentinel existed only to make
                # the tag loop below run ONCE for an untagged resource, but '0'.Name throws too; an
                # empty tag object runs it once AND emits the identical [string]-cast empty Name/Value.
                $RowTags = Get-AZSCSafeProperty -InputObject $1 -Path 'tags'
                $TagProps = if ($null -ne $RowTags) { $RowTags.psobject.properties } else { $null }
                $Tags = if (![string]::IsNullOrEmpty($TagProps)) { $TagProps } else { [pscustomobject]@{ Name = $null; Value = $null } }
 
                # Get provisioning state
                $provisioningState = if ((Get-AZSCSafeProperty -InputObject $data -Path 'provisioningState' -Enumerate)) { (Get-AZSCSafeProperty -InputObject $data -Path 'provisioningState' -Enumerate) } else { 'Unknown' }
 
                # Get associated flow logs
                $flowLogs = $Resources | Where-Object {
                    $_.TYPE -eq 'Microsoft.Network/networkWatchers/flowLogs' -and
                    $_.id -like "$($1.id)/*"
                }
                $flowLogCount = @($flowLogs).Count
                $flowLogNames = @()
                if ($flowLogs) {
                    foreach ($fl in $flowLogs) {
                        $flowLogNames += $fl.NAME
                    }
                }
                $flowLogStr = if ($flowLogNames.Count -gt 0) { $flowLogNames -join ', ' } else { 'None' }
 
                # Get connection monitors
                $connMonitors = $Resources | Where-Object {
                    $_.TYPE -eq 'Microsoft.Network/networkWatchers/connectionMonitors' -and
                    $_.id -like "$($1.id)/*"
                }
                $connMonitorCount = @($connMonitors).Count
                $connMonitorNames = @()
                if ($connMonitors) {
                    foreach ($cm in $connMonitors) {
                        $connMonitorNames += $cm.NAME
                    }
                }
                $connMonitorStr = if ($connMonitorNames.Count -gt 0) { $connMonitorNames -join ', ' } else { 'None' }
 
                # Check for packet captures (typically short-lived, might be 0)
                $packetCaptures = $Resources | Where-Object {
                    $_.TYPE -eq 'Microsoft.Network/networkWatchers/packetCaptures' -and
                    $_.id -like "$($1.id)/*"
                }
                $packetCaptureCount = @($packetCaptures).Count
'@


    AdditionalRowLoops = @()

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

    Fields = @(
        @{
            Name = 'ID'
            Expression = '$1.id'
        }
        @{
            Name = 'Subscription'
            Expression = '$SubscriptionName'
        }
        @{
            Name = 'Resource Group'
            Expression = '$1.RESOURCEGROUP'
        }
        @{
            Name = 'Network Watcher Name'
            Expression = '$1.NAME'
        }
        @{
            Name = 'Location'
            Expression = '$1.LOCATION'
        }
        @{
            Name = 'Provisioning State'
            Expression = '$provisioningState'
        }
        @{
            Name = 'Flow Logs Count'
            Expression = '$flowLogCount'
        }
        @{
            Name = 'Flow Logs'
            Expression = '$flowLogStr'
        }
        @{
            Name = 'Connection Monitors Count'
            Expression = '$connMonitorCount'
        }
        @{
            Name = 'Connection Monitors'
            Expression = '$connMonitorStr'
        }
        @{
            Name = 'Packet Captures Count'
            Expression = '$packetCaptureCount'
        }
        @{
            Name = 'Capabilities'
            Expression = '''IP Flow Verify, Next Hop, VPN Troubleshoot, NSG Diagnostics, Topology, Connection Troubleshoot'''
        }
        @{
            Name = 'Resource U'
            Expression = '$ResUCount'
        }
        @{
            Name = 'Tag Name'
            Expression = '[string]$Tag.Name'
        }
        @{
            Name = 'Tag Value'
            Expression = '[string]$Tag.Value'
        }
    )

    Export = @{
        WorksheetName = 'Network Watchers'
        TableNamePrefix = 'NetworkWatchersTable_'
        Columns = @(
            'Subscription'
            'Resource Group'
            'Network Watcher Name'
            'Location'
            'Provisioning State'
            'Flow Logs Count'
            'Flow Logs'
            'Connection Monitors Count'
            'Connection Monitors'
            'Packet Captures Count'
            'Capabilities'
            'Resource U'
        )
        TagColumns = @(
            'Tag Name'
            'Tag Value'
        )
        TagColumnsBefore = 'Resource U'
        NumberFormat = '0'
        ConditionalText = @()
    }

    SourceCollector = 'Modules/Public/InventoryModules/Networking/NetworkWatchers.ps1'
}