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

Source Code for Module ZenModel.StatusMonitorConf

  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__="""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   
41 -def manage_addStatusMonitorConf(context, id, title = None, REQUEST = None):
42 """make a monitor""" 43 dc = StatusMonitorConf(id, title) 44 context._setObject(id, dc) 45 46 if REQUEST is not None: 47 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
48 49 addStatusMonitorConf = DTMLFile('dtml/addStatusMonitorConf',globals()) 50
51 -class StatusMonitorConf(Monitor, StatusColor):
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 # Screen action bindings (and tab definitions) 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')
120 - def getPathName(self):
121 return self.id
122 123 security.declareProtected('View','getChunk')
124 - def getChunk(self):
125 '''get the chunk size''' 126 return self.chunk
127 128 security.declareProtected('View','getTimeOut')
129 - def getTimeOut(self):
130 '''get the timeout length''' 131 return self.timeOut
132 133 security.declareProtected('View','getTries')
134 - def getTries(self):
135 '''get the number of times to try on failure''' 136 return self.tries
137 138 security.declareProtected('View','getTimeOut')
139 - def getSnmpTimeOut(self):
140 '''get the timeout length''' 141 if not hasattr(self, 'snmpTimeOut'): 142 self.snmpTimeOut=3.0 143 return self.snmpTimeOut
144 145 security.declareProtected('View','getTries')
146 - def getSnmpTries(self):
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')
153 - def getCycleInterval(self):
154 '''get the number of seconds between sweeps''' 155 return self.cycleInterval
156 157 security.declareProtected('View','getConfigCycleInterval')
158 - def getConfigCycleInterval(self):
159 '''get the number of seconds between sweeps''' 160 return self.configCycleInterval
161 162 security.declareProtected('View','getCycleFailWarn')
163 - def getCycleFailWarn(self):
164 '''get the number of seconds between sweeps''' 165 if not hasattr(self, 'cycleFailWarn'): 166 self.cycleFailWarn=2 167 return self.cycleFailWarn
168 169 170 security.declareProtected('View','getCycleFailCritical')
171 - def getCycleFailCritical(self):
172 '''get the number of seconds between sweeps''' 173 if not hasattr(self, 'cycleFailCritical'): 174 self.cycleFailCritical=3 175 return self.cycleFailCritical
176 177 178 security.declareProtected('View','getMaxFailures')
179 - def getMaxFailures(self):
180 "return the number of failures allowed for a device" 181 return self.maxFailures
182 183 184 security.declareProtected('View','getPingDevices')
185 - def getPingDevices(self):
186 '''Return devices associated with this monitor configuration. 187 ''' 188 devices = [] 189 for dev in self.devices.objectValuesAll(): 190 dev = dev.primaryAq() 191 if dev.monitorDevice() and not dev.zPingMonitorIgnore: 192 devices.append(dev) 193 return devices
194 195 196 security.declareProtected('View','getExtraPingInterfaces')
197 - def getExtraPingInterfaces(self, dev):
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')
232 - def getSnmpDevices(self):
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')
255 - def updateSnmpDevices(self, devices):
256 '''process the snmp status information form the snmpmonitor''' 257 devs = self.getDmdRoot("Devices") 258 for hostname, uptime in devices: 259 try: 260 device = devs.findDevice(hostname) 261 if device and uptime: 262 device.setSnmpUpTime(long(uptime)) 263 except: 264 msg = "error updating device %s\n" % hostname 265 logging.exception(msg)
266 267
268 - def getPingHeartbeat(self):
269 """return ping heartbeat object""" 270 return self.pingHeartbeat
271 272
273 - def getPingHeartbeatString(self):
274 return self.pingHeartbeat.getString()
275 276
277 - def getSnmpHeartbeat(self):
278 """return snmp heartbeat object""" 279 return self.snmpHeartbeat
280 281
282 - def getSnmpHeartbeatString(self):
283 return self.snmpHeartbeat.getString()
284 285 286 security.declareProtected('Manage Device Status', 'setPingHeartbeat')
287 - def setPingHeartbeat(self):
288 """set the last time the ping monitor ran""" 289 self.pingHeartbeat.setDate()
290 291 292 security.declareProtected('Manage Device Status', 'setSnmpHeartbeat')
293 - def setSnmpHeartbeat(self):
294 """set the last time the snmp monitor ran""" 295 self.snmpHeartbeat.setDate()
296 297 298 InitializeClass(StatusMonitorConf) 299