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

Source Code for Module 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 as published by 
 8  # 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  import os 
25   
26  import Globals 
27   
28  from OFS.Folder import manage_addFolder 
29   
30  from Products.ZenUtils.BasicLoader import BasicLoader 
31  from Products.ZenModel.Manufacturer import manage_addManufacturer 
32  from Products.ZenModel.HardwareClass import HardwareClass 
33   
34 -class CiscoLoader(BasicLoader):
35 '''Load a machine''' 36
37 - def __init__(self):
38 '''Handle command line options, get app instance, 39 load caches and setup log file''' 40 BasicLoader.__init__(self) 41 manuf = self.dmd.Manufacturers 42 if not hasattr(manuf, 'Cisco'): 43 manage_addManufacturer(manuf, 'Cisco') 44 self.cisco = manuf._getOb('Cisco')
45 46 47 lineparser1 = re.compile( 48 r'^(?P<model>\w+)\s+OBJ.*Products (?P<id>\d+) \}.*-- (?P<descr>.*)') 49 lineparser2 = re.compile( 50 r'^(?P<model>\w+)\s+OBJ.*Products (?P<id>\d+) \}.*') 51 52 modelclean = re.compile(r'cisco|catalyst') 53
54 - def loaderBody(self,line):
55 """loader body override to customize what will load""" 56 m = self.lineparser1.match(line) 57 if not m: m = self.lineparser2.match(line) 58 if not m: return 59 fullid = '.1.3.6.1.4.1.9.1.' + m.group('id') 60 model = self.modelclean.sub('', m.group('model')) 61 description = "" 62 try: 63 description = m.group('descr') 64 except:pass 65 self.log.debug("Loading fullid=%s,prodpath=%s,descr=%s" 66 % (fullid, model, description)) 67 prod = HardwareClass(model,productKey=fullid,description=description) 68 self.cisco.products._setObject(model, prod)
69 70 71
72 - def buildOptions(self):
73 self.usage = "%prog [options] file" 74 BasicLoader.buildOptions(self)
75 76
77 - def parseOptions(self):
78 (self.options, args) = self.parser.parse_args() 79 if len(args) < 1: 80 self.parser.error("incorrect number of arguments") 81 self.filename = args[0]
82 83 84 if __name__ == "__main__": 85 loader = CiscoLoader() 86 loader.loadDatabase() 87 print "Database Load is finished!" 88