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 or (at your
     8  # option) any later version as published by 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          # FIXME: No longer called
    46          pass
    47
    48 -    def deleted(self, object):
    49          # FIXME: No longer called
    50          pass
    51
    52 -    def name(self):
    53          return self.__class__.__name__
    54
    55 -    def addListener(self, remote):
    56          remote.notifyOnDisconnect(self.removeListener)
    57          self.log.debug("adding listener for %s:%s", self.instance, self.name())
    58          self.listeners.append(remote)
    59
    60 -    def removeListener(self, listener):
    61          self.log.debug("removing listener for %s:%s", self.instance, self.name())
    62          try:
    63              self.listeners.remove(listener)
    64          except ValueError:
    65              self.warning("Unable to remove listener... ignoring")
    66
    67 -    def getMethodPriority(self, methodName):
    68          if methodName in self.methodPriorityMap:
    69              return self.methodPriorityMap[methodName]
    70          return 0.2
    71
    72 -    def sendEvents(self, events):
    73          map(self.sendEvent, events)
    74
    75 -    def sendEvent(self, event, **kw):
    76          event = event.copy()
    77          event['agent'] = 'zenhub'
    78          event['monitor'] = self.instance
    79          event['manager'] = self.fqdn
    80          event.update(kw)
    81          self.zem.sendEvent(event)
    82