Package ZenHub :: Package services :: Module StatusConfig
[hide private]
[frames] | no frames]

Source Code for Module ZenHub.services.StatusConfig

 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  from Products.ZenHub.HubService import HubService 
16   
17  from Products.ZenEvents.ZenEventClasses import Status_IpService 
18  from Products.ZenModel.Device import Device 
19  from Acquisition import aq_parent, aq_base 
20   
21  from Procrastinator import Procrastinate 
22   
23  from twisted.internet import reactor, defer 
24  from sets import Set 
25   
26  from twisted.spread import pb 
27 -class ServiceConfig(pb.Copyable, pb.RemoteCopy):
28
29 - def __init__(self, svc):
30 self.device = svc.hostname() 31 self.component = svc.name() 32 self.ip = svc.getManageIp() 33 self.port = svc.getPort() 34 self.sendString = svc.getSendString() 35 self.expectRegex = svc.getExpectRegex() 36 self.timeout = svc.zStatusConnectTimeout 37 self.failSeverity = svc.getFailSeverity() 38 self.key = svc.key()
39 pb.setUnjellyableForClass(ServiceConfig, ServiceConfig) 40
41 -class StatusConfig(HubService):
42
43 - def __init__(self, dmd, instance):
44 HubService.__init__(self, dmd, instance) 45 self.config = self.dmd.Monitors.Performance._getOb(self.instance) 46 self.procrastinator = Procrastinate(self.notify)
47
48 - def remote_propertyItems(self):
49 return self.config.propertyItems()
50
51 - def remote_serviceStatus(self):
52 zem = self.dmd.ZenEventManager 53 status = zem.getAllComponentStatus(Status_IpService) 54 devices = Set([d.id for d in self.config.devices()]) 55 return [x for x in status.items() if x[0][0] in devices]
56
57 - def remote_services(self, configpath):
58 result = [] 59 for dev in self.config.devices(): 60 dev = dev.primaryAq() 61 if not dev.monitorDevice(): continue 62 for svc in dev.getMonitoredComponents(collector='zenstatus'): 63 if svc.getProtocol() != "tcp": continue 64 result.append(ServiceConfig(svc)) 65 return result
66 67
68 - def update(self, object):
69 if not self.listeners: return 70 71 # the PerformanceConf changed 72 from Products.ZenModel.PerformanceConf import PerformanceConf 73 if isinstance(object, PerformanceConf): 74 for listener in self.listeners: 75 listener.callRemote('setPropertyItems', object.propertyItems()) 76 devices = [ 77 (d.id, float(d.getLastChange())) for d in object.devices() 78 ] 79 # listener.callRemote('updateDeviceList', devices) 80 self.procrastinator.doLater()
81
82 - def notify(self, unused):
83 lst = [] 84 for listener in self.listeners: 85 lst.append(listener.callRemote('notifyConfigChanged')) 86 return defer.DeferredList(lst)
87
88 - def deleted(self, obj):
89 for listener in self.listeners: 90 if isinstance(obj, Device): 91 listener.callRemote('deleteDevice', obj.id)
92