24 Replies Latest reply on Jan 20, 2017 10:34 AM by robdogaz

    List Resources By C# Orion SDK?

    adelk

      For example in NMS web console:

      1. Go Under Node Management.

      2. Click List Resources to get a checklist of interfaces.

       

      Can I have same operation from C#?

       

      Regards

        • Re: List Resources By C# Orion SDK?
          tdanner

          There is an API for enumerating and adding network interfaces for SNMP nodes, but there is no equivalent for the rest of the List Resouces functionality.

            • Re: List Resources By C# Orion SDK?
              rhomewood

              When will this be available in the API for other polling methods? This should be standard for the SAM module especially when polling with WMI, a given for automating Windows server provisioning? It's not made it into SAM 6.2.4 or NPM 12

               

              Regards

              • Re: List Resources By C# Orion SDK?
                adelk

                Shocko thanks for your response. That would solve my case, can you please share the function name or a link.

                • Re: List Resources By C# Orion SDK?
                  adelk

                  That would solve my case, can you please share the function name or a link.

                    • Re: List Resources By C# Orion SDK?
                      tdanner

                      The API consists of a pair of verbs: Orion.NPM.Interfaces.DiscoverInterfacesOnNode and Orion.NPM.Interfaces.AddInterfacesOnNode. There's a sample script here: https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/NPM.DiscoverAndAddInterfacesOnNode.ps1 .

                      1 of 1 people found this helpful
                        • Re: List Resources By C# Orion SDK?
                          robdogaz

                          I followed your script and have it working for all interfaces except the following when you click list resources, how via code can these get selected

                           

                            • Re: List Resources By C# Orion SDK?
                              tdanner

                              There are two methods in the API for adding nodes:

                               

                              1. Call Create for "Orion.Nodes" and then add the interfaces, pollers, and so on, to build up the monitoring you want.
                              2. Create and run a discovery profile that will scan the device and add monitoring for everything Orion can find. Then trim to remove unwanted interfaces, volumes, etc.

                               

                              The advantage of #2 is that it works for any device type supported by Orion. With #1 you have to know the right PollerType values in advance (and they can be different even between older and newer models of the same device!).

                               

                              If you want to continue with method #1, the best way to get the right set of poller types is to take an example of the kind of device you want to monitor (as close a match as you can get) and add it to Orion manually. Then query Orion.Pollers to see what got added for that device. Set up your script to mimic this.

                               

                              But you might find it simpler overall to look at https://github.com/solarwinds/OrionSDK/wiki/Discovery and use that API instead.

                                • Re: List Resources By C# Orion SDK?
                                  robdogaz

                                  I did mimic what is on another device like

                                   

                                  $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

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

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

                                   

                                   

                                  # Response

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

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

                                  $poller["PollerType"]="N.ResponseTime.SNMP.Native";

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

                                   

                                   

                                  # 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.CiscoGen4";

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

                                   

                                   

                                  # Topology

                                  $poller["PollerType"]="N.Topology_Vlans.SNMP.VtpVlan";

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

                                  $poller["PollerType"]="N.Topology_CDP.SNMP.cdpCacheTable";

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

                                  $poller["PollerType"]="N.Topology_Layer3.SNMP.ipNetToMedia";

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

                                  $poller["PollerType"]="N.Topology_Layer3_IpRouting.SNMP.ipCidrRouter";

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

                                   

                                   

                                  # Routing

                                  $poller["PollerType"]="N.VRFRouting.SNMP.MPLSVPNStandard";

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

                                  $poller["PollerType"]="N.Routing.SNMP.Ipv4CidrRoutingTable";

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

                                  $poller["PollerType"]="N.RoutingNeighbor.SNMP.BGP";

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

                                  $poller["PollerType"]="N.RoutingNeighbor.SNMP.EIGRP";

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

                                   

                                  But it still doesn't select the items in the screen shot.

                                   

                                  Do you have a matrix of Interface Type Numbers to Descriptions?

                                  • Re: List Resources By C# Orion SDK?
                                    robdogaz

                                    Even if not exposed to API what table is enabling the Health Monitor? I can't seem to find that.

                                     

                                    Also on the command Invoke-SwisVerb $swis "Orion.Nodes" "PollNow" @( "N:" + $nodeProps["NodeID"] ) doesn't seem to do the same thing as doing it via the Web UI. Is that because the Health Monitor is not enabled when I run the PollNow?

                                      • Re: List Resources By C# Orion SDK?
                                        tdanner

                                        Using the Create/Orion.Nodes API, you need to add the "N.HardwareHealthMonitoring.SNMP.NPM.Cisco" poller type and also one more thing:

                                         

                                        Add an entry in Orion.NodeSettings with NodeID = {your node id}, SettingName = "NeedsInventory", and SettingValue = "HWH" (for "hardware health"). I added this to the sample here: https://github.com/solarwinds/OrionSDK/commit/6116acde40d9ae4157cbc0a1eeee3f24ae8e63ac#diff-f1cf35fc822e3b595890991822152f9eR105

                                         

                                        If you switch to the discovery API, this should be handled automatically.

                                          • Re: List Resources By C# Orion SDK?
                                            robdogaz

                                            Ok let me try that I was adding it to the DB using that same method like

                                            $strQuery = "INSERT INTO dbo.[NodeSettings] (NodeID, SettingName, SettingValue) SELECT n.NodeID, 'Core.TopologyPollInterval','30' FROM Nodes n LEFT JOIN APM_HardwareInfo hw ON (n.NodeID = hw.NodeID) WHERE n.NodeID = '$NodeID'"

                                            $strQuery2 = "INSERT INTO dbo.[NodeSettings] (NodeID, SettingName, SettingValue) SELECT n.NodeID, 'Core.WebBrowseTemplate','http://{{ HrefIPAddress }}' FROM Nodes n LEFT JOIN APM_HardwareInfo hw ON (n.NodeID = hw.NodeID) WHERE n.NodeID = '$NodeID'"

                                            $strQuery3 = "INSERT INTO dbo.[NodeSettings] (NodeID, SettingName, SettingValue) SELECT n.NodeID, 'HardwareHealth.PreferredCiscoMIB','CISCO-ENVMON-MIB' FROM Nodes n LEFT JOIN APM_HardwareInfo hw ON (n.NodeID = hw.NodeID) WHERE n.NodeID = '$NodeID'"

                                             

                                            But did not have the N.HardwareHealthMonitoring.SNMP.NPM.Cisco

                                             

                                            Also based on your code example how would you add Custom Properties like?

                                             

                                            do another CreateAsync("Orion.Nodes/CustomProperties") ?

                                              • Re: List Resources By C# Orion SDK?
                                                tdanner

                                                You don't need to make a Create call for custom properties - that entity is created automatically when the node is created. To set custom property values, you need the node's URI (it is returned from the Create call for Orion.Nodes) with "/CustomProperties" appended. Then you can call Update passing that URI and the values for the custom properties. In PowerShell, that looks like this:

                                                 

                                                Set-SwisObject $swis $nodeCustomPropertiesUri @{ MyPropertyName = "My value"; MyOtherProperty = "my other value" }

                                                  • Re: List Resources By C# Orion SDK?
                                                    robdogaz

                                                    Yes I figured that out, you keep showing PowerShell commands like they interchange with REST ;-) - Not complaining, you are helping a ton.

                                                     

                                                    I just keep trying to figure out what to send to get values back.

                                                     

                                                    I was able to update the CustomProperties with

                                                    await swisClient.UpdateAsync(nodeUri + "/CustomProperties",  new

                                                                    {

                                                                        Country = "US",

                                                                        Node_Type = "ROUTER",

                                                                        Address = "XXX",

                                                                        Polling_Priority = "XX",

                                                                        RouterLocation = "XXX",

                                                                        EVDO = "XXX",

                                                                        City = "XXX",

                                                                        State = "AZ"

                                                                    });

                                                     

                                                    But now I am trying to figure out how to take the current script in Powershell and convert to a C# Async call.

                                                     

                                                    # Discover interfaces on the node

                                                    $discovered = Invoke-SwisVerb $swis Orion.NPM.Interfaces DiscoverInterfacesOnNode $nodeId

                                                     

                                                    So far this is what I have and not working

                                                     

                                                    private static JToken GetInterfaces(ISwisClient swisClient, string NodeNum)

                                                            {

                                                                JToken invokeInterfaces = swisClient.InvokeAsync("Orion.NPM.Interfaces", "DiscoverInterfacesOnNode", new object[]

                                                                {

                                                                    new[]

                                                                    {

                                                                        new

                                                                        {

                                                                            NodeNum

                                                                        }

                                                                    }

                                                                }).Result;

                                                                return invokeInterfaces;

                                                            }

                                                    • Re: List Resources By C# Orion SDK?
                                                      robdogaz

                                                      Hey Mr. Tanner,

                                                       

                                                      I was able to get the Interfaces and willing to share here but I am running into issues trying to AddInterfacesOnNode

                                                       

                                                      DataTable dt = Tabulate(GetInterfaces(swisClient, nodeId.ToString()).ToString());

                                                                  EnumerableRowCollection<DataRow> query = from myRow in dt.AsEnumerable()

                                                                                                           where myRow.Field<string>("Caption").StartsWith("Tunnel100") ||

                                                                                                           myRow.Field<string>("Caption").StartsWith("GigabitEthernet0/0/0") ||

                                                                                                           myRow.Field<string>("Caption").StartsWith("GigabitEthernet0/0/1") ||

                                                                                                           myRow.Field<string>("Caption").StartsWith("T1 0/1/0") ||

                                                                                                           myRow.Field<string>("Caption").StartsWith("Serial0/1/0:1") ||

                                                                                                           myRow.Field<string>("Caption").StartsWith("Serial0/1/0:100")

                                                                                                           select myRow;

                                                                  DataView view = query.AsDataView();

                                                       

                                                       

                                                                  for (int i = 0; i < view.Count; i++)

                                                                  {

                                                                      await swisClient.InvokeAsync("Orion.NPM.Interfaces", "AddInterfacesOnNode", nodeId, new

                                                                      {

                                                                          ifIndex = view[i][0],

                                                                          Caption = view[i][1],

                                                                          ifType = view[i][2],

                                                                          ifSubType = view[i][3],

                                                                          InterfaceID = view[i][4],

                                                                          Manageable = view[i][5],

                                                                          ifSpeed = view[i][6],

                                                                          ifAdminStatus = view[i][7],

                                                                          ifOperStatus = view[i][8]

                                                       

                                                       

                                                                      }, "AddDefaultPollers");               

                                                                  }

                                                       

                                                      Not sure what I am supposed to be passing here. I get the following error

                                                       

                                                      System.AggregateException: One or more errors occurred. ---> System.ApplicationException: Server returned error: 400 Bad Request

                                                      {

                                                        "Message": "Verb Orion.NPM.Interfaces.AddInterfacesOnNode cannot unpackage parameter 1 with type SolarWinds.NPM.Common.Models.Discovery.InterfaceDiscovery.DiscoveredLiteInterface[]",

                                                        "ExceptionType": "SolarWinds.InformationService.Verb.VerbExecutorException",

                                                        "FullException": "SolarWinds.InformationService.Verb.VerbExecutorException: Verb Orion.NPM.Interfaces.AddInterfacesOnNode cannot unpackage parameter 1 with type SolarWinds.NPM.Common.Models.Discovery.InterfaceDiscovery.DiscoveredLiteInterface[] ---> Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'SolarWinds.NPM.Common.Models.Discovery.InterfaceDiscovery.DiscoveredLiteInterface[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'ifIndex'.\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.<>c__DisplayClass22_0.<UnpackageParameters>b__0(Int32 index)\r\n   --- End of inner exception stack trace ---\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.<>c__DisplayClass22_0.<UnpackageParameters>b__0(Int32 index)\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.CreateParameters(Func`2 getParameterAt, Int32 parametersCount, Stream stream)\r\n   at SolarWinds.InformationService.Verb.VerbExecutorContext.UnpackageParameters(JArray parameters)\r\n   at SolarWinds.InformationService.Core.InformationService.Invoke[T](String entity, String verb, Action`1 setupParameters, Func`2 extractReturnValue)"