4 Replies Latest reply on Jan 26, 2017 2:35 PM by brandon.ewing

    Read interfaces on a node?

    brandon.ewing

      Greetings!

       

      I'm having some issues using swis's READ method to enumerate the interfaces on an Orion node.  If I pass an InterfaceID in the URI, it will correctly return one interface, but if I do not specify an interface ID, I get the following error from the server:

       

      requests.exceptions.HTTPError: 400 Client Error: Invalid key properties specified for entity Orion.NPM.Interfaces.
      Parameter name: filter for url: https://solarwinds:17778/SolarWinds/InformationService/v3/Json/swis://solarwinds/Orion/Orion.Nodes/NodeID=180/Interfaces
      

       

      Since I'm able to use "swis://solarwinds/Orion/Orion.Nodes/NodeID=180/CustomProperties" to get an enumeration of the custom properties of a node, I would have expected this trend to continue.  I know I can use a query instead to retrieve the same information, but would prefer to stick to CRUD operations wherever possible.  Am I just missing something simple here?

        • Re: Read interfaces on a node?
          tdanner

          A read operation on "swis://solarwinds/Orion/Orion.Nodes/NodeID=180/CustomProperties" is still only returning one object, a holder for the custom properties for one node.

           

          What you are asking for makes sense, but it is not supported by SWIS CRUD operations today. You will have to use a query for this.

            • Re: Read interfaces on a node?
              brandon.ewing

              tdanner wrote:

               

              A read operation on "swis://solarwinds/Orion/Orion.Nodes/NodeID=180/CustomProperties" is still only returning one object, a holder for the custom properties for one node.

               

              What you are asking for makes sense, but it is not supported by SWIS CRUD operations today. You will have to use a query for this.

              Is there a plan to alter this behavior in the future?  Performing a read operation for all 64 interfaces on the average switch takes a non-trivial amount of time, and redoing it as a query is hard to support going forward if the schema changes.

               

              Alternatively, is there an easy way to produce a query that mimics the behavior of the following, but doesn't result in multiple API calls?

               

              class InterfaceList(Mapping):
                  """ Container for the interface list """
                  def __init__(self, connection, uri, node_id):
                      self._data = {}
                      interface_ids = util.get_int_ids(connection, node_id)
                      for x in interface_ids:
                          self._data[x] = Interface(connection, uri, x)
              
              
                  def __getitem__(self, key):
                      return self._data[key]
              
              
                  def __iter__(self):
                      return iter(self._data)
              
              
                  def __len__(self):
                      return len(self._data)
              
              
              class Interface(object):
                  """Data for a specific interface."""
                  def __init__(self, connection, uri, interface_id):
                      self._connection = connection
                      resp = connection.read("{}/Interfaces/InterfaceID={}".format(uri, interface_id))
                      if resp is not None:
                          for key, value in resp.items():
                              if isinstance(value, basestring):
                                  value = value.strip()
                              setattr(self, "_" + underscore(key), value)
              
              
                  @property
                  def uri(self):
                      return self._uri
              
              
              
              
              
              
              
              
              
              
              
                • Re: Read interfaces on a node?
                  tdanner

                  You can ask SWIS for the set of properties an interface has:

                   

                  SELECT Name FROM Metadata.Property WHERE EntityName = 'Orion.NPM.Interfaces' AND IsNavigable=0

                   

                  Then use the results from this query to build a query that gets a bunch of interfaces:

                   

                  SELECT a, bunch, of, properties FROM Orion.NPM.Interfaces WHERE my-condition-here

                   

                  There are a few ways you could write the condition:

                   

                  WHERE NodeID=123     -- Gets all interfaces on Node 123

                  WHERE InterfaceID IN (4,5,6,7)    -- Gets interfaces 4, 5, 6 and 7

                  WHERE Uri IN ('swis://...', 'swis://...')   -- Gets some interfaces by Uri

                   

                  The response would be equivalent to a "BulkRead" operation.

                  1 of 1 people found this helpful
                    • Re: Read interfaces on a node?
                      brandon.ewing

                      tdanner wrote:

                       

                      You can ask SWIS for the set of properties an interface has:

                       

                      SELECT Name FROM Metadata.Property WHERE EntityName = 'Orion.NPM.Interfaces' AND IsNavigable=0

                       

                      Thanks!  This is what I was looking for!

                       

                      but i'd still also love to see the read operation updated to support recursive operations