Package Products :: Package ZenWin :: Package services :: Module WinServiceConfig |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenWin.services.WinServiceConfig

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007-2009, 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
     14  "Provides Wmi config to zenwin clients."
     15
     16  from Products.ZenCollector.services.config import CollectorConfigService
     17
     18  import logging
     19  log = logging.getLogger('zen.ModelerService.WinServiceConfig')
     20
     21 -class SmartService(object):
     22      "wraps a service and provides helper methods"
     23
     24 -    def __init__(self, service):
     25          self._service = service
     26
     27 -    def __getattr__(self, name):
     28          "delegate to the wrapped service"
     29          return getattr(self._service, name)
     30
     31      @property
     32 -    def isMonitored(self):
     33          "is the service monitored"
     34          return self._service.getStatus() >= 0
     35
     36      @property
     37 -    def name(self):
     38          "converts unicode service names"
     39          name = self._service.name()
     40          if type(name) == type(u''):
     41              name = name.encode(self._service.zCollectorDecoding)
     42          return name
     43
     44      @property
     45 -    def severity(self):
     46          return self._service.getAqProperty('zFailSeverity')
     47
     48 -def genServices(device):
     49      "generate services wrapped as SmartServices"
     50      for service in device.getMonitoredComponents(type='WinService'):
     51          yield SmartService(service)
     52
     53 -class WinServiceConfig(CollectorConfigService):
     54
     55 -    def __init__(self, dmd, instance):
     56          deviceProxyAttributes = ('zWmiMonitorIgnore',
     57                                   'zWinUser',
     58                                   'zWinPassword')
     59          CollectorConfigService.__init__(self, dmd, instance, deviceProxyAttributes)
     60
     61 -    def _filterDevice(self, device):
     62          include = CollectorConfigService._filterDevice(self, device)
     63
     64          if getattr(device, 'zWmiMonitorIgnore', False):
     65              self.log.debug("Device %s skipped because zWmiMonitorIgnore is True",
     66                             device.id)
     67              include = False
     68
     69          return include
     70
     71 -    def _createDeviceProxy(self, device):
     72          proxy = CollectorConfigService._createDeviceProxy(self, device)
     73
     74          # for now, every device gets a single configCycleInterval based upon
     75          # the collector's winCycleInterval configuration which is typically
     76          # located at dmd.Monitors.Performance._getOb('localhost').
     77          # TODO: create a zProperty that allows for individual device schedules
     78          proxy.configCycleInterval = self._prefs.winCycleInterval
     79
     80          proxy.services = {}
     81          for service in genServices(device):
     82              if service.isMonitored:
     83                  running = None
     84                  if service.getStatus() > 0:
     85                      running = False
     86                  else:
     87                      running = True
     88
     89                  proxy.services[service.name] = (
     90                      running, service.severity, None,
     91                      service.getMonitoredStartModes())
     92
     93          # don't bother adding this device proxy if there aren't any services
     94          # to monitor
     95          if not proxy.services:
     96              log.debug("Device %s skipped because there are no services",
     97                        proxy.id)
     98              return None
     99
    100          return proxy
    101