17 Replies Latest reply on Mar 3, 2017 9:16 AM by Steven Klassen

    API created ICMP node never gets polled

    mlandman

      I'm using PS and the API to add nodes from a CSV, and set custom properties. Here is the content of the CSV:

      Code,     Hostname,     IpAddr,          Department,             Env,                  TimeOffset

      C1,          DAG01,         10.0.0.1,    Win DBA,                    Testing,            0

      C2,          DAG02,         10.0.0.2,     Server Operations,     Production,      0

       

      The nodes get created, the custom properties get set, but they are never polled and the NodeID is not inserted into the Pollers table. The IP (changed for this thread) is pingable. When I use the GUI "Add Node" and the same IP it gets into the poller table and comes up right away.

      What am I missing?

       

      Here is the code:

       

      #requires -version 2
      <#
      .SYNOPSIS
      This script is used to add a new node using CRUD operations from a CSV file
      It adds the node in Alert_Muted_Node = TRUE state
      Other customproperties can be set

      The script progresses in several steps:
      1. Create the node based on caption and IP
      1a. Optionally set a trailing caption qualifier
      2. Assign ICMP pollers
      3. Set custom properties
      .DESCRIPTION
      Run via SWIS.
      .OUTPUTS
      None.
      .NOTES
      Version: 1.0
      Author: Michael Landman <Michael.Landman@FirstCitizens.com>
      Creation Date: MAR. 01, 2017
      Purpose/Change: Initial script development.
      #>

      #---------------------------------------------------------[Initializations]--------------------------------------------------------

      # set error action to silently continue
      $ErrorActionPreference = "SilentlyContinue"


      #----------------------------------------------------------[Declarations]----------------------------------------------------------

      # script version
      $scriptVersion = "1.0"

      #-------------------------------------------------------------[Init]---------------------------------------------------------------

      $hostname = "REDACTED";
      $Nodename = @();
      $IPAddr = @();
      $Dept = @();
      $Environ = @();
      $TimeO = @();
      $customProps = @();
      $CaptionQualifier = "";
      $PathToFile = "D:\temp\TestClustersIP.csv";
      $msg="";
      $now = (get-date -Format s);
      $outFile = ("d:\temp\$now.AddIcmpNodeSWISlog.txt").Replace(":",".");

      #-----------------------------------------------------------[Functions]------------------------------------------------------------

      #-----------------------------------------------------------[Execution]------------------------------------------------------------

      if (-not (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {
          Add-PSSnapin "SwisSnapin"
      }

      # Connect to SWIS

      $cred = Get-Credential
      $swis = Connect-Swis -host $hostname -cred $cred

      Import-Csv $PathToFile |ForEach-Object {
         $Nodename += $_."Hostname";
         $IPAddr += $_."IpAddr";
                  $Dept += $_."Department";
                  $Environ += $_."Env";
                  $TimeO += $_."TimeOffset";
        }
      #$ip = "10.0.0.1"

      # add a node
      for ($i=0; $i -lt $Nodename.length; $i++)
      {
          If($Nodename[$i] -match "sd")
          {
              $CaptionQualifier = "_SqlCluster";
          }
          else
          {
              $CaptionQualifier = "_Cluster";
          }

      $newNodeProps = @{
        IPAddress = $IPAddr[$i];
        EngineID = 1;
        ObjectSubType = "ICMP";
        Caption = $Nodename[$i] + $CaptionQualifier;
        # SNMP v2 specific
        #ObjectSubType = "SNMP";

        #SNMPVersion = 2;

        # === default values ===

        # EntityType = 'Orion.Nodes'
        # Caption = ''
        # DynamicIP = false
        # PollInterval = 120
        # RediscoveryInterval = 30
        # StatCollection = 10 
      }

      $newNodeUri = New-SwisObject $swis -EntityType "Orion.Nodes" -Properties $newNodeProps
      $nodeProps = Get-SwisObject $swis -Uri $newNodeUri

      # register specific pollers for the node

      $poller = @{
        NetObject="N:"+$nodeProps["NodeID"];
        NetObjectType="N";
        NetObjectID=$nodeProps["NodeID"];
            
      }

      # Status
      $poller["PollerType"]="N.Status.ICMP.Native";
      $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

       

      # Response time
      $poller["PollerType"]="N.ResponseTime.ICMP.Native";
      $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

          # set Alert_muted_Node to True and other custom properties

          # prepare a custom property value. These MUST be present or no properties will be set
          $customProps = @{
              Alert_Muted_Node=1;
              Department = $Dept[$i];
              Environment = $Environ[$i];
              TimeOffset=$TimeO[$i];
          }

          # build the node URI
          $uri = "swis://$hostname/Orion/Orion.Nodes/NodeID=$($nodeProps["NodeID"])/CustomProperties";

          # set the custom property
          Set-SwisObject $swis -Uri $uri -Properties $customProps
      }

        • Re: API created ICMP node never gets polled
          Steven Klassen

          Hey mlandman, long time no talk!

           

          When I write something like this I usually just carve the NodeID off the end of the URI instead of trying to query for it immediately after it's created. Maybe check out $nodeProps to make sure you're getting a valid value?

           

          $newNodeUri = New-SwisObject $swis -EntityType "Orion.Nodes" -Properties $newNodeProps
          $nodeProps = Get-SwisObject $swis -Uri $newNodeUri
          
            • Re: API created ICMP node never gets polled
              mlandman

              Hi Steve

              Still unknown this morning.

              BTW...Since I do not like leaving connections open, what is the PS call to close the connection?

              Looks like good data:

              PS C:\WINDOWS\system32> $nodeProps

               

              Key                                                                                                 Value

              ---                                                                                                 -----

              NodeID                                                                                                285

              ObjectSubType                                                                                        ICMP

              IPAddress                                                                                    10.xxx.xxx.xxx

              IPAddressType                                                                                        IPv4

              DynamicIP                                                                                           False

              Caption                                                                                   NPDAWBlahBlahBlah

              NodeDescription                                                                                         

              Description                                                                                       Unknown

              DNS                                                                                                     

              SysName                                                                                                 

              Vendor                                                                                            Unknown

              SysObjectID                                                                                             

              Location                                                                                                

              Contact                                                                                                 

              VendorIcon                                                                           Unknown.gif        

              Icon                                                                                 Unknown.gif        

              Status                                                                                                  0

              StatusLED                                                                                               

              StatusDescription                                                                 Node status is Unknown.

              CustomStatus                                                                                        False

              IOSImage                                                                                                

              IOSVersion                                                                                              

              GroupStatus                                                      Unknown.gif                            

              StatusIcon                                                       Unknown.gif                            

              LastBoot                                                                                                

              SystemUpTime                                                                                            

              ResponseTime                                                                                            

              PercentLoss                                                                                             

              AvgResponseTime                                                                                         

              MinResponseTime                                                                                         

              MaxResponseTime                                                                                         

              CPULoad                                                                                                -2

              MemoryUsed                                                                                             -2

              MemoryAvailable                                                                                         

              PercentMemoryUsed                                                                                       

              PercentMemoryAvailable                                                                                  

              LastSync                                                                                                

              LastSystemUpTimePollUtc                                                                                 

              MachineType                                                                                       Unknown

              IsServer                                                                                                

              Severity                                                                                                

              UiSeverity                                                                                              

              ChildStatus                                                                                             1

              Allow64BitCounters                                                                                   True

              AgentPort                                                                                             161

              TotalMemory                                                                                             

              CMTS                                                                                                    N

              CustomPollerLastStatisticsPoll                                                      12/30/1899 5:00:00 AM

              CustomPollerLastStatisticsPollSuccess                                               12/30/1899 5:00:00 AM

              SNMPVersion                                                                                             0

              PollInterval                                                                                          120

              EngineID                                                                                                1

              RediscoveryInterval                                                                                    30

              NextPoll                                                                              3/1/2017 9:15:14 PM

              NextRediscovery                                                                       3/1/2017 9:45:11 PM

              StatCollection                                                                                         10

              External                                                                                                

              Community                                                                                          public

              RWCommunity                                                                                             

              IP                                                                                           10.xxx.xxx.xxx

              IP_Address                                                                                   10.xxx.xxx.xxx

              IPAddressGUID                                                        7301d00a-0000-0000-0000-000000000000

              NodeName                                                                                  NPDAWBlahBlahBlah

              BlockUntil                                                                          12/30/1899 5:00:00 AM

              BufferNoMemThisHour                                                                                    -2

              BufferNoMemToday                                                                                       -2

              BufferSmMissThisHour                                                                                   -2

              BufferSmMissToday                                                                                      -2

              BufferMdMissThisHour                                                                                   -2

              BufferMdMissToday                                                                                      -2

              BufferBgMissThisHour                                                                                   -2

              BufferBgMissToday                                                                                      -2

              BufferLgMissThisHour                                                                                   -2

              BufferLgMissToday                                                                                      -2

              BufferHgMissThisHour                                                                                   -2

              BufferHgMissToday                                                                                      -2

              OrionIdPrefix                                                                                          N:

              OrionIdColumn                                                                                      NodeID

              SkippedPollingCycles                                                                                    

              MinutesSinceLastSync                                                                                    

              EntityType                                                                                    Orion.Nodes

              DetailsUrl                                             /Orion/NetPerfMon/NodeDetails.aspx?NetObject=N:285

              DisplayName                                                                               NPDAWBlahBlahBlah

              UnManaged                                                                                           False

              UnManageFrom                                                                       12/30/1899 12:00:00 AM

              UnManageUntil                                                                      12/30/1899 12:00:00 AM

              Image                                                                                                   

              AncestorDisplayNames                                                                    {NPDAWBlahBlahBlah}

              AncestorDetailsUrls                                  {/Orion/NetPerfMon/NodeDetails.aspx?NetObject=N:285}

              StatusIconHint                                                                                          

              InstanceType                                                                                  Orion.Nodes

              Uri                                   swis://NPDARBlahBlahBlah.DC.DC.net/Orion/Orion.Nodes/NodeID=285

              • Re: API created ICMP node never gets polled
                mlandman

                I threw the call to assign the poller into a Try{} /Catch{} loop and got this:

                try{

                # Status

                $poller["PollerType"]="N.Status.ICMP.Native";

                $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

                }

                catch{

                $errMsg = $_.Exception.Message

                Write-Host $errMsg

                }

                 

                " Cannot convert value "PollerType" to type "System.Int32". Error: "Input string was not in a correct format." "

                  • Re: API created ICMP node never gets polled
                    Steven Klassen

                    Let me see the $poller variable just before the call to New-SwisObject?

                      • Re: API created ICMP node never gets polled
                        mlandman

                        PS C:\WINDOWS\system32> $Poller

                         

                        Name                           Value                                                                                                                                                         

                        ----                           -----                                                                                                                                                         

                        NetObjectType                  N                                                                                                                                                             

                        NetObjectID                    292                                                                                                                                                           

                        NetObject                      N:292                                                                                                                                                         

                          • Re: API created ICMP node never gets polled
                            Steven Klassen

                            Ah well, there you go - it's missing the PollerType key.

                              • Re: API created ICMP node never gets polled
                                Steven Klassen

                                If you get all four key/value pairs in there it definitely works as advertised:

                                  • Re: API created ICMP node never gets polled
                                    mlandman

                                    This is supposed to add it:

                                    $poller["PollerType"]="N.Status.ICMP.Native";
                                    $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
                                    


                                    but it fails with this error:

                                    Cannot convert value "PollerType" to type "System.Int32". Error: "Input string was not in a correct format."

                                     

                                    I am going to try adding it here:

                                    # register specific pollers for the node
                                    $poller = @{
                                        NetObject="N:"+$nodeProps["NodeID"];
                                        NetObjectType="N";
                                        NetObjectID=$nodeProps["NodeID"]:
                                    }
                                    
                                      • Re: API created ICMP node never gets polled
                                        Steven Klassen

                                        It's failing when the New-SwisObject runs, not when value is assigned. The error you're getting is because it's taking one of the lateral values (probably the NetObjectID because of the complaint about Int32) and is trying to use that for the PollerType instead. That code at the top looks right to me but if $poller doesn't have the key then it's not working for some reason.

                                        • Re: API created ICMP node never gets polled
                                          Steven Klassen

                                          I would try stripping everything out but the connect, building the $poller hash, and the New-SwisObject call and see how you fare with that. I wonder if it's a scope issue. I don't think I've seen the entire script so I don't know where variables are being created.

                                           

                                          Also, BRB, need to get 3 hrs of sleep in before my next obligation (been up since 1 AM).

                                            • Re: API created ICMP node never gets polled
                                              mlandman

                                              It's Some stupid computer issue!!!

                                              Ran this from my WS and from our QA SolarWinds server, fails on the WS, works from the server! Feel free to use this code to make nodes from a CSV.

                                              There are a bunch of hours I will not get back!!!

                                               

                                              #requires -version 2
                                              <#
                                              .SYNOPSIS
                                              This script is used to add a new node using CRUD operations from a CSV file
                                              It adds the node in Alert_Muted_Node = TRUE state
                                              Other customproperties can be set
                                              
                                              The script progresses in several steps:
                                              1. Create the node based on caption and IP
                                              1a. Optionally set a trailing caption qualifier
                                              2. Assign ICMP pollers
                                              3. Set custom properties
                                              .DESCRIPTION
                                              Run via SWIS.
                                              .OUTPUTS
                                              None.
                                              .NOTES
                                              Version: 1.0
                                              Author: Michael Landman <Michael.Landman@FirstCitizens.com>
                                              Creation Date: Feb. 28, 2017 
                                              Purpose/Change: Initial script development.
                                              #>
                                              
                                              #---------------------------------------------------------[Initializations]--------------------------------------------------------
                                              
                                              # set error action to silently continue
                                              $ErrorActionPreference = "SilentlyContinue"
                                              
                                              
                                              #----------------------------------------------------------[Declarations]----------------------------------------------------------
                                              
                                              # script version
                                              $scriptVersion = "1.0"
                                              
                                              #-------------------------------------------------------------[Init]---------------------------------------------------------------
                                              
                                              $hostname = "SolarWindsQaServerName";
                                              $Nodename = @();
                                              $IPAddr = @();
                                              $Dept = @();
                                              $Environ = @();
                                              $TimeO = @();
                                              $customProps = @();
                                              $CaptionQualifier = "";
                                              $PathToFile = "D:\temp\TestClustersIP.csv";
                                              $msg="";
                                              $now = (get-date -Format s);
                                              $outFile = ("d:\temp\$now.AddIcmpNodeSWISlog.txt").Replace(":",".");
                                              
                                              #-----------------------------------------------------------[Functions]------------------------------------------------------------
                                              
                                              
                                              #-----------------------------------------------------------[Execution]------------------------------------------------------------
                                              
                                              
                                              if (-not (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {
                                                  Add-PSSnapin "SwisSnapin"
                                              }
                                              
                                              # Connect to SWIS
                                              
                                              
                                              $cred = Get-Credential
                                              $swis = Connect-Swis -host $hostname -cred $cred
                                              
                                              
                                              Import-Csv $PathToFile |ForEach-Object {
                                                          $Nodename += $_."Hostname";
                                                          $IPAddr += $_."IpAddr";
                                                          $Dept += $_."Department";
                                                          $Environ += $_."Env";
                                                          $TimeO += $_."TimeOffset";
                                                      }
                                              #$ip = "10.0.0.1"
                                              
                                              # add a node
                                              for ($i=0; $i -lt $Nodename.length; $i++) 
                                              {
                                                  If($Nodename[$i] -match "sd")
                                                  {
                                                      $CaptionQualifier = "_SqlCluster";
                                                  }
                                                  else
                                                  {
                                                      $CaptionQualifier = "_Cluster";
                                                  }
                                                  
                                                  $newNodeProps = @{
                                                      IPAddress = $IPAddr[$i];
                                                      EngineID = 1;
                                                      ObjectSubType = "ICMP"
                                                      Caption = $Nodename[$i] + $CaptionQualifier
                                                      # SNMP v2 specific
                                                      #ObjectSubType = "SNMP";
                                              
                                                      #SNMPVersion = 2;
                                              
                                                      # === default values ===
                                              
                                                      # EntityType = 'Orion.Nodes'
                                                      # Caption = ''
                                                      # DynamicIP = false
                                                      # PollInterval = 120
                                                      # RediscoveryInterval = 30
                                                      # StatCollection = 10  
                                                  }
                                              
                                                  $newNodeUri = New-SwisObject $swis -EntityType "Orion.Nodes" -Properties $newNodeProps
                                                  $nodeProps = Get-SwisObject $swis -Uri $newNodeUri
                                              
                                                  # register specific pollers for the node
                                              
                                                  
                                              
                                              # Status 
                                              $poller = @{
                                                      NetObject="N:"+$nodeProps["NodeID"];
                                                      NetObjectType="N";
                                                      NetObjectID=$nodeProps["NodeID"];
                                                     }
                                              
                                              
                                               # Add Pollers for Status (Up/Down), Response Time
                                               # Status 
                                               $poller["PollerType"]="N.Status.ICMP.Native"; 
                                               $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller 
                                              
                                              
                                               # Response time 
                                               $poller["PollerType"]="N.ResponseTime.ICMP.Native"; 
                                               $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller 
                                              
                                              
                                                  # set Alert_muted_Node to True and other custom properties
                                              
                                                  # prepare a custom property value. These MUST be present or no properties will be set
                                                  $customProps = @{
                                                      Alert_Muted_Node=1;
                                                      Department = $Dept[$i];
                                                      Environment = $Environ[$i];
                                                      TimeOffset=$TimeO[$i];
                                                  }
                                              
                                                  # build the node URI
                                                  $uri = "swis://$hostname/Orion/Orion.Nodes/NodeID=$($nodeProps["NodeID"])/CustomProperties";
                                              
                                                  # set the custom property
                                                  Set-SwisObject $swis -Uri $uri -Properties $customProps
                                              }
                                                  $swis.Close()
                                              
                                              
                                • Re: API created ICMP node never gets polled
                                  mlandman

                                  BTW...
                                  What is the HTML for this format?