14 Replies Latest reply on Sep 2, 2016 2:25 PM by Steven Klassen

    How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?

    mlampe

      I am attempting to add nodes via SNMP using python.  I have previously been using ICMP to add the nodes only for Status and response time polling, but would like to expand further and gather more information automatically.  Is there a good way to try to authenticate over SNMP using the SNMP string, and if the string verifies, add the node?  I currently am using this snippet of code, and it does successfully add an SNMP node, but the only statistics that show up on the node page are for Average Response Time and Packet Loss, but CPU load, Memory, and any disks are not detected.  I may not be fully understanding the polling aspect and how it works in regards to the API, but I would like to essentially recreate what happens when I "List Resources" on a node and select which disks, CPU, RAM, and other properties to monitor.  If someone could take a look at my poller options and let me know if I am making a mistake somewhere that would be great.


      Also, can I use some sort of try/catch exception handling when adding SNMP nodes, in case the string does not authenticate, I can revert back to adding the node via simply ICMP?


      Thanks!


      uri = swis.create(EntityType,
         IPAddress = IP_input,
         IPAddressGUID = ip_to_guid(IP_input),
         Caption = str(IP_input),
         DynamicIP = False,
         EngineID = 1,
         Status = 1,
         UnManaged = False,
         Allow64BitCounters = True,
         ObjectSubType = "SNMP",
         MachineType = "",
         VendorIcon = "",
         RediscoveryInterval = 30,
         PollInterval = 60,
         StatCollection = 1,
         City = "REDACTED",
         Managed_Monitored = "REDACTED",
           Node_Type = "TBD",
         ALERT_CPU = 90,
         ALERT_RAM = 90,
         Community = 'REDACTED',
         SNMPVersion=2
         )
        # Get all object properties for new node added
        obj = swis.read(uri)
        snmpDetailsUri = swis.create("Orion.Pollers", PollerType = "N.Details.SNMP.Generic", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpUptimeUri = swis.create("Orion.Pollers", PollerType = "N.Uptime.SNMP.Generic", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpCpuUri = swis.create("Orion.Pollers", PollerType = "N.Cpu.SNMP.HrProcessorLoad", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpMemoryUri = swis.create("Orion.Pollers", PollerType = "N.Memory.SNMP.NetSnmpReal", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpAssetInventoryUri = swis.create("Orion.Pollers", PollerType = "N.AssetInventory.Snmp.Generic", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpResponseTimeUri = swis.create("Orion.Pollers", PollerType = "N.ResponseTime.SNMP.Native", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpStatusUri = swis.create("Orion.Pollers", PollerType = "N.Status.SNMP.Native", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
        snmpTopologyUri = swis.create("Orion.Pollers", PollerType = "N.Topology_Layer3.SNMP.ipNetToMedia", NetObject="N:" + str(obj["NodeID"]), NetObjectType="N", NetObjectID=obj["NodeID"])
      
        • Re: How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?
          madhavan

          Hi,

           

          In the below provided link, we have information on how to programmatically list resources and automatically add pollers to the resources.

           

          How do we programmatically discover the non-interface properties [in Orion] and enable them

           

          We cannot validate SNMP credentials with try catch when adding nodes as polling happens in background after the node is created.

            • Re: How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?
              mlampe

              That thread was definitely insightful, but I'm still not sure if I can accomplish what I need.  Do you have an example using the python swis api to invoke the node discovery and list resources and return the resources found?  From there I think I can filter what I need and add the appropriate pollers.

                • Re: How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?
                  Steven Klassen

                  I've been trying to avoid getting into the discovery method of getting this information mainly because I don't want to add extra overhead to the API conversation and I'm not entirely comfortable with the "1) create the discovery, 2) run the discovery, 3) wait for the discovery to complete, 4) determine if it discovered anything of use" dance. Since the only thing I need to add fixed disks are an index, the size of the volume, the used amount of the volume, and its name I'd rather have snmpwalk step out, get me the indexes (1.3.6.1.2.1.25.2.3.1.3), and then let me query again for the size & used OIDs (1.3.6.1.2.1.25.2.3.1.<idx>.5 and 1.3.6.1.2.1.25.2.3.1.<idx>.6, respectively).

                   

                  At that point, you add it like any other object:

                   

                      def _add_volumes_to_solarwinds(self):
                          now = datetime.utcnow()
                  
                          for volume in self.node.volumes:
                              props = {
                                  'NodeID': self._nodeid,
                                  'Icon': 'FixedDisk.gif',
                                  'Index': volume['index'],
                                  'Caption': volume['name'],
                                  'StatusIcon': 'Up.gif',
                                  'Type': 'Fixed Disk',
                                  'Size': volume['size'],
                                  'Responding': 'Y',
                                  'FullName': '{}-{}'.format(self.node.sysinfo['sysname'], volume['name']),
                                  'VolumeDescription': volume['name'],
                                  'VolumePercentUsed': str(int(volume['used']) / int(volume['size']) * 100),
                                  'VolumeAllocationFailuresThisHour': None,
                                  'VolumeSpaceUsed': volume['used'],
                                  'VolumeAllocationFailuresToday': '',
                                  'VolumeSpaceAvailable': str(int(volume['size']) - int(volume['used'])),
                              }
                  
                              ret = self._swis.create('Orion.Volumes', **props)
                              self._add_volume_pollers(volume['name'])
                  
                      def _add_volume_pollers(self, name):
                          pollers_enabled = {
                              'V.Details.SNMP.Generic': True,
                              'V.Statistics.SNMP.Generic': True,
                              'V.Status.SNMP.Generic': True
                          }
                  
                          pollers = []
                          for k in pollers_enabled:
                              pollers.append(
                                  {
                                      'PollerType': k,
                                      'NetObject': 'V:' + self._nodeid,
                                      'NetObjectType': 'V',
                                      'NetObjectID': self._nodeid,
                                      'Enabled': pollers_enabled[k]
                                  }
                              )
                  
                          for poller in pollers:
                              print("  Adding [{}] volume poller type: {} with status {}... ".\
                                    format(name,
                                          poller['PollerType'],
                                          poller['Enabled']),
                                    end="")
                              response = self._swis.create('Orion.Pollers', **poller)
                              print("DONE!")
                  

                   

                  --

                  Steven Klassen

                  Developer Analyst @ Loop1 Systems, Inc.

                  http://www.loop1systems.com/

                    • Re: How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?
                      beagless

                      Hi Steven

                      Would running the above against an already discovered node with new volumes add the new volumes to be monitored ?

                       

                      many thanks

                      Paul

                          • Re: How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?
                            beagless

                            Hi Steven

                            Please excuse my lack of python knowledge but should this work

                             

                            #!/usr/bin/env python
                            import requests
                            from orionsdk import SwisClient

                            npm_server = 'server'
                            username = 'username'
                            password = 'password'

                             

                            swis = SwisClient(npm_server, username, password)

                             

                            def _add_volumes_to_solarwinds(self):
                                now = datetime.utcnow()
                                for volume in self.node.volumes:
                                        props = {
                                            'NodeID': self._nodeid,
                                            'Icon': 'FixedDisk.gif',
                                            'Index': volume['index'],
                                            'Caption': volume['name'],
                                            'StatusIcon': 'Up.gif',
                                            'Type': 'Fixed Disk',
                                            'Size': volume['size'],
                                            'Responding': 'Y',
                                            'FullName': '{}-{}'.format(self.node.sysinfo['sysname'], volume['name']),
                                            'VolumeDescription': volume['name'],
                                            'VolumePercentUsed': str(int(volume['used']) / int(volume['size']) * 100),
                                            'VolumeAllocationFailuresThisHour': None,
                                            'VolumeSpaceUsed': volume['used'],
                                            'VolumeAllocationFailuresToday': '',
                                            'VolumeSpaceAvailable': str(int(volume['size']) - int(volume['used'])),
                                        }

                                        ret = self._swis.create('Orion.Volumes', **props)
                                        self._add_volume_pollers(volume['name'])

                                def _add_volume_pollers(self, name):
                                    pollers_enabled = {
                                        'V.Details.SNMP.Generic': True,
                                        'V.Statistics.SNMP.Generic': True,
                                        'V.Status.SNMP.Generic': True
                                    }

                                    pollers = []
                                    for k in pollers_enabled:
                                        pollers.append(
                                            {
                                                'PollerType': k,
                                                'NetObject': 'V:' + self._nodeid,
                                                'NetObjectType': 'V',
                                                'NetObjectID': self._nodeid,
                                                'Enabled': pollers_enabled[k]
                                            }
                                        )

                                    for poller in pollers:
                                        print("  Adding [{}] volume poller type: {} with status {}... ".\
                                              format(""name,
                                                    poller['PollerType'],
                                                    poller['Enabled']),
                                              end="")
                                        response = self._swis.create('Orion.Pollers', **poller)
                                        print("DONE!")

                             

                             

                            when I run I get an error on line   print("  Adding [{}] volume poller type: {} with status {}... ".\ - unexpected character

                             

                            thanks for the reply it is appreciated

                                • Re: How do I add CPU, RAM, and Disk pollers to a new SNMP node via the Python API?
                                  beagless

                                  HI Steven

                                  Thanks for you help, the script runs now without error but it doesn't update the node

                                   

                                  i added pdb to see whats happening

                                   

                                  > /root/solar.py(8)<module>()

                                  -> hostname  = 'removed'

                                  (Pdb) n

                                  > /root/solar.py(9)<module>()

                                  -> username = 'iremoved'

                                  (Pdb) n

                                  > /root/solar.py(10)<module>()

                                  -> password = 'Removed'

                                  (Pdb) n

                                  > /root/solar.py(12)<module>()

                                  -> swis = SwisClient("hostname", "username", "password")

                                  (Pdb) n

                                  > /root/solar.py(14)<module>()

                                  -> def _add_volumes_to_solarwinds(self):

                                  (Pdb) n

                                  > /root/solar.py(39)<module>()

                                  -> def _add_volume_pollers(self, name):

                                  (Pdb) n

                                  --Return--

                                  > /root/solar.py(39)<module>()->None

                                  -> def _add_volume_pollers(self, name):

                                  (Pdb) n

                                   

                                  While running through the script it stops at  def _add_volume_pollers with () ->NONE and wont go any further

                                  The system i'm testing on has python 2.6 and we recently upgraded to NPM version 12

                                   

                                   

                                  #!/usr/bin/env python

                                  from __future__ import print_function

                                  import pdb

                                  import requests

                                  from orionsdk import SwisClient

                                  import pdb;pdb.set_trace()

                                   

                                   

                                  hostname  = 'removed'

                                  username = 'removed'

                                  password = removed'

                                   

                                   

                                  swis = SwisClient("hostname", "username", "password")

                                   

                                   

                                  def _add_volumes_to_solarwinds(self):

                                        now = datetime.utcnow()

                                   

                                   

                                        for volume in self.node.volumes:

                                            props = {

                                                'NodeID': self._nodeid,

                                                'Icon': 'FixedDisk.gif',

                                                'Index': volume['index'],

                                                'Caption': volume['name'],

                                                'StatusIcon': 'Up.gif',

                                                'Type': 'Fixed Disk',

                                                'Size': volume['size'],

                                                'Responding': 'Y',

                                                'FullName': '{}-{}'.format(self.node.sysinfo['sysname'], volume['name']),

                                                'VolumeDescription': volume['name'],

                                                'VolumePercentUsed': str(int(volume['used']) / int(volume['size']) * 100),

                                                'VolumeAllocationFailuresThisHour': None,

                                                'VolumeSpaceUsed': volume['used'],

                                                'VolumeAllocationFailuresToday': '',

                                                'VolumeSpaceAvailable': str(int(volume['size']) - int(volume['used'])),

                                            }

                                   

                                   

                                            ret = self._swis.create('Orion.Volumes', **props)

                                            self._add_volume_pollers(volume['name'])

                                   

                                   

                                  def _add_volume_pollers(self, name):

                                      pollers_enabled = {

                                          'V.Details.SNMP.Generic': True,

                                          'V.Statistics.SNMP.Generic': True,

                                          'V.Status.SNMP.Generic': True

                                      }

                                   

                                   

                                      pollers = []

                                      for k in pollers_enabled:

                                          pollers.append(

                                              {

                                                  'PollerType': k,

                                                  'NetObject': 'V:' + self._nodeid,

                                                  'NetObjectType': 'V',

                                                  'NetObjectID': self._nodeid,

                                                  'Enabled': pollers_enabled[k]

                                              }

                                            )

                                   

                                   

                                      for poller in pollers:

                                          print("  Adding [{}] volume poller type: {} with status {}... ".\

                                                format(name,

                                                      poller['PollerType'],

                                                      poller['Enabled']),

                                                end="")

                                          response = self._swis.create('Orion.Pollers', **poller)

                                          print("DONE!")