2 Replies Latest reply on Sep 5, 2017 7:32 AM by zackm

    Discovery Function Question (PowerShell)

    zackm

      I am attempting to create some functions inside of a larger script that will create a basic SNMP Discovery job. All of the details in the function were pulled from my base script that works without any issues. It seems that something about passing the values across in this manner is causing a ruckus.

       

      SAMPLE

       

      #region Connect to SWIS
      # Import the SolarWinds PowerShell Module if needed
      
      
      If (!(Get-Module SwisPowerShell)) {
          Import-Module SwisPowerShell
      }
      
      
      # Connect to SWIS
      
      
      $hostname = "hostname here"
      $swis = Connect-Swis -Trusted -Hostname $hostname
      
      
      #endregion 
      
      
      #region Functions
      # $nodeList $snmpID
      FUNCTION New-CoreParameter ($ipAddresses, $snmpCredentialID) {
      <#
      .SYNOPSIS
          Creates the Core Parameter for Sonar Discovery
      .DESCRIPTION
          Building block for New-DiscoveryJob
      .EXAMPLE
          $coreParameter = New-CoreParameter $nodeList $snmpID
      .PARAMETER ipAddresses
          Value of $nodeList from the File Select Region
      .PARAMETER snmpCredentialID
          Value of $snmpID from the SNMP Community String Region
      #>
      
      
          $ipList = @()
          foreach ($ip in $ipAddresses) {
              $ipList += '<IpAddress><Address>{0}</Address></IpAddress>' -f ($ip)
          }
      
      
          $core = ([xml]"<CorePluginConfigurationContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>
          <BulkList>
              $ipList         
          </BulkList>
          <IpRanges></IpRanges>
          <Subnets></Subnets>
          <Credentials>     
              <SharedCredentialInfo>
                  <CredentialID>$snmpCredentialID</CredentialID>
                  <Order>1</Order>
              </SharedCredentialInfo>   
          </Credentials>
          <WmiRetriesCount>1</WmiRetriesCount>
          <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
          </CorePluginConfigurationContext>").DocumentElement
      
      
          # Build the Core Plugin Config, and grab its XML
      
      
          $coreConfig = Invoke-SwisVerb $swis Orion.Discovery CreateCorePluginConfiguration @($core)
          $coreConfigInnerXml = $coreConfig.InnerXml
      
      
          RETURN $coreConfigInnerXML
      }
      
      
      # $discName $selectedEngineID $coreParamter $vimParameter $interfaceParameter
      FUNCTION New-DiscoveryJob($discoveryName, $engineID, $core) {
      <#
      .SYNOPSIS
          Builds a new Orion Sonar Discovery Job for SNMPv1/2c
      .DESCRIPTION
          Leverages the New-CoreParameter, New-VimParameter, and New-InterfaceParamater functions
      .EXAMPLE
          $newDiscovery = New-DiscoveryJob $discName, $selectedEngineID, $coreParamter, $vimParamter, $interfaceParameter
      .PARAMETER discoveryName
          The value of the $discName parameter from the Variables Region
      .PARAMETER engineID
          The value of the $selectedEngineID parameter from the Polling Engines Region
      .PARAMETER core
          The value of the New-CoreParameter function return
      .PARAMETER vim
          The value of the New-VimParameter function return
      .PARAMETER interface
          The value of the New-InterfaceParameter function return
      #>
      
      
          ([xml]"<StartDiscoveryContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>
          <Name>$discoveryName</Name>
          <EngineId>$engineID</EngineId>
          <JobTimeoutSeconds>3600</JobTimeoutSeconds>
          <SearchTimeoutMiliseconds>2000</SearchTimeoutMiliseconds>
          <SnmpTimeoutMiliseconds>3000</SnmpTimeoutMiliseconds>
          <SnmpRetries>3</SnmpRetries>
          <RepeatIntervalMiliseconds>1800000</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>$core</PluginConfigurationItem>
              </PluginConfiguration>
          </PluginConfigurations>
          </StartDiscoveryContext>").DocumentElement
      }
      
      
      # $newDiscovery
      FUNCTION Start-Discovery($discoveryJob) {
      <#
      .SYNOPSIS
          Starts to newly-created Orion Sonar Discovery
      .DESCRIPTION
          Utilizes the results of the New-DiscoveryJob function
      .EXAMPLE
          $discoveryProfileID = Start-Discovery $newDiscovery
      .PARAMETER discoveryJob
          The value of the New-DiscoveryJob function return
      #>
          (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($discoveryJob)).InnerText    
      }
      
      
      #endregion
      
      
      $nodeList = Get-Content -Path "C:\Testing\ipDemo.txt"
      $snmpID = 3
      $discName = "gentleTest"
      $selectedEngineID = 8
      $coreParameter = New-CoreParameter $nodeList $snmpID
      $newDiscovery = New-DiscoveryJob $discName $selectedEngineID $coreParamter
      Start-Discovery $newDiscovery
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       

      Investigation of the $coreParameter and $newDiscovery variables look good; not idea why but the Start-Discovery function returns the following:

       

      Invoke-SwisVerb : ProvideFault failed, check fault information.
      At line:116 char:6
      +     (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($discover ...
      +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [Invoke-SwisVerb], FaultException`1
          + FullyQualifiedErrorId : SwisError,SwisPowerShell.InvokeSwisVerb

       

      So it's failing on the (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($discoveryJob)).InnerText  execution...

       

      Here's the Original Script (sans-Functions) that works

       

      #region Connect to SWIS
      # Import the SolarWinds PowerShell Module if needed
      
      
      If (!(Get-Module SwisPowerShell)) {
          Import-Module SwisPowerShell
      }
      
      
      # Connect to SWIS
      
      
      $hostname = "wpil0219swweb01"
      $swis = Connect-Swis -Trusted -Hostname $hostname
      
      
      #endregion 
      
      
      #####-----------------------------------------------------------------------------------------#####
      
      
      #region Variables
      # Name your discovery job
      $discName = "gentleTest_old"
      
      
      # Build an array of IP addresses
      $ipAddresses = Get-Content -Path "C:\Testing\ipDemo.txt"
      $ipList = @()
      
      
      foreach ($ip in $ipAddresses) {
          $ipList += '<IpAddress><Address>{0}</Address></IpAddress>' -f ($ip)
      }
      
      
      # Get the SNMP Community String ID
      $credID = 3
      
      
      # Get the Polling Engine ID
      $engineID = 8
      
      
      #endregion 
      
      
      #####-----------------------------------------------------------------------------------------#####
      
      
      #region Core Plugin Configuration
      
      
      # Build the Core parameter, using the $ipList and $credID variables from above
      $coreParameter = ([xml]"<CorePluginConfigurationContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>
      <BulkList>
          $ipList         
      </BulkList>
      <IpRanges></IpRanges>
      <Subnets></Subnets>
      <Credentials>     
          <SharedCredentialInfo>
              <CredentialID>$credID</CredentialID>
              <Order>1</Order>
          </SharedCredentialInfo>   
      </Credentials>
      <WmiRetriesCount>1</WmiRetriesCount>
      <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds>
      </CorePluginConfigurationContext>").DocumentElement
      
      
      # Build the Core Plugin Config, and grab its XML
      
      
      $coreConfig = Invoke-SwisVerb $swis "Orion.Discovery" "CreateCorePluginConfiguration" @($coreParameter)
      $coreConfigInnerXml = $coreConfig.InnerXml
      
      
      #endregion 
      
      
      #####-----------------------------------------------------------------------------------------#####
      
      
      #region Discovery Context
      
      
      # Build the Discovery Configuration
      $newDiscovery = ([xml]"<StartDiscoveryContext xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.solarwinds.com/2012/Orion/Core'>
          <Name>$discName</Name>
          <EngineId>$engineID</EngineId>
          <JobTimeoutSeconds>3600</JobTimeoutSeconds>
          <SearchTimeoutMiliseconds>2000</SearchTimeoutMiliseconds>
          <SnmpTimeoutMiliseconds>3000</SnmpTimeoutMiliseconds>
          <SnmpRetries>3</SnmpRetries>
          <RepeatIntervalMiliseconds>1800000</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>$coreConfigInnerXml</PluginConfigurationItem>
              </PluginConfiguration>
          </PluginConfigurations>
      </StartDiscoveryContext>").DocumentElement
      
      
      #endregion
      
      
      #####-----------------------------------------------------------------------------------------#####
      
      
      #region Start The Discovery
      
      
      # Start the discovery
      
      
      (Invoke-SwisVerb $swis Orion.Discovery StartDiscovery @($newDiscovery)).InnerText
      
      
      #endregion
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      

       

      After running the original script:

       

      My assumption is something trivial has been overlooked by me being too deep in the script; so any and all feedback is welcome.

       

      Any help is appreciated!