Package Products :: Package ZenModel :: Module ThresholdInstance |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.ThresholdInstance

      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
     14  import os
     15
     16  import Globals
     17  from Products.ZenModel.PerformanceConf import PerformanceConf, performancePath
     18  from Products.ZenUtils.Utils import unused
     19
     20
     21  from twisted.spread import pb
     22 -class ThresholdContext(pb.Copyable, pb.RemoteCopy):
     23      """Remember all the little details about a specific data point
     24      within a context.  This is useful for error messages and path
     25      information in the collectors.  It's a copy of the key bits of
     26      information from the Model."""
     27
     28 -    def __init__(self, context):
     29          if isinstance(context, PerformanceConf):
     30              # Collector threshold events should have their device field set
     31              # to the collector's hostname if possible, and id otherwise.
     32              self.deviceName = getattr(context, 'hostname', context.id)
     33          else:
     34              self.deviceName = context.device().id
     35
     36          if hasattr( context, 'name' ) and callable( getattr( context, 'name' ) ):
     37              self.componentName = context.name()
     38          else:
     39              self.componentName = context.id
     40          if self.componentName == self.deviceName:
     41              self.componentName = ''
     42          self.rrdPath = context.rrdPath()
     43
     44
     45 -    def key(self):
     46          "Unique data that refers this context"
     47          return self.deviceName, self.componentName
     48
     49
     50 -    def fileKey(self, dataPoint):
     51          "Unique base filename for this context and given dataPoint"
     52          return os.path.join(self.rrdPath, dataPoint)
     53
     54
     55 -    def path(self, dataPoint):
     56          "The full pathname to RRD file that uses a dataPoint"
     57          return performancePath(os.path.join(self.rrdPath, dataPoint)) + '.rrd'
     58
     59  pb.setUnjellyableForClass(ThresholdContext, ThresholdContext)
     60
     61 -class ThresholdInstance(pb.Copyable, pb.RemoteCopy):
     62      """A ThresholdInstance is a threshold to be evaluated in a
     63      collector within a given context."""
     64
     65      # count is unknown if None
     66      count = None
     67
     68 -    def name(self):
     69          "return the name of this threshold (from the ThresholdClass)"
     70
     71 -    def context(self):
     72          "Return the ThresholdContext for this ThresholdInstance"
     73
     74 -    def key(self):
     75          "Unique data that refers to this object within a collector"
     76          return self.name(), self.context().key()
     77
     78 -    def dataPoints(self):
     79          "Returns the names of the datapoints used to compute the threshold"
     80
     81 -    def check(self, dataPoints):
     82          """The given datapoints have been updated, so re-evaluate.
     83          returns events or an empty sequence"""
     84
     85 -    def checkRaw(self, dataPoint, timeOf, value):
     86          """A new datapoint has been collected, use the given _raw_
     87          value to re-evalue the threshold.
     88          returns a sequence of events.
     89          """
     90          unused(timeOf, value)
     91          return self.check([dataPoint])
     92
     93 -    def getGraphElements(self, template, context, gopts, namespace, color,
     94                           legend, relatedGps):
     95          """Produce a visual indication on the graph of where the
     96          threshold applies."""
     97          unused(template, context, gopts, namespace, color, legend, relatedGps)
     98          return []
     99
    100
    101  pb.setUnjellyableForClass(ThresholdInstance, ThresholdInstance)
    102