SWIS: Node Rediscovery Process based on Engine ID

Hi Folks,

I am trying to accomplish solarwinds node rediscovery process via SWIS. if i want to run the rediscovery for single/few nodes then it is running completely fine with below script. 

$username = "xxxx"
$password = ConvertTo-SecureString "xxxxx" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $password)
$swis = Connect-Swis -Credential $creds -Hostname polling_server_name

$CorePluginConfigurationContext = ([xml]"
<CorePluginConfigurationContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>
     <BulkList>
          <IpAddress>
               <Address>10.72.14.72</Address>
          </IpAddress>
          <IpAddress>
               <Address>10.72.156.33</Address>
          </IpAddress>
     </BulkList>
     <Credentials>
          <SharedCredentialInfo>
               <CredentialID>28</CredentialID>
               <Order>1</Order>
          </SharedCredentialInfo>
          <SharedCredentialInfo>
               <CredentialID>20</CredentialID>
               <Order>2</Order>
          </SharedCredentialInfo>
     </Credentials>
     <WmiRetriesCount>1</WmiRetriesCount>
     <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
</CorePluginConfigurationContext>
").DocumentElement

$CorePluginConfiguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext)

$EngineID = 1
$DeleteProfileAfterDiscoveryCompletes = "false"

$StartDiscoveryContext = ([xml]"
<StartDiscoveryContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>
     <Name>Script Discovery $([DateTime]::Now)</Name>
     <EngineId>$EngineID</EngineId>
     <JobTimeoutSeconds>3600</JobTimeoutSeconds>
     <SearchTimeoutMiliseconds>2500</SearchTimeoutMiliseconds>
     <SnmpTimeoutMiliseconds>2500</SnmpTimeoutMiliseconds>
     <SnmpRetries>1</SnmpRetries>
     <RepeatIntervalMiliseconds>2500000</RepeatIntervalMiliseconds>
     <SnmpPort>161</SnmpPort>
     <HopCount>0</HopCount>
     <PreferredSnmpVersion>SNMP2c</PreferredSnmpVersion>
     <DisableIcmp>false</DisableIcmp>
     <AllowDuplicateNodes>false</AllowDuplicateNodes>
     <IsAutoImport>false</IsAutoImport>
     <IsHidden>false</IsHidden>
     <PluginConfigurations>
          <PluginConfiguration>
               <PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
          </PluginConfiguration>
     </PluginConfigurations>
</StartDiscoveryContext>
").DocumentElement

$DiscoveryProfileID = ( Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext) ).InnerText

Write-Verbose "$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss'):`t 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) {
1 { "InProgress" }
2 { "Finished" }
3 { "Error" }
4 { "NotScheduled" }
5 { "Scheduled" }
6 { "NotCompleted" }
7 { "Canceling" }
8 { "ReadyForImport" }
}
$Result.ResultDescription
$Result.ErrorMessage

However, if i want to provide a moduler solution to admins to trigger rediscovery on particular polling engine for all its associated Nodes, then i am following below steps:

  1. Connect to SWIS and feed step 2,3,4 info into above script. 
  2. Find the engine ID
  3. All the nodes which are getting polled by that Engine ID
  4. All credential info which is associated with the particular Node. 
  5. then rest of below XML thing. 

Currently I am unable to feed all the info into the above script. Any help related to the same will be helpful, kindly assist. 

Parents
  • It reads like you are trying to build a function you can just have people call.  Something like this?

    Start-SwisDiscovery -SwisConnection $Swis -PollingEngine $PollingEngineName

    Is that generally what you are thinking?

    It's completely possible, but that would be a very bad idea as your environment grew larger.  There's every real chance that it would time out since a Network Discovery is not a light function - computationally speaking.

    I'd only use Network Discovery if I needed to get a list of child elements that I'm not currently monitoring (interfaces, volumes, etc.).  If you just want to do a simple rediscovery (refresh the information about the device), you could just decrease the Rediscovery Interval (in Orion.Nodes) for certain devices.

    I guess the larger question is: what are you actually trying to accomplish by offering this function to other users?

  • Hi KMSigma,

    Yes, this is exactly what i want to accomplish to enable my team to rediscover all the nodes and its resources on defined protocols (Like particular set of interfaces and volumes.)

    They are spending a lot of time to run manual discovery and by selecting required resources to be added into polling for each device. so we want to build something which leverage them to trigger discovery on per polling engine basis or by a set of IP ranges. 

Reply
  • Hi KMSigma,

    Yes, this is exactly what i want to accomplish to enable my team to rediscover all the nodes and its resources on defined protocols (Like particular set of interfaces and volumes.)

    They are spending a lot of time to run manual discovery and by selecting required resources to be added into polling for each device. so we want to build something which leverage them to trigger discovery on per polling engine basis or by a set of IP ranges. 

