Trees | Indices | Help |
|
---|
|
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 #! /usr/bin/env python 14 15 import Globals 16 from Products.ZenEvents.ZenEventClasses import Status_Snmp 17 18 from Products.ZenHub.HubService import HubService 19 20 from Products.ZenModel.Device import Device 21 from Acquisition import aq_parent, aq_base 22 23 from twisted.internet import reactor, defer 24 25 from Procrastinator import Procrastinate 262815530 HubService.__init__(self, dmd, instance) 31 self.config = self.dmd.Monitors.Performance._getOb(self.instance) 32 self.procrastinator = Procrastinate(self.pushConfig)33 34 37 3840 "Return the failure counts for Snmp" 41 result = [] 42 counts = {} 43 try: 44 # get all the events with /Status/Snmp 45 conn = self.zem.connect() 46 try: 47 curs = conn.cursor() 48 cmd = ('SELECT device, sum(count) ' + 49 ' FROM status ' + 50 ' WHERE eventClass = "%s"' % Status_Snmp) 51 if devname: 52 cmd += ' AND device = "%s"' % devname 53 cmd += ' GROUP BY device' 54 curs.execute(cmd); 55 counts = dict([(d, int(c)) for d, c in curs.fetchall()]) 56 finally: 57 self.zem.close(conn) 58 except Exception, ex: 59 self.log.exception('Unable to get Snmp Status') 60 raise 61 if devname: 62 return [(devname, counts.get(devname, 0))] 63 return [(dev.id, counts.get(dev.id, 0)) for dev in self.config.devices()]64 6567 return self.config.getDefaultRRDCreateCommand(*args, **kwargs)68 6971 from Products.ZenModel.MinMaxThreshold import MinMaxThreshold 72 classes = [MinMaxThreshold] 73 for pack in self.dmd.packs(): 74 classes += pack.getThresholdClasses() 75 return map(lambda c: c.__module__, classes)76 77 81 8284 deferreds = [] 85 cfg = self.getDeviceConfig(device) 86 for listener in self.listeners: 87 if cfg is None: 88 deferreds.append(listener.callRemote('deleteDevice', device.id)) 89 else: 90 deferreds.append(self.sendDeviceConfig(listener, cfg)) 91 return defer.DeferredList(deferreds)92 93 97 98 102 103105 if not self.listeners: 106 return 107 108 # the PerformanceConf changed 109 from Products.ZenModel.PerformanceConf import PerformanceConf 110 if isinstance(object, PerformanceConf) and object.id == self.instance: 111 for listener in self.listeners: 112 listener.callRemote('setPropertyItems', object.propertyItems()) 113 devices = [ 114 (d.id, float(d.getLastChange())) for d in object.devices() 115 ] 116 # listener.callRemote('updateDeviceList', devices) 117 118 # a ZenPack is installed 119 from Products.ZenModel.ZenPack import ZenPack 120 if isinstance(object, ZenPack): 121 for listener in self.listeners: 122 try: 123 listener.callRemote('updateThresholdClasses', 124 self.remote_getThresholdClasses()) 125 except Exception, ex: 126 self.log.exception("Error notifying a listener of new classes") 127 128 # device has been changed: 129 if isinstance(object, Device): 130 self.notifyAll(object) 131 return 132 133 # somethinge else... mark the devices as out-of-date 134 from Products.ZenModel.DeviceClass import DeviceClass 135 136 import transaction 137 while object: 138 # walk up until you hit an organizer or a device 139 if isinstance(object, DeviceClass): 140 for device in object.getSubDevices(): 141 self.notifyAll(device) 142 break 143 144 if isinstance(object, Device): 145 self.notifyAll(object) 146 break 147 148 object = aq_parent(object)149 150152 for listener in self.listeners: 153 if isinstance(obj, Device): 154 listener.callRemote('deleteDevice', obj.id)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:44 2007 | http://epydoc.sourceforge.net |