Package Products :: Package ZenHub :: Module HubService |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenHub.HubService

     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  from twisted.spread import pb
    14
    15  import logging
    16  import time
    17  import socket
    18
    19 -class HubService(pb.Referenceable):
    20
    21 -    def __init__(self, dmd, instance):
    22          self.log = logging.getLogger('zen.hub')
    23          self.fqdn = socket.getfqdn()
    24          self.dmd = dmd
    25          self.zem = dmd.ZenEventManager
    26          self.instance = instance
    27          self.listeners = []
    28          self.callTime = 0.
    29          self.methodPriorityMap = {}
    30
    31 -    def getPerformanceMonitor(self):
    32          return self.dmd.Monitors.getPerformanceMonitor(self.instance)
    33
    34 -    def remoteMessageReceived(self, broker, message, args, kw):
    35          self.log.debug("Servicing %s in %s", message, self.name())
    36          now = time.time()
    37          try:
    38              return pb.Referenceable.remoteMessageReceived(self, broker, message, args, kw)
    39          finally:
    40              secs = time.time() - now
    41              self.log.debug("Time in %s: %.2f", message, secs)
    42              self.callTime += secs
    43
    44 -    def update(self, object):
    45          pass
    46
    47 -    def deleted(self, object):
    48          pass
    49
    50 -    def name(self):
    51          return self.__class__.__name__
    52
    53 -    def addListener(self, remote):
    54          remote.notifyOnDisconnect(self.removeListener)
    55          self.log.debug("adding listener for %s:%s", self.instance, self.name())
    56          self.listeners.append(remote)
    57
    58 -    def removeListener(self, listener):
    59          self.log.debug("removing listener for %s:%s", self.instance, self.name())
    60          try:
    61              self.listeners.remove(listener)
    62          except ValueError:
    63              self.warning("Unable to remove listener... ignoring")
    64
    65 -    def getMethodPriority(self, methodName):
    66          if self.methodPriorityMap.has_key(methodName):
    67              return self.methodPriorityMap[methodName]
    68          return 0.4
    69
    70 -    def sendEvents(self, events):
    71          map(self.sendEvent, events)
    72
    73 -    def sendEvent(self, event, **kw):
    74          event = event.copy()
    75          event['agent'] = 'zenhub'
    76          event['monitor'] = self.instance
    77          event['manager'] = self.fqdn
    78          event.update(kw)
    79          self.zem.sendEvent(event)
    80