1
2
3
4
5
6
7
8
9
10
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
35 '''Load a machine'''
36
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
75
76
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