1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""BasicDeviceLoader.py
15
16 BasicDeviceLoader.py populates the dmd with devices from a file. The input file
17 only needs to have a list of machines. It uses the Classifier system
18 to figure out where in the DeviceClass a new device should be created.
19 If no location is found it will use a specified default path or put
20 the device in the top level of the DevicesClass tree.
21
22 $Id: BasicDeviceLoader.py,v 1.19 2004/04/04 01:51:19 edahl Exp $"""
23
24 __version__ = "$Revision: 1.19 $"[11:-2]
25
26 from logging import debug, info, warn, critical, exception
27
28 from Products.ZenModel.Exceptions import *
29
30
32 '''Load a machine'''
33
34 - def loadDevice(self, deviceName, devicePath="", systemPath="",
35 manufacturer="", model="", groupPath="",
36 locationPath="", rack="",
37 statusMonitorName="localhost", perfMonitorName="localhost",
38 snmpCommunity="", snmpPort=None,
39 loginName="", loginPassword=""):
40 """load a device into the database"""
41 info("adding device %s" % deviceName)
42 device = self.getDevice(deviceName, devicePath, snmpCommunity, snmpPort,
43 loginName, loginPassword)
44
45 if manufacturer and model:
46 info("setting manufacturer to %s model to %s"
47 % (manufacturer, model))
48 device.setModel(manufacturer, model)
49
50 if not locationPath: locationPath = self.getLocationPath()
51 if locationPath:
52 if rack:
53 locationPath += "/%s" % rack
54 info("setting rack location to %s" % locationPath)
55 device.setRackLocation(locationPath)
56 else:
57 info("setting location to %s" % locationPath)
58 device.setLocation(locationPath)
59
60 if not groupPath: groupPath = self.getGroupPath()
61 if groupPath:
62 info("setting group %s" % groupPath)
63 device.setGroups(groupPath)
64
65 if not systemPath: systemPath = self.getSystemPath()
66 if systemPath:
67 info("setting system %s" % systemPath)
68 device.setSystems(systemPath)
69
70 if not statusMonitorName:
71 statusMonitorName = self.getStatusMonitorName()
72 info("setting status monitor to %s" % statusMonitorName)
73 device.setStatusMonitor(statusMonitorName)
74
75 if not perfMonitorName:
76 perfMonitorName = self.getPerformanceMonitorName()
77 info("setting performance monitor to %s" % perfMonitorName)
78 device.setPerformanceMonitor(perfMonitorName)
79
80 return device
81
82
83 - def getDevice(self, deviceName, devicePath,
84 snmpCommunity, snmpPort, loginName, loginPassword):
85 """get a device if devicePath is None try classifier"""
86 self.classificationEntry = None
87 if self.getDmdRoot("Devices").findDevice(deviceName):
88 raise DeviceExistsError, "Device %s already exists" % deviceName
89 if not devicePath:
90 self.classificationEntry = \
91 self.getDmdRoot("Devices").ZenClassifier.classifyDevice(
92 deviceName,
93 snmpCommunity, snmpPort,
94 loginName, loginPassword)
95 if not self.classificationEntry:
96 raise DeviceNotClassified, \
97 "classifier failed to classify device %s" % deviceName
98 devicePath = self.classificationEntry.getDeviceClassPath
99
100 deviceClass = self.getDmdRoot("Devices").getOrganizer(devicePath)
101 if not deviceClass:
102 raise PathNotFoundError, \
103 "Path to device %s is not valid" % deviceName
104 return deviceClass.createInstance(deviceName)
105
106
108 """get the location path for an object"""
109 pass
110
111
113 """override if you need to derive the group name from something else"""
114 pass
115
116
118 """override if you need to derive the system name from something else"""
119 pass
120
121
123 """return the status monitor name, default is localhost"""
124 return "localhost"
125
126
130
131
132 if __name__ == "__main__":
133 loader = BasicDeviceLoader()
134 loader.loadDatabase()
135 print "Database Load is finished!"
136