1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""StatusMonitorConf
15
16 The configuration object for monitors.
17
18 $Id: StatusMonitorConf.py,v 1.40 2004/04/22 02:13:23 edahl Exp $"""
19
20 __version__ = "$Revision: 1.40 $"[11:-2]
21
22 import re
23 import logging
24
25 from AccessControl import ClassSecurityInfo
26 from Globals import DTMLFile
27 from Globals import InitializeClass
28 from DateTime import DateTime
29
30 from zLOG import LOG, WARNING
31
32 from AccessControl import Permissions as permissions
33
34 from Products.ZenRelations.RelSchema import *
35
36 from Products.ZenModel.Monitor import Monitor
37 from Products.ZenModel.StatusColor import StatusColor
38 from Products.ZenModel.ZenDate import ZenDate
39
40
48
49 addStatusMonitorConf = DTMLFile('dtml/addStatusMonitorConf',globals())
50
52 '''Configuration for monitors'''
53 portal_type = meta_type = "StatusMonitorConf"
54
55 monitorRootName = "StatusMonitors"
56
57 chunk=75
58 timeOut=1.5
59 tries=2
60 snmpTimeOut=3.0
61 snmpTries=2
62 cycleInterval=60
63 configCycleInterval=20
64 maxFailures = 1440
65 cycleFailWarn = 2
66 cycleFailCritical = 3
67
68 _properties = (
69 {'id':'chunk','type':'int','mode':'w'},
70 {'id':'timeOut','type':'float','mode':'w'},
71 {'id':'tries','type':'int','mode':'w'},
72 {'id':'snmpTimeOut','type':'float','mode':'w'},
73 {'id':'snmpTries','type':'int','mode':'w'},
74 {'id':'cycleInterval','type':'int','mode':'w'},
75 {'id':'cycleFailWarn','type':'int','mode':'w'},
76 {'id':'cycleFailCritical','type':'int','mode':'w'},
77 {'id':'configCycleInterval','type':'int','mode':'w'},
78 {'id':'maxFailures','type':'int','mode':'w'},
79 )
80 _relations = (
81 ("devices", ToMany(ToMany,"Products.ZenModel.Device","monitors")),
82 )
83
84
85 factory_type_information = (
86 {
87 'id' : 'StatusMonitorConf',
88 'meta_type' : 'StatusMonitorConf',
89 'description' : """Arbitrary device grouping class""",
90 'icon' : 'StatusMonitorConf_icon.gif',
91 'product' : 'ZenModel',
92 'factory' : 'manage_addStatusMonitorconf',
93 'immediate_view' : 'viewStatusMonitorOverview',
94 'actions' :
95 (
96 { 'id' : 'overview'
97 , 'name' : 'Overview'
98 , 'action' : 'viewStatusMonitorOverview'
99 , 'permissions' : (
100 permissions.view, )
101 },
102 { 'id' : 'edit'
103 , 'name' : 'Edit'
104 , 'action' : 'editStatusMonitorConf'
105 , 'permissions' : ("Manage DMD",)
106 },
107 { 'id' : 'viewHistory'
108 , 'name' : 'Modifications'
109 , 'action' : 'viewHistory'
110 , 'permissions' : (
111 permissions.view, )
112 },
113 )
114 },
115 )
116
117 security = ClassSecurityInfo()
118
119 security.declareProtected('View','getPathName')
122
123 security.declareProtected('View','getChunk')
125 '''get the chunk size'''
126 return self.chunk
127
128 security.declareProtected('View','getTimeOut')
130 '''get the timeout length'''
131 return self.timeOut
132
133 security.declareProtected('View','getTries')
135 '''get the number of times to try on failure'''
136 return self.tries
137
138 security.declareProtected('View','getTimeOut')
144
145 security.declareProtected('View','getTries')
147 '''get the number of times to try on failure'''
148 if not hasattr(self, 'snmpTies'):
149 self.snmpTies=2
150 return self.snmpTries
151
152 security.declareProtected('View','getCycleInterval')
154 '''get the number of seconds between sweeps'''
155 return self.cycleInterval
156
157 security.declareProtected('View','getConfigCycleInterval')
161
162 security.declareProtected('View','getCycleFailWarn')
168
169
170 security.declareProtected('View','getCycleFailCritical')
176
177
178 security.declareProtected('View','getMaxFailures')
180 "return the number of failures allowed for a device"
181 return self.maxFailures
182
183
184 security.declareProtected('View','getPingDevices')
194
195
196 security.declareProtected('View','getExtraPingInterfaces')
198 """collect other interfaces to ping based on
199 aquired value pingInterfaceSpecifications"""
200 intDescr = getattr(dev, 'zPingInterfaceDescription', None)
201 intName = getattr(dev, 'zPingInterfaceName', None)
202 catalog = getattr(dev, 'interfaceSearch', None)
203 interfaces = {}
204 if catalog:
205 results = []
206 if intName:
207 namequery = {}
208 namequery['deviceName'] = dev.getId()
209 namequery['interfaceName'] = intName
210 results += catalog(namequery)
211 if intDescr:
212 descrquery = {}
213 descrquery['deviceName'] = dev.getId()
214 descrquery['description'] = intDescr
215 results += catalog(descrquery)
216 for result in results:
217 int = self.getZopeObj(result.getPrimaryUrlPath)
218 if (int and int.adminStatus == 1
219 and not interfaces.has_key(int)):
220 ip = int.getIp()
221 if ip:
222 name = dev.getId() + ":" + int.getId()
223 interfaces[int] = (
224 name,
225 ip,
226 int.absolute_url(),
227 int.getPingStatusNumber())
228 return interfaces.values()
229
230
231 security.declareProtected('View','getSnmpDevices')
233 '''get the devices associated with this
234 monitor configuration'''
235 devices = []
236 for dev in self.devices.objectValuesAll():
237 try:
238 dev = dev.primaryAq()
239 if getattr(dev, "zSnmpMonitorIgnore", False): continue
240 ipaddr = dev.getManageIp()
241 url = dev.absolute_url()
242 if dev.monitorDevice() and dev.zSnmpCommunity:
243 devices.append((
244 dev.id, url, ipaddr,
245 dev.getSnmpStatusNumber(),
246 dev.zSnmpCommunity,
247 dev.zSnmpPort))
248 except:
249 msg = "exception getting device %s\n" % dev.getId()
250 logging.exception(msg)
251 return devices
252
253
254 security.declareProtected('View','updateSnmpDevices')
266
267
269 """return ping heartbeat object"""
270 return self.pingHeartbeat
271
272
275
276
278 """return snmp heartbeat object"""
279 return self.snmpHeartbeat
280
281
284
285
286 security.declareProtected('Manage Device Status', 'setPingHeartbeat')
288 """set the last time the ping monitor ran"""
289 self.pingHeartbeat.setDate()
290
291
292 security.declareProtected('Manage Device Status', 'setSnmpHeartbeat')
294 """set the last time the snmp monitor ran"""
295 self.snmpHeartbeat.setDate()
296
297
298 InitializeClass(StatusMonitorConf)
299