20 Replies Latest reply on Sep 10, 2014 2:20 PM by marunderwood

    new-swisobject fails

    sw_ross


      I've been able to pull data

      get-swisdata, get-swisobject

       

      I've been able to updte data

      set-swisobject

       

      But this always fails for me

      $newNodeUri = New-SwisObject $swis –EntityType "Orion.Nodes" –Properties $newNodeProps

       

       

       

      New-SwisObject : Object reference not set to an instance of an object.

       

       

       

      I don't understand why new-swisobject fails as the $swis connection works for everything else.

        • Re: new-swisobject fails
          tdanner

          That is strange. What is in $newNodeProps when this happens?

            • Re: new-swisobject fails
              sw_ross

               

              Name Value

               

              ---- -----

               

              IPAddressGUID 044648a4-0000-0000-0000-000000000000

               

              DynamicIP False

               

              MachineType

               

              VendorIcon

               

              NodeName TDMGER

               

              Allow64BitCounters False

               

              Community commString

               

              RediscoveryInterval 5

               

              SysObjectID

               

              PollInterval 120

               

              EngineID 1

               

              ObjectSubType SNMP

               

              IPAddress 164.72.70.4

               

              StatCollection 10

               

              UnManaged False

               

              Caption

               

              Status 1

               

              EntityType Orion.Nodes

               

              SNMPVersion 2

               

              Contact MSSupport

               

                • Re: new-swisobject fails
                  madhavan

                  Hi,

                   

                  NodeName and Caption both correspond to the same property of a Node. Remove NodeName from the list of properties provided as input and try. I hope this should solve the issue.

                   

                  If not we need more details as I tried with the same parameters and was not able to reproduce this issue.

                    • Re: new-swisobject fails
                      sw_ross

                      Powershell_ise 3.0 x86

                      I know the $swis connection works because I can query/update data.  I just cannot add nodes.

                      I've tried it from my Win7 desktop.  I've tried it run locally on the solarwinds server.

                       

                      Still this same message:

                       

                       

                      New-SwisObject : Object reference not set to an instance of an object.

                       

                       

                       

                      # This sample script demonstrates how to add a new node using CRUD operations.
                      #
                      # Please update the hostname and credential setup to match your configuration, and
                      # information about the node you would like to add for monitoring.

                       

                      # Helper function
                      function ip2guid($ipString) {
                        $ip = [System.Net.IPAddress]::Parse($ipString)
                        $src = $ip.GetAddressBytes();
                        $data = new-object byte[] 16
                        $src.CopyTo($data, $data.Length - $src.Length)

                       

                        $dest = new-object byte[] 16
                        [Array]::Copy($data, 12, $dest, 0, 4)
                        [Array]::Copy($data, 10, $dest, 4, 2)
                        [Array]::Copy($data, 8, $dest, 6, 2)
                        [Array]::Copy($data, 6, $dest, 8, 2)
                        [Array]::Copy($data, 0, $dest, 10, 6)

                       

                        return (New-Object Guid (,$dest)).ToString()
                      }

                       

                      # Connect to SWIS
                      $hostname = "solarwinds01"
                      #$username = "admin"
                      #$password = New-Object System.Security.SecureString
                      #$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
                      $swis = Connect-Swis -trusted -host $hostname #-cred $cred

                       

                      $ServerName = "TDMGR"
                      $ip = [System.Net.Dns]::GetHostAddresses($ServerName).IPAddressToString
                      $ipGuid = ip2guid($ip)

                       

                      # add a node
                      $newNodeProps = @{
                        EntityType="Orion.Nodes";
                        IPAddress=$ip;
                        IPAddressGUID=$ipGuid;
                        Contact="MSSupport"
                        Caption=$ServerName;
                        DynamicIP=$False;
                        EngineID=1;
                        Status=1;
                        UnManaged=$False;
                        Allow64BitCounters=$False;
                        SysObjectID="";
                        MachineType="";
                        VendorIcon="";
                        # SNMP v2 specific
                        ObjectSubType="SNMP";
                        SNMPVersion=2;
                        Community="commString";
                        # polling timing (optional)
                        RediscoveryInterval=5; # minutes (5..525600=1 year)
                        PollInterval=120; # seconds (1..1200)
                        StatCollection=10; # minutes (1..600)
                      }
                      $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"];
                      }
                      # Details
                      $poller["PollerType"]="N.Details.SNMP.Generic";
                      $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
                      # Uptime
                      $poller["PollerType"]="N.Uptime.SNMP.Generic";
                      $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
                      # CPU
                      #$poller["PollerType"]="N.Cpu.SNMP.CiscoGen3";
                      #$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller
                      # Memory
                      #$poller["PollerType"]="N.Memory.SNMP.CiscoGen3";
                      #$pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

                        • Re: new-swisobject fails
                          tdanner

                          After you get the "object reference not set" error, please run this command and post the results here:

                           

                          $Error[0].Exception.ToString()

                            • Re: new-swisobject fails
                              sw_ross

                              System.NullReferenceException: Object reference not set to an instance of an object.

                              Server stack trace:
                                 at SolarWinds.InformationService.Contract2.Serialization.XmlStrippedSerializerCache.GetSerializer(Type type)
                                 at SolarWinds.InformationService.Contract2.SerializationHelper.Serialize(Object value, String typename)
                                 at SolarWinds.InformationService.Contract2.PropertyBag.WriteXml(XmlWriter writer)
                                 at System.Runtime.Serialization.XmlObjectSerializerWriteContext.WriteIXmlSerializable(XmlWriterDelegator xmlWriter, Object
                              obj, XmlSerializableWriter xmlSerializableWriter)
                                 at System.Runtime.Serialization.XmlDataContract.WriteXmlValue(XmlWriterDelegator xmlWriter, Object obj, XmlObjectSerializer
                              WriteContext context)
                                 at System.Runtime.Serialization.DataContractSerializer.InternalWriteObjectContent(XmlWriterDelegator writer, Object graph,
                              DataContractResolver dataContractResolver)
                                 at System.Runtime.Serialization.DataContractSerializer.InternalWriteObject(XmlWriterDelegator writer, Object graph, DataCon
                              tractResolver dataContractResolver)
                                 at System.Runtime.Serialization.XmlObjectSerializer.WriteObjectHandleExceptions(XmlWriterDelegator writer, Object graph, Da
                              taContractResolver dataContractResolver)
                                 at System.Runtime.Serialization.XmlObjectSerializer.WriteObject(XmlDictionaryWriter writer, Object graph)
                                 at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameterPart(XmlDictionaryWriter write
                              r, PartInfo part, Object graph)
                                 at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameter(XmlDictionaryWriter writer, P
                              artInfo part, Object graph)
                                 at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeParameters(XmlDictionaryWriter writer,
                              PartInfo[] parts, Object[] parameters)
                                 at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, Messag
                              eVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isReq
                              uest)
                                 at System.ServiceModel.Dispatcher.OperationFormatter.SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion versi
                              on, Object[] parameters, Object returnValue, Boolean isRequest)
                                 at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyCont
                              ents(XmlDictionaryWriter writer)
                                 at System.ServiceModel.Channels.BodyWriterMessage.OnWriteBodyContents(XmlDictionaryWriter writer)
                                 at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
                                 at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 init
                              ialOffset, Int32 maxSizeQuota)
                                 at System.ServiceModel.Channels.BinaryMessageEncoderFactory.BinaryMessageEncoder.WriteMessage(Message message, Int32 maxMes
                              sageSize, BufferManager bufferManager, Int32 messageOffset)
                                 at System.ServiceModel.Channels.FramingDuplexSessionChannel.EncodeMessage(Message message)
                                 at System.ServiceModel.Channels.FramingDuplexSessionChannel.OnSendCore(Message message, TimeSpan timeout)
                                 at System.ServiceModel.Channels.TransportDuplexSessionChannel.OnSend(Message message, TimeSpan timeout)
                                 at System.ServiceModel.Channels.OutputChannel.Send(Message message, TimeSpan timeout)
                                 at System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
                                 at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[
                              ] ins, Object[] outs, TimeSpan timeout)
                                 at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime oper
                              ation)
                                 at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

                              Exception rethrown at [0]:
                                 at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
                                 at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
                                 at SolarWinds.InformationService.Contract2.IInformationService.Create(String entityType, PropertyBag properties)
                                 at SolarWinds.InformationService.Contract2.InfoServiceProxy.Create(String entityType, PropertyBag properties)
                                 at SwisPowerShell.NewSwisObject.<>c__DisplayClass1.<InternalProcessRecord>b__0()
                                 at SwisPowerShell.BaseSwisCmdlet.DoWithExceptionReporting(Action work)
                                 at SwisPowerShell.NewSwisObject.InternalProcessRecord()
                                 at SwisPowerShell.BaseSwisCmdlet.DoWithExceptionReporting(Action work)
                                 at SwisPowerShell.BaseSwisCmdlet.ProcessRecord()
                                 at System.Management.Automation.Cmdlet.DoProcessRecord()
                                 at System.Management.Automation.CommandProcessor.ProcessRecord()

                                • Re: new-swisobject fails
                                  Jan Pelousek

                                  Hello sw_ross,

                                   

                                  we're currently working on investigation what's going on here and we're convinced we have it reproducible internally.

                                  We're planning to release next Orion SDK version very soon and are interrested in integration of the fix into the PowerShell SWISSnapin if possible.

                                  I'd like just to ask you for favor.

                                  Although we think we have it reproducible (with the same exception, but only with PowerShell 2.0), there's pretty high probability, that what would work for us, will work also for you. However there might be some not yet discovered dependency.

                                  Per SWI internal processes, I'd like to ask you to create the support ticket and ask them to assign it directly to me? Jan Pelousek, Orion Core. If we had it, we could possibly give you the pre-release version of SDK to test. Otherwise not.

                                  Many thanks in advance.

                              • Re: new-swisobject fails
                                madhavan

                                sw_ross,

                                 

                                The problem is with Guid. When you assign the value to IPAddressGUID, make the below mentioned change. (Here we are explicitly declaring that IPAddressGUID is of type Guid.

                                 

                                IPAddressGUID=[System.Guid]$ipGuid;

                                 

                                The issue is your powershell_ise should be running in powershell 2.0 version. Execute $PSVersionTable and see the PSVersion, which will provide version PS is currently running. (Even when powershell 3.0 is installed, it is compatible to run any downgrade version)

                                 

                                The issue can be solved even when running on powershell 2.0 by above mentioned change.

                                 

                                Try and let me know.

                                  • Re: new-swisobject fails
                                    sw_ross

                                    PS C:\scripts> $PSVersionTable.PSVersion

                                    Major  Minor  Build  Revision
                                    -----  -----  -----  --------
                                    3      0      -1     -1     


                                    I haven't had need to try the Invoke-SwisVerb, but all the other calls work for me.

                                    New-SwisObject works to add the pollers to the node.  It just throws this error on creating nodes in Powershell_ise 3.0

                                     

                                    Odd behavior.  I find that running "Powershell -version 2" from a command line, then running the script, it works.  In ise 3.0 it does not.

                                     

                                    The REST solution I've posted for node creation is a perfectly acceptable solution for us to this issue.  It allows us to stay in v3 or above powershell.

                                     

                                    It's good that there are multiple possible paths to enable the same end result.

                                      • Re: new-swisobject fails
                                        Jan Pelousek

                                        Hello sw_ross,

                                         

                                        your situation is perfectly mirrored to the issue we're having. Working fine in PS 3 and throwing the error in PS2. I'm glad you found the solution by yourself via REST interface, however I'd like to ask you, if you could test for us the Madhavan's suggestion and that's definition of the IPAddressGUID as: IPAddressGUID=[System.Guid]$ipGuid;

                                        It worked for us so we need to know if we could proceed the new SDK version as is.

                                        Many thanks.

                                        Honza

                                          • Re: new-swisobject fails
                                            sw_ross

                                            Incorrect, for us New-SwisObject to create Orion.Nodes fails in Powershell_ise 3.  However it works in Powershell 2 (non ise).

                                            I went to a command prompt, ran powershell -version 2 and the script ran for me and added the node.  It throws the error every time I run the script in Powershell_ise 3.

                                             

                                            I have tried IPAddressGUID=[System.Guid]$ipGuid; - it made no difference.  The behavior remains the same.


                                            But within Powershell_ise 3 we use REST to create the node and New-SwisObject works to add the pollers to the node.


                                            When I get into work I'll try to run the script from powershell 3, non-ise and see if it still throws an error.

                                              • Re: new-swisobject fails
                                                sw_ross

                                                Now I'm really confused.  I jump to powershell 3 non-ise and it runs.  Now it no longer errors on my pc in the ise either.

                                                We had the error on multiple computers.  I'll have to check if the behavior is the same.

                                                  • Re: new-swisobject fails
                                                    Jan Pelousek

                                                    Hello,

                                                     

                                                    are there some news per your observations? Did the IPAddressGUID=[System.Guid]$ipGuid; definition resolve the issue for you as in our case? We just need confirmation so we could move forward with new release. Many thanks in advance.

                                                      • Re: new-swisobject fails
                                                        sw_ross

                                                        No, the odd thing is, after running from a command line "powershell -version 2" and running the script, then it no longer errors even in the ISE.

                                                        Prior to running under powershell version 2 it failed every time in the ISE.

                                                        I have not had the chance to check on another machine yet to verify if the behavior is the same.

                                                          • Re: new-swisobject fails
                                                            sw_ross

                                                            Interesting.  I've found the culprit, though I don't understand why.

                                                            When I use

                                                             

                                                            $ip = ([System.Net.Dns]::GetHostAddresses($ServerName)).IPAddressToString

                                                            if ($ip -is [array]) {

                                                                foreach ($ipaddr in $ip) {

                                                                    # Strip IPv6 address

                                                                    if ($ipaddr.contains(".")){$ip=$ipaddr}

                                                                }

                                                            }

                                                            rather than directly hardcoding the IP:

                                                            $ip = "123.12.0.2"

                                                             

                                                            It fails, even though $ip is a System.String in either case.

                                                            But if I do this after the above .Net call:

                                                            $ip=$ip.ToString()

                                                             

                                                            it works.

                                                             

                                                            So when is a System.String not a System.String?

                                                              • Re: new-swisobject fails
                                                                tdanner

                                                                That's very strange! When you have one of these "kind of a string, but not really" objects, what do you get when you call .GetType() on it?

                                                                  • Re: new-swisobject fails
                                                                    sw_ross

                                                                    $ServerName = "LS-TAD"
                                                                    $ip = ([System.Net.Dns]::GetHostAddresses($ServerName)).IPAddressToString
                                                                    if ($ip -is [array]) {
                                                                        foreach ($ipaddr in $ip) {
                                                                            # Strip IPv6 address
                                                                            if ($ipaddr.contains(".")){$ip=$ipaddr}
                                                                        }
                                                                    }
                                                                    $ip.GetType()

                                                                    $txtIp = "123.12.0.2"
                                                                    $txtIp.GetType()

                                                                    IsPublic IsSerial Name                                     BaseType                                    
                                                                    -------- -------- ----                                     --------                                    
                                                                    True     True     String                                   System.Object                               
                                                                    True     True     String                                   System.Object  

                                              • Re: new-swisobject fails
                                                Jan Pelousek

                                                Some time ago I found this mightn't work  under PowerShell 2.0. Please try to upgrade the PowerShell to version 3.0+ e.g. from http://www.microsoft.com/en-us/download/details.aspx?id=34595

                                            • Re: new-swisobject fails
                                              sw_ross

                                              Well at least I found a workaround to script adding nodes to solarwinds.   Since the powershell API has been failing for me, I hacked the examples to use JSON/REST to add nodes.

                                               

                                              ============powershell code==================

                                              # Helper function
                                              function ip2guid($ipString) {
                                                $ip = [System.Net.IPAddress]::Parse($ipString)
                                                $src = $ip.GetAddressBytes();
                                                $data = new-object byte[] 16
                                                $src.CopyTo($data, $data.Length - $src.Length)

                                               

                                                $dest = new-object byte[] 16
                                                [Array]::Copy($data, 12, $dest, 0, 4)
                                                [Array]::Copy($data, 10, $dest, 4, 2)
                                                [Array]::Copy($data, 8, $dest, 6, 2)
                                                [Array]::Copy($data, 6, $dest, 8, 2)
                                                [Array]::Copy($data, 0, $dest, 10, 6)

                                               

                                                return (New-Object Guid (,$dest)).ToString()
                                              }

                                               

                                              #$password = ConvertTo-SecureString "" -AsPlainText -Force
                                              $orionCred = Get-Credential
                                              $orion_server = "Solarwinds"
                                              $ServerName = "serverToAdd"
                                              $ip = [System.Net.Dns]::GetHostAddresses($ServerName).IPAddressToString
                                              $ipGuid = ip2guid($ip)

                                               

                                              add-type @"
                                                  using System.Net;
                                                  using System.Security.Cryptography.X509Certificates;
                                                  public class TrustAllCertsPolicy : ICertificatePolicy {
                                                      public bool CheckValidationResult(
                                                          ServicePoint srvPoint, X509Certificate certificate,
                                                          WebRequest request, int certificateProblem) {
                                                          return true;
                                                      }
                                                  }
                                              "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy $body = @{   EntityType=Orion.Nodes"";"
                                                IPAddress=$ip;
                                                IPAddressGUID=$ipGuid;
                                                Contact="MSSupport"
                                                Caption=$ServerName;
                                                DynamicIP=$False;
                                                EngineID=1;
                                                Status=1;
                                                UnManaged=$False;
                                                Allow64BitCounters=$False;
                                                SysObjectID="";
                                                MachineType="";
                                                VendorIcon="";
                                                # SNMP v2 specific
                                                ObjectSubType="SNMP";
                                                SNMPVersion=2;
                                                Community="XXcommStringXX";
                                                # polling timing (optional)
                                                RediscoveryInterval=5; # minutes (5..525600=1 year)
                                                PollInterval=120; # seconds (1..1200)
                                                StatCollection=10; # minutes (1..600)
                                              }
                                              $jsonBody = ConvertTo-Json $body
                                              $create = "https://"+$orion_server+":17778/SolarWinds/InformationService/v3/Json/Create/Orion.Nodes"
                                              $results = Invoke-RestMethod -Uri $create -Credential $orioncred -ContentType "application/json" -Body $jsonBody -Method Post

                                              ============end of powershell code==================

                                              • Re: new-swisobject fails
                                                marunderwood

                                                Thank you!!

                                                I too was getting the "Object reference not set to an instance of an object" ... by adding the statement to convert to string, it now works fine.  (Using Powershell v 2.0)

                                                 

                                                $NodeId = get-swisdata $swis "SELECT NodeID FROM Orion.Nodes WHERE IP_Address=@ip" @{ip=$ip} -errorvariable myerrorvariable      --- This works fine.

                                                $NodeId = $NodeId.ToString()                                                                                                                                                                -- This fixed the error I was getting in the next statement.

                                                $NodeStatus = get-swisdata $swis "SELECT Status FROM Orion.Nodes WHERE NodeId=@id" @{id=$NodeId} -errorvariable myerrorvariable     -- Statement with the error