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