This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

new-swisobject fails


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.

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

  •  

    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

  • 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.

  • 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

  • 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

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

    $Error[0].Exception.ToString()

  • 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==================

  • 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()

  • 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.

  • 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.