2 Replies Latest reply on Jun 10, 2016 10:38 AM by edondurguti

    add nodes to NCM via python

    edondurguti

      I have a script that add nodes to NPM, i'd like to be able to add the same node to NCM:

      I found this:

      https://pypi.python.org/pypi/swisclient/1.0.1

      but im not really sure how to implement this, I am a beginner / newbie in programming so any help would be appreciated.

      thanks

       

      here is the script:

       

      # -*- encoding: utf-8 -*-

      from __future__ import print_function

      import re

      import orionsdk

      import requests

      import sys

      from orionsdk import SwisClient

      import re

      from pprint import pprint as pp

      sys.argv

       

       

       

       

      class NodeManager:

          def __init__(self):

              self._swis = SwisClient(

                  '10.95.237.54',

                  'test',

                  'test')

       

       

          def add_local_node(self):

              self._add_node_element()

              self._add_pollers()

              self._pollnow()

       

       

          def _add_node_element(self):

              props = {

                  'Caption': sys.argv[2],

                  'IPAddress': sys.argv[1],

                  'DynamicIP': False,

                  'EngineID': 2,

                  'Allow64BitCounters': 1,

                  'ObjectSubType': 'ICMP',

                  'SNMPVersion': 2,

                  'RediscoveryInterval': 30,

                  'PollInterval': 120,

                  'ChildStatus': 1,

                  'StatCollection': 10,

                  #'AddNodetoNCM': 1,

                  'Community': 'test',

              }

       

       

              print("Adding node {}... ".format(props['IPAddress']), end="")

              results = self._swis.create('Orion.Nodes', **props)

              print("DONE!")

       

       

              self._nodeid = self._parse_node(results)

       

       

          def _parse_node(self, results):

              return re.search('(\d+)$', results).group(0)

       

       

          def _add_pollers(self):

              pollers_enabled = {

                  'N.Status.ICMP.Native': True,

                  'N.Status.SNMP.Native': False,

                  'N.ResponseTime.ICMP.Native': True,

                  'N.ResponseTime.SNMP.Native': False,

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

                  'N.Uptime.SNMP.Generic': True,

                  'N.Cpu.SNMP.HrProcessorLoad': True,

                  'N.Memory.SNMP.NetSnmpReal': True,

                  'N.AssetInventory.Snmp.Generic': True,

                  'N.Status.SNMP.Native': False,

                  'N.ResponseTime.SNMP.Native': False,

                  'N.Topology_Layer3.SNMP.ipNetToMedia': False,

                  'N.Routing.SNMP.Ipv4CidrRoutingTable': False

              }

       

       

              pollers = []

              for k in pollers_enabled:

                  pollers.append(

                      {

                          'PollerType': k,

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

                          'NetObjectType': 'N',

                          'NetObjectID': self._nodeid,

                          'Enabled': pollers_enabled[k]

                      }

                  )

       

       

              for poller in pollers:

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

                        format(poller['PollerType'],

                               poller['Enabled']),

                        end="")

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

                  print("DONE!")

       

       

          def _configure_custom_properties(self):

              pass

       

       

          def _pollnow(self):

              print("    Forcing a polling now... ", end="")

              self._swis.invoke('Orion.Nodes', 'PollNow', 'N:' + self._nodeid)

              print("DONE!")

       

       

       

       

      def main():

          nm = NodeManager()

          nm.add_local_node()

       

       

       

       

      if __name__ == '__main__':

          main()