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

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