I need some help with the <AutoImportExpressionFilter> xml structure for adding interface nodes during discovery based on a regex filter. Is there someone that could provide an update to the syntax in my script below? I have tried a few different ways however nothing seems to change in the interface discovery settings on the console. Thanks!
# Swis connection info
$OrionServer = "localhost"
# Discovery parameters
$ipAddresses = @("10.99.248.10","10.99.248.11")
$ipList = @()
foreach ($ip in $ipAddresses) {
$ipList += '<IpAddress><Address>{0}</Address></IpAddress>' -f ($ip)
}
$snmpv3_network = "Network v3"
$snmpv3_voice = "Voice"
$engindId = 1
$DeleteProfileAfterDiscoveryCompletes = "false"
$swis = Connect-Swis $OrionServer -Trusted
# Get the ID of the named SNMPv3 credential
$snmpv3_network_id = Get-SwisData $swis "SELECT ID FROM Orion.Credential WHERE Name=@name" @{name = $snmpv3_network}
$snmpv3_voice_id = Get-SwisData $swis "SELECT ID FROM Orion.Credential WHERE Name=@name" @{name = $snmpv3_voice}
$CorePluginConfigurationContext = ([xml]"
<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<BulkList>
$ipList
</BulkList>
<Credentials>
<SharedCredentialInfo>
<CredentialID>$snmpv3_network_id</CredentialID>
<Order>1</Order>
</SharedCredentialInfo>
<SharedCredentialInfo>
<CredentialID>$snmpv3_voice_id</CredentialID>
<Order>2</Order>
</SharedCredentialInfo>
</Credentials>
<WmiRetriesCount>1</WmiRetriesCount>
<WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
</CorePluginConfigurationContext>
").DocumentElement
$InterfacesPluginConfigurationContext = ([xml]"
<InterfacesDiscoveryPluginContext xmlns='http://schemas.solarwinds.com/2008/Interfaces'
xmlns:a='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>
<AutoImportStatus>
<a:string>Up</a:string>
<a:string>Down</a:string>
<a:string>Shutdown</a:string>
</AutoImportStatus>
<AutoImportVirtualTypes>
<a:string>Virtual</a:string>
</AutoImportVirtualTypes>
<AutoImportVlanPortTypes>
<a:string>Trunk</a:string>
</AutoImportVlanPortTypes>
<AutoImportExpressionFilter>
<a:string>{'Prop': 'Alias', 'Op': 'Regex', 'Val': '.*Nortel.*'}</a:string>
</AutoImportExpressionFilter>
<UseDefaults>false</UseDefaults>
</InterfacesDiscoveryPluginContext>
").DocumentElement
$InterfacesPluginConfiguration = Invoke-SwisVerb $swis Orion.NPM.Interfaces CreateInterfacesPluginConfiguration @($InterfacesPluginConfigurationContext)
$StartDiscoveryContext = ([xml]"
<StartDiscoveryContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
<Name>Script Discovery $([DateTime]::Now)</Name>
<EngineId>$engindId</EngineId>
<JobTimeoutSeconds>3600</JobTimeoutSeconds>
<SearchTimeoutMiliseconds>2000</SearchTimeoutMiliseconds>
<SnmpTimeoutMiliseconds>2000</SnmpTimeoutMiliseconds>
<SnmpRetries>2</SnmpRetries>
<RepeatIntervalMiliseconds>1500</RepeatIntervalMiliseconds>
<SnmpPort>161</SnmpPort>
<HopCount>0</HopCount>
<PreferredSnmpVersion>SNMP3</PreferredSnmpVersion>
<DisableIcmp>false</DisableIcmp>
<AllowDuplicateNodes>false</AllowDuplicateNodes>
<IsAutoImport>true</IsAutoImport>
<IsHidden>$DeleteProfileAfterDiscoveryCompletes</IsHidden>
<PluginConfigurations>
<PluginConfiguration>
<PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
<PluginConfigurationItem>$($InterfacesPluginConfigurationContext.InnerXml)</PluginConfigurationItem>
</PluginConfiguration>
</PluginConfigurations>
</StartDiscoveryContext>
").DocumentElement
$DiscoveryProfileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText
Write-Host -NoNewline "Discovery profile #$DiscoveryProfileID running..."
# Wait until the discovery completes
do {
Write-Host -NoNewline "."
Start-Sleep -Seconds 1
$Status = Get-SwisData $swis "SELECT Status FROM Orion.DiscoveryProfiles WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID}
} while ($Status -eq 1)
# If $DeleteProfileAfterDiscoveryCompletes is true, then the profile will be gone at this point, but we can still get the result from Orion.DiscoveryLogs
$Result = Get-SwisData $swis "SELECT Result, ResultDescription, ErrorMessage, BatchID FROM Orion.DiscoveryLogs WHERE ProfileID = @profileId" @{profileId = $DiscoveryProfileID}
# Print the outcome
switch ($Result.Result) {
0 {"Unknown"}
1 {"InProgress"}
2 {"Finished"}
3 {"Error"}
4 {"NotScheduled"}
5 {"Scheduled"}
6 {"NotCompleted"}
7 {"Canceling"}
8 {"ReadyForImport"}
}
$Result.ResultDescription
$Result.ErrorMessage
if ($Result.Result -eq 2) { # if discovery completed successfully
# Find out what objects were discovered
$Discovered = Get-SwisData $swis "SELECT EntityType, DisplayName, NetObjectID FROM Orion.DiscoveryLogItems WHERE BatchID = @batchId" @{batchId = $Result.BatchID}
"$($Discovered.Count) items imported."
$Discovered
}