Children
  • Hello There, 

    I have figured out complete working script now. sharing here as if can help others as well. Kindly test it in your Dev environment first before running it.

    #Connecting to Solarwinds console
    Write-Host "Welcome to SolarWinds Nodes Rediscovery Process !!!" -ForegroundColor Black -BackgroundColor Green
    Start-Sleep -s 2
    Write-Host "Follow step by step process to carry out Node Rediscovery." -ForegroundColor Black -BackgroundColor White
    Start-Sleep -s 2
    Write-Host "Kindly Provide UserName and password to connect SolarWinds Web Console"  -ForegroundColor Black -BackgroundColor Green
    Start-Sleep -s 2
    $username = Read-Host "Enter UserName" 
    $password = Read-Host "Enter your Password" -AsSecureString 
    $creds = New-Object System.Management.Automation.PSCredential ($username, $password)
    $HostName = Read-Host "Enter Solarwinds Main polling engine details (Name OR IP)"
    $swis = Connect-Swis -Credential $creds -Hostname $HostName
    
    $Engines = @(Get-SwisData $swis 'SELECT e.EngineID, e.ServerName, e.IP FROM [Orion].[Engines] e')
    #$Engines
    $Engines | Out-GridView -title "Below are the solarwinds Polling Engines are available in your Environment:-" #Display polling Engines result in the new window. 
    
    [int]$Provided_Engine_ID = Read-Host 'Provide Engine ID (Number only) for which the Re-discovery need to be run'  #(First show user how many Engine ID's are there and then ask them which one to chose to run the discvoery for) >> once selected
    
    # then we can start rest of discovery based on the provided EngineID. 
    $Nodes = @(Get-SwisData $swis "SELECT nd.IP_Address FROM [Orion].[Nodes] nd where nd.engineid = $Provided_Engine_ID")
    
    $Cred = @(Get-SwisData $swis "SELECT distinct cred.ID from Orion.[Credential] as cred where CredentialOwner ='Orion' ")
    
    #Get all engine info put into array
    
    $ipList = @()
    $NdCred = @()
    
    foreach ($ip in $Nodes) {  
            $ipList += '<IpAddress><Address>{0}</Address></IpAddress>' -f ($ip)
            }
            $order = 0        
            foreach ($cd in $Cred) {
            $order = $order+1
                     $NdCred +='<SharedCredentialInfo><CredentialID>{0}</CredentialID><Order>' -f ($cd) +$order+'</Order></SharedCredentialInfo>'
                     }
    #Feed all the above collected info into below Core Plugin XML which will be used within discovery. 
    
    $CorePluginConfigurationContext = ([xml]"
    <CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
       <BulkList>
        $ipList         
    </BulkList>
    <IpRanges></IpRanges>
    <Subnets></Subnets>
        <Credentials>
            $NdCred
         </Credentials>
        <WmiRetriesCount>1</WmiRetriesCount>
        <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
    </CorePluginConfigurationContext>
    ").DocumentElement
    
    #Invode Discovery by calling the core plugin info. 
    $CorePluginConfiguration = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($CorePluginConfigurationContext)
    
    $EngineID = $Provided_Engine_ID
    $DeleteProfileAfterDiscoveryCompletes = "false"
    
    #Set up discovery settings 
    $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>$EngineID</EngineId>
    <JobTimeoutSeconds>3600</JobTimeoutSeconds>
    <SearchTimeoutMiliseconds>2500</SearchTimeoutMiliseconds>
    <SnmpTimeoutMiliseconds>2500</SnmpTimeoutMiliseconds>
    <SnmpRetries>1</SnmpRetries>
    <RepeatIntervalMiliseconds>2500000</RepeatIntervalMiliseconds>
    <SnmpPort>161</SnmpPort>
    <HopCount>0</HopCount>
    <PreferredSnmpVersion>SNMP2c</PreferredSnmpVersion>
    <DisableIcmp>false</DisableIcmp>
    <AllowDuplicateNodes>false</AllowDuplicateNodes>
    <IsAutoImport>false</IsAutoImport>
    <IsHidden>false</IsHidden>
    <PluginConfigurations>
                 <PluginConfiguration>
           <PluginConfigurationItem>$($CorePluginConfiguration.InnerXml)</PluginConfigurationItem>
    </PluginConfiguration>
    </PluginConfigurations>
    </StartDiscoveryContext>
    ").DocumentElement
    
    # Creating discovery profile into Orion console. 
    $DiscoveryProfileID = (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($StartDiscoveryContext)).InnerText
    
    Write-Verbose "$(Get-Date -Format 'dd/MM/yyyy HH:mm:ss'):`t 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) {
    1 { "InProgress" }
    2 { "Finished" }
    3 { "Error" }
    4 { "NotScheduled" }
    5 { "Scheduled" }
    6 { "NotCompleted" }
    7 { "Canceling" }
    8 { "ReadyForImport" }
    }
    $Result.ResultDescription
    $Result.ErrorMessage
    
    #Completion#    ##THANK YOU!!!##

  • I approve and may steal for my own (with attribution of course) after I get a chance to test it out.

  • If you tighten it up, you are welcome to share it in the Content Exchange for scripts.