1
2
3
4
5
6
7
8
9
10
11
12
13
14 from PerformanceConfig import PerformanceConfig
15 from Products.ZenHub.PBDaemon import translateError
16
17 from sets import Set
18
19 from Products.ZenRRD.zenperfsnmp import SnmpConfig
20
21 import logging
22 log = logging.getLogger('zen.SnmpPerfConfig')
25 oids = []
26 if comp.snmpIgnore(): return None
27 basepath = comp.rrdPath()
28 perfServer = comp.device().getPerformanceServer()
29 for templ in comp.getRRDTemplates():
30 for ds in templ.getRRDDataSources("SNMP"):
31 if not ds.enabled: continue
32 oid = ds.oid
33 if not oid: continue
34 snmpindex = getattr(comp, "ifindex", comp.snmpindex)
35 if snmpindex: oid = "%s.%s" % (oid, snmpindex)
36 for dp in ds.getRRDDataPoints():
37 cname = comp.meta_type != "Device" \
38 and comp.viewName() or dp.id
39 oids.append((cname,
40 oid,
41 "/".join((basepath, dp.name())),
42 dp.rrdtype,
43 dp.getRRDCreateCommand(perfServer),
44 (dp.rrdmin, dp.rrdmax)))
45 return (oids, comp.getThresholdInstances('SNMP'))
46
66
68
69 @translateError
71 """Return the subset of devices that should be monitored.
72
73 If devices is empty, then all the monitored devices are given.
74 """
75 if devices:
76 if not isinstance(devices, list):
77 devices = Set([devices])
78 else:
79 devices = Set(devices)
80 snmp = []
81 for dev in self.config.devices():
82 if devices and dev.id not in devices: continue
83 dev = dev.primaryAq()
84 if dev.snmpMonitorDevice():
85 snmp.append(dev.id)
86 return snmp
87
88
92
93
94 @translateError
105
106
107 @translateError
109 """Return a list of devices that have changed.
110 Takes a list of known devices and the time of last known change.
111 The result is a list of devices that have changed,
112 or not in the list."""
113 lastChanged = dict(devices)
114 new = Set()
115 all = Set()
116 for dev in self.config.devices():
117 dev = dev.primaryAq()
118 if dev.snmpMonitorDevice():
119 all.add(dev.id)
120 if lastChanged.get(dev.id, 0) < float(dev.getLastChange()):
121 new.add(dev.id)
122 deleted = Set(lastChanged.keys()) - all
123 return list(new | deleted)
124
125
127 "Template method helper for PerformanceConfig.pushConfig"
128 return listener.callRemote('updateDeviceConfig', config)
129
130
137