Package Products :: Package ZenRRD :: Module RRDDaemon |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenRRD.RRDDaemon

      1  #! /usr/bin/env python
      2  ###########################################################################
      3  #
      4  # This program is part of Zenoss Core, an open source monitoring platform.
      5  # Copyright (C) 2007, Zenoss Inc.
      6  #
      7  # This program is free software; you can redistribute it and/or modify it
      8  # under the terms of the GNU General Public License version 2 as published by
      9  # the Free Software Foundation.
     10  #
     11  # For complete information please visit: http://www.zenoss.com/oss/
     12  #
     13  ###########################################################################
     14
     15  __doc__= """RRDDaemon
     16
     17  Common performance monitoring daemon code for performance daemons.
     18  """
     19
     20  import socket
     21
     22  import Globals
     23  from Products.ZenEvents import Event
     24
     25  from twisted.python import failure
     26
     27  from Products.ZenHub.PBDaemon import FakeRemote, PBDaemon
     28  from Products.ZenRRD.Thresholds import Thresholds
     29  from Products.ZenUtils.Utils import unused
     30
     31
     32  BAD_SEVERITY=Event.Warning
     33
     34  BASE_URL = 'http://localhost:8080/zport/dmd'
     35  DEFAULT_URL = BASE_URL + '/Monitors/Performance/localhost'
     36
     37
     38  COMMON_EVENT_INFO = {
     39      'manager': socket.getfqdn(),
     40      }
     41
     42
     43 -class RRDDaemon(PBDaemon):
     44      """
     45      Holds the code common to performance gathering daemons.
     46      """
     47
     48      properties = ('configCycleInterval',)
     49      configCycleInterval = 20            # minutes
     50      rrd = None
     51      shutdown = False
     52      thresholds = None
     53
     54 -    def __init__(self, name, noopts=False):
     55          """
     56          Initializer
     57
     58          @param name: name of the daemon
     59          @type name: string
     60          @param noopts: process command-line arguments?
     61          @type noopts: boolean
     62          """
     63          self.events = []
     64          PBDaemon.__init__(self, noopts, name=name)
     65          self.thresholds = Thresholds()
     66
     67
     68 -    def getDevicePingIssues(self):
     69          """
     70          Determine which devices we shouldn't expect to hear back from.
     71
     72          @return: list of devices
     73          @rtype: list
     74          """
     75          return self.eventService().callRemote('getDevicePingIssues')
     76
     77
     78 -    def remote_setPropertyItems(self, items):
     79          """
     80          Set zProperties provided from zenhub.
     81
     82          @param items: list of zProperties to obtain
     83          @type items: list
     84          """
     85          self.log.debug("Async update of collection properties")
     86          self.setPropertyItems(items)
     87
     88
     89 -    def remote_updateDeviceList(self, devices):
     90          """
     91          Callable from zenhub.
     92
     93          @param devices: list of devices (unused)
     94          @type devices: list
     95          """
     96          unused(devices)
     97          self.log.debug("Async update of device list")
     98
     99
    100 -    def setPropertyItems(self, items):
    101          """
    102          Set zProperties
    103
    104          @param items: list of zProperties
    105          @type items: list
    106          """
    107          table = dict(items)
    108          for name in self.properties:
    109              value = table.get(name, None)
    110              if value is not None:
    111                  if getattr(self, name) != value:
    112                      self.log.debug('Updated %s config to %s' % (name, value))
    113                  setattr(self, name, value)
    114
    115
    116 -    def sendThresholdEvent(self, **kw):
    117          """
    118          "Send the right event class for threshhold events"
    119
    120          @param kw: keyword arguments describing an event
    121          @type kw: dictionary of keyword arguments
    122          """
    123          self.sendEvent({}, **kw)
    124
    125
    126 -    def buildOptions(self):
    127          """
    128          Command-line options to add
    129          """
    130          PBDaemon.buildOptions(self)
    131          self.parser.add_option('-d', '--device',
    132                                 dest='device',
    133                                 default='',
    134                                 help="Specify a specific device to monitor")
    135
    136
    137 -    def logError(self, msg, error):
    138          """
    139          Log messages to the logger
    140
    141          @param msg: the message
    142          @type msg: string
    143          @param error: an exception
    144          @type error: Exception
    145          """
    146          if isinstance(error, failure.Failure):
    147              from twisted.internet.error import TimeoutError
    148              if isinstance(error.value, TimeoutError):
    149                  self.log.warning("Timeout Error")
    150              else:
    151                  self.log.exception(error)
    152          else:
    153              self.log.error('%s %s', msg, error)
    154
    155
    156 -    def error(self, error):
    157          """
    158          Log an error, including any traceback data for a failure Exception
    159          Stop if we got the --cycle command-line option.
    160
    161          @param error: the error message
    162          @type error: string
    163          """
    164          self.logError('Error', error)
    165          if not self.options.cycle:
    166              self.stop()
    167
    168
    169 -    def errorStop(self, why):
    170          """
    171          Twisted callback to receive fatal messages.
    172
    173          @param why: the error message
    174          @type why: string
    175          """
    176          self.error(why)
    177          self.stop()
    178
    179
    180 -    def model(self):
    181          """
    182          Return the list of services from zenhub
    183
    184          @return: list of services
    185          @rtype: list
    186          """
    187          return self.services.get(self.initialServices[-1], FakeRemote())
    188