solarwinds / OrionSDK

SDK for the SolarWinds Orion platform, including tools, documentation, and samples in PowerShell, C#, Go, Perl, and Java.
https://thwack.com/OrionSDK
Apache License 2.0
401 stars 142 forks source link

Discovery - Interface Selection (PowerShell) #218

Open packetmagic opened 4 years ago

packetmagic commented 4 years ago

Setting the InterfacesDiscoveryPluginContext doesn't appear to actually do anything. The discovery works but does not select interfaces based on the option set in InterfacesDiscoveryPluginContext.

When I edit the discovery in the GUI the interface selection settings do not match those set in the code.

Running 2019.4

$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>
    </AutoImportStatus>
    <AutoImportVirtualTypes>
        <a:string>Virtual</a:string>
        <a:string>Physical</a:string>
    </AutoImportVirtualTypes>
    <AutoImportVlanPortTypes>
        <a:string>Trunk</a:string>
    </AutoImportVlanPortTypes>
    <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>1</SnmpRetries>
    <RepeatIntervalMiliseconds>1500</RepeatIntervalMiliseconds>
    <SnmpPort>161</SnmpPort>
    <HopCount>0</HopCount>
    <PreferredSnmpVersion>SNMP2c</PreferredSnmpVersion>
    <DisableIcmp>true</DisableIcmp>
    <AllowDuplicateNodes>false</AllowDuplicateNodes>
    <IsAutoImport>true</IsAutoImport>
    <IsHidden>$DeleteProfileAfterDiscoveryCompletes</IsHidden>
    <PluginConfigurations>
        <PluginConfiguration>
            <PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
            <PluginConfigurationItem>$($InterfacesPluginConfiguration.InnerXml)</PluginConfigurationItem>
        </PluginConfiguration>
    </PluginConfigurations>
</StartDiscoveryContext>
").DocumentElement
cberg2048 commented 4 years ago

I am experiencing the same issue in Python.

` def createDiscovery(network, networks, number): orion_engine_id = 2 # Designate a specific engine to complete discovery snmpDiscoveryCreds = getCreds()

Select current subnet for discovery

district = networks[network][2]
subnet = list(networks[network]) 

# If CIDR
if networks[network][3]:
    sub = {
        'SubnetIP'   :  networks[network][0],
        'SubnetMask' :  networks[network][1]   
    }
    corePluginContext = {
    'Subnets'                       :   [sub],
    'Credentials'                   :   snmpDiscoveryCreds,
    'WmiRetriesCount'               :   0,
    'WmiRetryIntervalMiliseconds'   :   1000,
    'IsDiscoveryForVimEnabled'      :   False
    }
# If range
else:
    iprange = {
        'StartAddress'   :  networks[network][0],
        'EndAddress' :  networks[network][1]   
    }
    corePluginContext = {
    'IpRanges'                      :   [iprange],
    'Credentials'                   :   snmpDiscoveryCreds,
    'WmiRetriesCount'               :   0,
    'WmiRetryIntervalMiliseconds'   :   1000,
    'IsDiscoveryForVimEnabled'      :   False
    }

interfacePluginContext = {
'AutoImportStatus': ['Up'] # Also available: Down, Shutdown
}

# Create core PluginConfigurationItem for Orion
corePluginConfig = swis.invoke('Orion.Discovery', 'CreateCorePluginConfiguration', corePluginContext)

# Create interface PluginConfigurationItem for Orion
interfacePluginConfig = swis.invoke('Orion.NPM.Interfaces', 'CreateInterfacesPluginConfiguration', interfacePluginContext)

# Assign name to profile
if number < 10:
    name = '00'+ str(number) +' - ' + district + ' - ' + network
elif number < 100:
    name = '0'+ str(number) +' - ' + district + ' - ' + network
else:
    name = str(number) +' - ' + district + ' - ' + network
print(name)
# Generate profile
discoveryProfile = {
    'Name': name,
    'EngineID': orion_engine_id,
    'JobTimeoutSeconds': 28800,
    'SearchTimeoutMiliseconds': 5000,
    'SnmpTimeoutMiliseconds': 5000,
    'SnmpRetries': 2,
    'RepeatIntervalMiliseconds': 1800,
    'SnmpPort': 161,
    'HopCount': 0,
    'PreferredSnmpVersion': 'SNMP2c',
    'DisableIcmp': True,
    'AllowDuplicateNodes': False,
    'IsAutoImport': True,
    'IsHidden': False,
    'PluginConfigurations': [{'PluginConfigurationItem': corePluginConfig}, {'PluginConfigurationItem': interfacePluginConfig}]
}
return discoveryProfile`
markatdxb commented 4 years ago

Apparently this is a bug introduced in 2019.4 version. We used this feature and worked well in 2019.2

bonickle commented 3 years ago
I know this is old but I working on a discovery script for solarwinds and was stuck on this same issue all day. The command actually works fine, I discovered me, you and bunch of other people were just setting up the xml wrong. If you want to pass multiple plugin configurations it needs to look like the following:

     <PluginConfigurations>
    <PluginConfiguration>
        <PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
    </PluginConfiguration>
    <PluginConfiguration>
        <PluginConfigurationItem>$($InterfacesPluginConfiguration.InnerXml)</PluginConfigurationItem>
    </PluginConfiguration>
</PluginConfigurations>