4 Replies Latest reply on Feb 11, 2015 4:52 PM by dkeyser

    Discovery through SDK is no longer working as expected PowerShell

    dkeyser

      I've been working on and off on this automation tool and it used to work great on 10.6. I've recently upgraded to 11.0.1 and now my script is no longer importing WMI based nodes properly at all. I've checked to see if my variable inside the CreateCorePluginConfiguraiton is present and it appears that it is but when I look at the discovery profiles it doesn't find the test node. Also the discovery finishes incredibly quick which makes me believe that it's not handling this properly. Code for the discovery below. I still need to make this more flexable but I've not had the time to keep up on this project.

       

      $FaultIPListImport = 0

       

       

      if ($CSV)

      {

      #CSV import

      $importFile="c:\Users\Administrator\Desktop\NodeList.csv"

      $importList=IMPORT-CSV $importFile

      }

      else

      {

      $importList = $IPAddresses

      }

       

       

      $nodeIpList = Get-SwisData $swis "Select IPAddress from Orion.Nodes"

       

       

      ForEach ($import in $importList)

      {

          if ($nodeIpList -contains $import)

          {

          Write-Host "Node is already in system with IP $import"

          }

          else

          {

          $FaultIPListImport = 1

          $block = $import

         # $build = $build + "<d3p1:string>$block</d3p1:string>"

         $build = $build + "<IPAddress><Address>$block</Address></IPAddress>"

          }

      }

      #Logic to test for blank import list.

      if ($FaultIPListImport -eq 0)

      {

      Write-Host "No IPs to import! All are duplicates!"

      Break

      }

       

       

      #Output the IP List

      $build

       

       

      $CoreParameter = ([xml]"<CorePluginConfigurationContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>

      <BulkList >

      $build

      </BulkList>

        <Credentials>    

          <SharedCredentialInfo>

          <CredentialID>1</CredentialID>

          <Order>1</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>2</CredentialID>

          <Order>2</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>3</CredentialID>

          <Order>3</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>4</CredentialID>

          <Order>4</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>5</CredentialID>

          <Order>5</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>6</CredentialID>

          <Order>6</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>7</CredentialID>

          <Order>7</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>8</CredentialID>

          <Order>8</Order>

          </SharedCredentialInfo>

          <SharedCredentialInfo>

          <CredentialID>9</CredentialID>

          <Order>9</Order>

          </SharedCredentialInfo>

        </Credentials>

      <WmiRetriesCount>1</WmiRetriesCount>

      <WmiRetryIntervalMiliseconds>10000</WmiRetryIntervalMiliseconds>

      </CorePluginConfigurationContext>").DocumentElement

       

       

      $CoreConfig = Invoke-SwisVerb $swis "Orion.Discovery" "CreateCorePluginConfiguration" @($CoreParameter)

      $CoreConfigInnerPiece = $coreConfig.InnerXml

       

       

      $StartDiscoveryCfg = ([xml]"

      <StartDiscoveryContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>

        <Name>Test Discovery1</Name>

        <EngineId>1</EngineId>

        <JobTimeoutSeconds>3600</JobTimeoutSeconds>

        <SearchTimeoutMiliseconds>2000</SearchTimeoutMiliseconds>

        <SnmpTimeoutMiliseconds>3000</SnmpTimeoutMiliseconds>

        <SnmpRetries>4</SnmpRetries>

        <RepeatIntervalMiliseconds>1800000</RepeatIntervalMiliseconds>

        <SnmpPort>161</SnmpPort>

        <HopCount>0</HopCount>

        <PreferredSnmpVersion>SNMP2c</PreferredSnmpVersion>

        <DisableIcmp>false</DisableIcmp>

        <AllowDuplicateNodes>false</AllowDuplicateNodes>

        <IsAutoImport>false</IsAutoImport>

        <ImportUpInterface>false</ImportUpInterface>

        <ImportDownInterface>false</ImportDownInterface>

        <ImportShutdownInterface>false</ImportShutdownInterface>

        <IsHidden>false</IsHidden>

        <PluginConfigurations>

          <PluginConfiguration>

              <PluginConfigurationItem>$CoreConfigInnerPiece</PluginConfigurationItem>

          </PluginConfiguration>

        </PluginConfigurations>

      </StartDiscoveryContext>"

      ).DocumentElement

       

       

      $out = Invoke-SwisVerb $swis "Orion.Discovery" "StartDiscovery" @($StartDiscoveryCfg)

      $output = $out.innerxml

       

       

      #Once complete $output will give you the ProfileID.

      $output

       

       

      #Will leave in the $JobStatus loop to stall the script until the discovery is complete.

      $JobStatus = Get-SwisData $swis "Select Status from Orion.DiscoveryProfiles Where ProfileID = $output"

      While ($jobStatus -ne 2)

      {

          Write-Host "Discovery Not Finished Yet!"

          Start-Sleep -s 10

          $JobStatus = Get-SwisData $swis "Select Status from Orion.DiscoveryProfiles Where ProfileID = $output"

      }

       

       

      Write-Host "Discovery has completed!"

       

      $DiscoveryInfo = Get-SwisData $swis "select IPAddress, IPAddressGUID, NodeID, ProfileID, cred.Name, cred.ID, EngineID, HostName, Vendor from Orion.DiscoveredNodes dn

      left join Orion.DiscoveryProfiles dp on dn.ProfileID = dp.ProfileID

      left join Orion.Credential cred on dn.CredentialID = cred.ID

      where dn.ProfileID = $output"