Create Discovery for Agent via API

Hey Thwackers,

I'm looking to do targeted re-discoveries of some of our server nodes automatically via the API which includes both SNMPv2c, and agent nodes. The primary goal is to rediscover and add new volumes, however another goal as well would be to initially add volumes and interfaces once the nodes get created automatically via the API as well (or an agent is registered).

All the documentation is essentially for discovery of SNMP or WMI nodes. Does anyone happen to know how to adjust the XML for the script up on GitHub to accommodate for Agents? In my own digging, I've taken a look at some of the XML from creating a discovery via the web UI and have been attempting to inject it into the CorePluginConfiguration (with little success).

What I found are these settings but I'm not sure where they may go or which ones are required and the appropriate syntax either (or better yet... if this is even technically supported via the API yet)


Any and all help and/or suggestions appreciated, thanks!

  • The discovery process is the same for all nodes irrespective of the polling method. The purpose of 'Check existing nodes polled by agent' in the discovery workflow is to keep all or a subset of agents updated. It has been a while since I last looked at this but if I remember the easiest way I have found to check what XML is expected is to 1st create the profile in the UI ad then check out the PluginConfigurations field in the DiscoveryProfiles table directly in the database, This contains the <DiscoveryPluginConfigurationBase> element which should show what you are looking for.

    This KB may also help

    Here is an example of the XML element for reference

    <DiscoveryPluginConfigurationBase xmlns:d2p1="" i:type="d2p1:CoreDiscoveryPluginConfiguration">
    				<d2p1:AgentsAddresses xmlns:d3p1=""/>
    				<d2p1:AgentsFilterQuery>Nodes.IsServer = 'True'</d2p1:AgentsFilterQuery>
    				<d2p1:AutoImportVolumeTypes xmlns:d3p1="">
    				<d2p1:BulkList xmlns:d3p1=""/>
    				<d2p1:Credentials i:nil="true"/>
    				<d2p1:SharedCredentials xmlns:d3p1="">

  • Thank you  for the tips! I'll give this a whirl and spend some more time digging into it.

Reply Children
  • I think I've hit a wall here. I've thrown quite a bit at attempting the XML markup expected and nothing I seem to do will work. Some values I notice don't show up the same once the configuration is invoked from the context created.. For example we set the property <WmiRetriesCount> and <WmiRetryIntervalMiliseconds>, however they get converted to <WmiRetries> and <WmiRetryInterval> when invoking creation of the configuration. Attempting to create the configuration with the latter results in a failure. So while digging into the database is quite useful to help understand some of it -- it doesn't provide much insight in the way of determining the appropriate XML markup and properties to get this going. Disappointed

    I've got a mock script put together (patched together from the various different sources of the API discoveries) and I'm trying to get it to be super simple for now until I get it working.

    Unfortunately I cannot make sense of this and there's very little guidance / documentation around it. The script below works just fine and appears to run a discovery against SNMP nodes but so far no dice with getting any agent settings in there.

    The values for the agent settings always show up like so still regardless of how I've put it together.

    Any help appreciated. Thanks

    <d2p1:AgentsAddresses xmlns:d3p1="" />
    <d2p1:AgentsFilterDefinition i:nil="true" />
    <d2p1:AgentsFilterQuery i:nil="true" />

    <# finding the default values SQL query:
    SELECT dp.Name, dp.IsHidden, dp.IsAutoImport, dp.Status, dp.StatusDescription
    , SUBSTRING(dp.PluginConfigurations, CHARINDEX('PreferredPollingMethod', dp.PluginConfigurations) + 23, 4) AS [PreferredPollingMethod]
    , SUBSTRING(dp.PluginConfigurations, CHARINDEX('DiscoverAgentNodes', dp.PluginConfigurations) + 19, 5) AS [DiscoverAgentNodes]
    , dp.PluginConfigurations
    FROM SolarWindsOrion.dbo.DiscoveryProfiles AS dp
    WHERE ( dp.Name IS NOT NULL AND dp.Name != '' )
    ORDER BY dp.Name DESC
    Import-Module -Name SwisPowerShell
    $swis = Connect-Swis -Hostname 'hostname' -Username 'username' -Password 'password'
    $ip = 'x.x.y.y'
    $credentialsId = '0'
    $engindId = '0'
    $CorePluginConfigurationContext = ([xml]"
    <CorePluginConfigurationContext xmlns='' xmlns:i=''>
        <ActiveDirectoryList />
        <AddressRange />
        <AgentsAddresses xmlns:a=''>
        <AutoImportVolumeTypes xmlns=''>
        <SubnetList />
        <WMICredentials />
    $CorePluginConfiguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext)
    $InterfacesPluginConfigurationContext = ([xml]"
    <InterfacesDiscoveryPluginContext xmlns='' xmlns:a=''>
            <a:string>{'Prop': 'Name', 'Op': 'Regex', 'Val': '^Eth.*'}</a:string>
    $InterfacesPluginConfiguration = Invoke-SwisVerb $swis Orion.NPM.Interfaces CreateInterfacesPluginConfiguration @($InterfacesPluginConfigurationContext)
    $StartDiscoveryContext = ([xml]"
    <StartDiscoveryContext xmlns='' xmlns:i=''>
    	<Name>Script Discovery $([DateTime]::Now)</Name>
    $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)
    $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"}
    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."