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 as published by
     8  # 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 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          self.deviceName = context.device().id
    30          if hasattr( context, 'name' ) and callable( getattr( context, 'name' ) ):
    31              self.componentName = context.name()
    32          else:
    33              self.componentName = context.id
    34          if self.componentName == self.deviceName:
    35              self.componentName = ''
    36          self.rrdPath = context.rrdPath()
    37
    38
    39 -    def key(self):
    40          "Unique data that refers this context"
    41          return self.deviceName, self.componentName
    42
    43
    44 -    def fileKey(self, dataPoint):
    45          "Unique base filename for this context and given dataPoint"
    46          return os.path.join(self.rrdPath, dataPoint)
    47
    48
    49 -    def path(self, dataPoint):
    50          "The full pathname to RRD file that uses a dataPoint"
    51          return performancePath(os.path.join(self.rrdPath, dataPoint)) + '.rrd'
    52
    53  pb.setUnjellyableForClass(ThresholdContext, ThresholdContext)
    54
    55 -class ThresholdInstance(pb.Copyable, pb.RemoteCopy):
    56      """A ThresholdInstance is a threshold to be evaluated in a
    57      collector within a given context."""
    58
    59      # count is unknown if None
    60      count = None
    61
    62 -    def name(self):
    63          "return the name of this threshold (from the ThresholdClass)"
    64
    65 -    def context(self):
    66          "Return the ThresholdContext for this ThresholdInstance"
    67
    68 -    def key(self):
    69          "Unique data that refers to this object within a collector"
    70          return self.name(), self.context().key()
    71
    72 -    def dataPoints(self):
    73          "Returns the names of the datapoints used to compute the threshold"
    74
    75 -    def check(self, dataPoints):
    76          """The given datapoints have been updated, so re-evaluate.
    77          returns events or an empty sequence"""
    78
    79 -    def checkRaw(self, dataPoint, timeOf, value):
    80          """A new datapoint has been collected, use the given _raw_
    81          value to re-evalue the threshold.
    82          returns a sequence of events.
    83          """
    84          unused(timeOf, value)
    85          return self.check([dataPoint])
    86
    87 -    def getGraphElements(self, template, context, gopts, namespace, color,
    88                           legend, relatedGps):
    89          """Produce a visual indication on the graph of where the
    90          threshold applies."""
    91          unused(template, context, gopts, namespace, color, legend, relatedGps)
    92          return []
    93
    94
    95  pb.setUnjellyableForClass(ThresholdInstance, ThresholdInstance)
    96