Package Products :: Package ZenModel :: Module CiscoLoader |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.CiscoLoader

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  __doc__="""CiscoLoader.py
    12
    13  CiscoLoader.py populates the sysObjectIdClassifier with Cisco product data
    14  by parsing their Products mib.
    15
    16  $Id: CiscoLoader.py,v 1.2 2004/02/18 16:19:18 edahl Exp $"""
    17
    18  __version__ = "$Revision: 1.2 $"[11:-2]
    19
    20  import re
    21
    22  import Globals
    23
    24  from Products.ZenUtils.BasicLoader import BasicLoader
    25  from Products.ZenModel.Manufacturer import manage_addManufacturer
    26  from Products.ZenModel.HardwareClass import HardwareClass
    27
    28 -class CiscoLoader(BasicLoader):
    29      '''Load a machine'''
    30
    31 -    def __init__(self):
    32          '''Handle command line options, get app instance,
    33          load caches and setup log file'''
    34          BasicLoader.__init__(self)
    35          manuf = self.dmd.Manufacturers
    36          if not hasattr(manuf, 'Cisco'):
    37              manage_addManufacturer(manuf, 'Cisco')
    38          self.cisco = manuf._getOb('Cisco')
    39
    40
    41      lineparser1 = re.compile(
    42          r'^(?P<model>\w+)\s+OBJ.*Products (?P<id>\d+) \}.*-- (?P<descr>.*)')
    43      lineparser2 = re.compile(
    44          r'^(?P<model>\w+)\s+OBJ.*Products (?P<id>\d+) \}.*')
    45
    46      modelclean = re.compile(r'cisco|catalyst')
    47
    48 -    def loaderBody(self,line):
    49          """loader body override to customize what will load"""
    50          m = self.lineparser1.match(line)
    51          if not m: m = self.lineparser2.match(line)
    52          if not m: return
    53          fullid = '.1.3.6.1.4.1.9.1.' + m.group('id')
    54          model = self.modelclean.sub('', m.group('model'))
    55          description = ""
    56          try:
    57              description = m.group('descr')
    58          except:pass
    59          self.log.debug("Loading fullid=%s,prodpath=%s,descr=%s"
    60                            % (fullid, model, description))
    61          prod = HardwareClass(model,productKey=fullid,description=description)
    62          self.cisco.products._setObject(model, prod)
    63
    64
    65
    66 -    def buildOptions(self):
    67          self.usage = "%prog [options] file"
    68          BasicLoader.buildOptions(self)
    69
    70
    71 -    def parseOptions(self):
    72          (self.options, args) = self.parser.parse_args()
    73          if len(args) < 1:
    74              self.parser.error("incorrect number of arguments")
    75          self.filename = args[0]
    76
    77
    78  if __name__ == "__main__":
    79      loader = CiscoLoader()
    80      loader.loadDatabase()
    81      print "Database Load is finished!"
    82