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

Source Code for Module Products.ZenModel.CiscoLoader

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