24 Replies Latest reply on Apr 13, 2012 11:18 AM by tdanner

    Using the SDK powershell snap in - some newbie questions

    qbarry

      Hi all,

      Just getting started doing an integration between Orion and some of our other tools. Have been through the SDK 1.3 and found some useful stuff in there especially around the kind of things we're looking to do like:

      - create/remove a new node

      - Add pollers

      - Get a list of nodes

       

      So I have some questions and please excuse me if these are trivial, but I think it's important we get this right at the outset. To set the scene my plan is to use the powershell cmdlets to do my integrations. So to the questions:

      1. The Connect-Swis cmdlet - can it take the user/pw as parameters? If so how? eg:

           $swis = Connect-Swis -user myuser -pw mypassword

       

      2. To create a node, i can use the New-SwisObject cmdlet. There are basically 2 instances where I'd want to do this: creating a server or a network device like a switch etc. In either case, is it necessary to add one or more interfaces for that Orion.Node object or will Orion discover the interfaces when it polls it and add them itself?

      3. Follow on from Q2 - can I force Orion to poll the device once I've added it?

      4. Is it always necessary to use the NodeID when querying for a Orion.Node object? I've tried to use a select statement to do a query using "where Caption='myhost'" but it doesn't seem to like that.

        • Re: Using the SDK powershell snap in - some newbie questions
          tdanner

          1. Following the PowerShell guidelines, Connect-Swis takes a PSCredential object for the username and password. If you want to put the password in your script in clear text, here's how to make a PSCredential from a username and password from strings: http://blogs.technet.com/b/gary/archive/2009/07/23/creating-a-ps-credential-from-a-clear-text-password-in-powershell.aspx
          2. Orion will not automatically add the interfaces or volumes to a node added this way. The "Technical Reference" document (Orion SDK.pdf) describes how to add an interface to a node. It requires you to provide the interface index and interface name.
          3. Orion will poll it automatically if you assign the proper pollers. Please see Orion SDK.pdf for more details.
          4. You should be able to query using any property, just like in SQL. Could you post the full command you are using that isn't working as expected?

            • Re: Using the SDK powershell snap in - some newbie questions
              qbarry

              1. That works a treat - thanks for that.

              2. Yup - I've seen how to add an interface in the SDK.pdf. So this leads to another question - what does Orion regard as the primary address for a device (say a server)? Is it the details containted in the Orion.nodes -> IPAddress value? Or is it the interface object related to the server with an index of 0? (or do i need to always add at least one interface to a node when adding in this way?)

               

              4. The queries I've been trying look like this:

               

              $mynode = 'SELECT NodeID, caption From Orion.Nodes where Caption="Testnode"'

              Get-SwisData $swis $mynode

               

              Error comes back as: Get-SwisData : Cannot resolve property Testnode.  

              Seems to work ok if i query on where NodeID=1 or variations on that.

                • Re: Using the SDK powershell snap in - some newbie questions
                  tom.rybka

                  2. Yes, you are right. The primary address for communication with a device is a value available in the IPAddress property of the Orion.Nodes entity.

                  4. The quotes in your query are not recognized by SWQL. String literals needs to enclosed in a pair of apostrophes. Try to use:

                  SELECT NodeID, caption From Orion.Nodes where Caption='Testnode'

                    • Re: Using the SDK powershell snap in - some newbie questions
                      mkomeara

                      I'm trying to find a way to automate adding new nodes.  These nodes will be SNMP nodes with Custom Properties set and whatever other parameters necessary to make it work.  One problem I see is if I add a node using a script, then want to add Custom Properties, I have to know the NodeID to do that.I've been trying without success to write a query to get that info so I can go on and add Custom Properties to the node.  I can run a query successfully if I already know the NodeID;

                      Get-SwisData $swis 'SELECT NodeID, Caption FROM Orion.Nodes WHERE NodeID=18'

                                                                           NodeID  Caption
                                                                           ------      -------
                                                                               18      106 (Z23) Sacramento, CA

                      But how would I find the NodeID of that node with a query?  I've tried using LIKE in the query, but can't seem to find a way to specify '106%' to match the node Caption above in order to get that node information.  I've tried these queries without success;

                      Get-SwisData $swis 'SELECT NodeID, Caption FROM Orion.Nodes WHERE Caption like "106%"'
                      Get-SwisData $swis 'SELECT NodeID, Caption FROM Orion.Nodes WHERE Caption like '106%''
                      Get-SwisData $swis 'SELECT NodeID, Caption FROM Orion.Nodes WHERE Caption like "%Sacramento%"'

                      Is there a guide to using queries under PS for Orion?  The examples in the SDK book don't give a novice like me enough information to help me get this done.  Enclosing the SELECT statement in apostrophes changes the way the query works.

                      OR, is there a better way to do this?

                        • Re: Using the SDK powershell snap in - some newbie questions
                          tom.rybka

                          SWIS recognizes single-quotes as string delimiters, so you may use double-quotes to delimit the query and single-quotes to delimit a string literal inside. E.g.:

                          Get-SwisData $swis "SELECT NodeID, Caption FROM Orion.Nodes WHERE Caption like '106%' "

                          Other than that, when you add a node to Orion, you receive a SWIS URI for the new Orion.Nodes entity you can use in other CRUD operations. E.g. if you use the Read operation to get the properties of the node, you can easily get NodeID directly: (fragment taken from the SDK PS sample):

                          # $newNodeUri is what you receive from the Create operation
                          $nodeProps = Get-SwisObject $swis -Uri $newNodeUri
                          $nodeId = $nodeProps["NodeID"];
                          # $nodeId contains the NodeID of the node

                            • Re: Using the SDK powershell snap in - some newbie questions
                              mkomeara

                              Following the example in the book for setting the Custom Properties of the node, everything seems to be set correctly.  But when I issue the Set-SwisObject command it errors out;

                              PS H:\> $nodeId
                              2373
                              PS H:\> $customProps = @{
                              >>   Comments="Franchise Router";
                              >>   NodeID=$nodeId;
                              >>   Building="Franchise";
                              >>   Country="USA";
                              >>   Franchise="True";
                              >>   FranData="True";
                              >>   FranServers="False";
                              >>   HQ_Critical="False";
                              >>   HQData="True";
                              >>   HQServers="False";
                              >>   HQWksta="False";
                              >>   iSeries="False";
                              >>   PhoneSys="False";
                              >>   Remote="True";
                              >>   Service_Provider="Sprint";
                              >>   Service_Type="";
                              >>   SpecialCase="False";
                              >>   State=$nnST;
                              >>   Virtual="False";
                              >>   DisplayName="";
                              >>   Description="";
                              >> }
                              >> # build the node URI
                              >> $uri = "swis://localhost/Orion/Orion.Nodes/NodeID=$nodeId/CustomProperties";
                              >> # set the custom property
                              >> Set-SwisObject $swis -Uri $uri -Properties $customProps
                              >>
                              Set-SwisObject : Object reference not set to an instance of an object.
                              At line:27 char:15
                              + Set-SwisObject <<<<  $swis -Uri $uri -Properties $customProps
                                  + CategoryInfo          : NotSpecified: (:) [Set-SwisObject], NullReferenceException
                                  + FullyQualifiedErrorId : System.NullReferenceException,SwisPowerShell.SetSwisObject

                              It seems to be saying the value for $swis is set incorrectly.  This is what it  looks like;

                              OperationTimeout                        Channel                                              ClientChannel
                              ----------------                        -------                                                          -------------
                              01:00:00                                SolarWinds.InformationService.Contra... SolarWinds.InformationService.Contra...

                              What's wrong and how would I troubleshoot this?

                                • Re: Using the SDK powershell snap in - some newbie questions
                                  tdanner

                                  PowerShell is a bit stingy with error output by default, and I can't figure out what is going wrong from what it has printed here. Try using this function to get some more details:

                                  http://blogs.msdn.com/b/powershell/archive/2006/12/07/resolve-error.aspx

                                  Then I bet we can figure it out.

                                    • Re: Using the SDK powershell snap in - some newbie questions
                                      mkomeara

                                      Here it is.  I thought maybe it was rejecting the "True" and "False" values for the Custom Properties, so I changed them to $True and $False, but it didn't change the result.;

                                      PS H:\> rver


                                      PSMessageDetails      :
                                      Exception             : System.ServiceModel.FaultException: Update failed, check fault information.

                                                              Server stack trace:
                                                                 at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation,
                                                              ProxyRpc& rpc)
                                                                 at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOper
                                                              ationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
                                                                 at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOper
                                                              ationRuntime operation, Object[] ins, Object[] outs)
                                                                 at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodC
                                                              all, ProxyOperationRuntime operation)
                                                                 at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

                                                              Exception rethrown at [0]:
                                                                 at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage r
                                                              etMsg)
                                                                 at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
                                                                 at SolarWinds.InformationService.Contract2.IInformationService.Update(String uri, PropertyBa
                                                              g propertiesToUpdate)
                                                                 at SolarWinds.InformationService.Contract2.InfoServiceProxy.Update(String uri, PropertyBag p
                                                              ropertiesToUpdate)
                                                                 at SwisPowerShell.SetSwisObject.InternalProcessRecord()
                                                                 at SwisPowerShell.BaseSwisCmdlet.ProcessRecord()
                                      TargetObject          :
                                      CategoryInfo          : InvalidOperation: (:) [Set-SwisObject], FaultException
                                      FullyQualifiedErrorId : SwisError,SwisPowerShell.SetSwisObject
                                      ErrorDetails          : Update failed, check fault information.
                                      InvocationInfo        : System.Management.Automation.InvocationInfo
                                      PipelineIterationInfo : {0, 1}

                                       

                                       

                                      MyCommand        : Set-SwisObject
                                      BoundParameters  : {[Uri, swis://localhost/Orion/Orion.Nodes/NodeID=2374/CustomProperties], [Properties, System.Collect
                                                         ions.Hashtable], [SwisConnection, SolarWinds.InformationService.Contract2.InfoServiceProxy]}
                                      UnboundArguments : {}
                                      ScriptLineNumber : 46
                                      OffsetInLine     : 15
                                      HistoryId        : 166
                                      ScriptName       :
                                      Line             : Set-SwisObject $swis -Uri $uri -Properties $customProps
                                      PositionMessage  :
                                                         At line:46 char:15
                                                         + Set-SwisObject <<<<  $swis -Uri $uri -Properties $customProps
                                      InvocationName   : Set-SwisObject
                                      PipelineLength   : 1
                                      PipelinePosition : 1
                                      ExpectingInput   : False
                                      CommandOrigin    : Runspace

                                       

                                      00000000000000000000000000000000000000000000000000000000000000000000000000000000


                                      Action         : http://schemas.solarwinds.com/2007/08/informationservice/InformationService/UpdateInfoServiceFaultCont
                                                       ractFault
                                      Code           : System.ServiceModel.FaultCode
                                      Message        : Update failed, check fault information.
                                      Reason         : Update failed, check fault information.
                                      Data           : {}
                                      InnerException :
                                      TargetSite     : Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging
                                                       .IMessage)
                                      StackTrace     :
                                                       Server stack trace:
                                                          at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRp
                                                       c& rpc)
                                                          at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRu
                                                       ntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
                                                          at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRu
                                                       ntime operation, Object[] ins, Object[] outs)
                                                          at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, Pr
                                                       oxyOperationRuntime operation)
                                                          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.Update(String uri, PropertyBag prope
                                                       rtiesToUpdate)
                                                          at SolarWinds.InformationService.Contract2.InfoServiceProxy.Update(String uri, PropertyBag properti
                                                       esToUpdate)
                                                          at SwisPowerShell.SetSwisObject.InternalProcessRecord()
                                                          at SwisPowerShell.BaseSwisCmdlet.ProcessRecord()
                                      HelpLink       :
                                      Source         : mscorlib

                                        • Re: Using the SDK powershell snap in - some newbie questions
                                          tdanner

                                          We're going to have to follow this another level down. Could you reproduce the error again and look in C:\ProgramData\SolarWinds\InformationService\v2.0\Orion.InformationService.log? That should have the details.

                                          • Re: Using the SDK powershell snap in - some newbie questions
                                            tom.rybka

                                            You are trying to set quite a bunch of custom properties in your script, I assume all of these are valid custom properties.

                                            However, there is also NodeID specified in the dictionary being passed to the Set-SwisObject cmdlet which is not correct. This is a readonly property of Orion.Nodes entity type, whereas the script is updating CustomProperties navigation property of the Orion.Nodes entity. The specification of which node's custom properties should be updated is a part of the SWIS URI you are passing to Set-SwisObject.

                                              • Re: Using the SDK powershell snap in - some newbie questions
                                                mkomeara

                                                That was it.  I removed the NodeID entry and the DisplayName and Description entries and it ran correctly.

                                                Next item - I need to add interfaces, so can I add all three interfaces at once like this;

                                                $newIfaceProps = @{
                                                NodeID=$nodeId; # NodeID on which the interface is working on
                                                InterfaceName="Ethernet0"; 
                                                InterfaceIndex=1;
                                                ObjectSubType="SNMP";
                                                Status=0;
                                                InterfaceName="Ethernet1";
                                                InterfaceIndex=2;
                                                ObjectSubType="SNMP";
                                                Status=0;
                                                InterfaceName="FastEthernet1"; 
                                                InterfaceIndex=3;
                                                ObjectSubType="SNMP";
                                                Status=0;
                                                }

                                                $newIfaceUri = New-SwisObject $swis –EntityType "Orion.NPM.Interfaces" –Properties $newIfaceProps
                                                $ifaceProps = Get-SwisObject $swis -Uri $newIfaceUri

                                                *****************************************************************************************
                                                Or do I need to add them separately like this;

                                                # First interface
                                                $newIfaceProps = @{
                                                NodeID=$nodeId; # NodeID on which the interface is working on
                                                InterfaceName="Ethernet0"; 
                                                InterfaceIndex=1;
                                                ObjectSubType="SNMP";
                                                Status=0;
                                                }
                                                $newIfaceUri = New-SwisObject $swis –EntityType "Orion.NPM.Interfaces" –Properties $newIfaceProps
                                                $ifaceProps = Get-SwisObject $swis -Uri $newIfaceUri
                                                # Second interface
                                                $newIfaceProps = @{
                                                NodeID=$nodeId; # NodeID on which the interface is working on
                                                InterfaceName="Ethernet1";
                                                InterfaceIndex=2;
                                                ObjectSubType="SNMP";
                                                Status=0;
                                                }
                                                $newIfaceUri = New-SwisObject $swis –EntityType "Orion.NPM.Interfaces" –Properties $newIfaceProps
                                                $ifaceProps = Get-SwisObject $swis -Uri $newIfaceUri
                                                # Third interface
                                                $newIfaceProps = @{
                                                NodeID=$nodeId; # NodeID on which the interface is working on
                                                InterfaceName="FastEthernet1"; 
                                                InterfaceIndex=3;
                                                ObjectSubType="SNMP";
                                                Status=0;
                                                }
                                                $newIfaceUri = New-SwisObject $swis –EntityType "Orion.NPM.Interfaces" –Properties $newIfaceProps
                                                $ifaceProps = Get-SwisObject $swis -Uri $newIfaceUri