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

# Source Code for Module Products.ZenModel.ValueChangeThreshold

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2012, all rights reserved.
     4  #
     5  # This content is made available according to terms specified in
     6  # License.zenoss under the directory where your Zenoss product is installed.
     7  #
     8  ##############################################################################
     9
    10
    11  from Products.ZenModel.ThresholdInstance import RRDThresholdInstance
    12
    13  __doc__= """Threshold to track when a value changes.
    14  """
    15
    16  from Globals import InitializeClass
    17  from ThresholdClass import ThresholdClass
    18  from ThresholdInstance import ThresholdContext
    19  from zenoss.protocols.protobufs.zep_pb2 import SEVERITY_INFO
    20  from Products.ZenEvents.ZenEventClasses import Status_Perf
    21
    22  import logging
    23  log = logging.getLogger('zen.MinMaxCheck')
    24
    25
    26  NaN = float('nan')
    27
    28 -class ValueChangeThreshold(ThresholdClass):
    29      """
    30      Threshold that can watch changes in a value
    31      """
    32
    33      eventClass = Status_Perf
    34      severity = SEVERITY_INFO
    35
    36 -    def createThresholdInstance(self, context):
    37          """Return the config used by the collector to process change thresholds
    38          """
    39          mmt = ValueChangeThresholdInstance(self.id,
    40                                        ThresholdContext(context),
    41                                        self.dsnames,
    42                                        eventClass=self.eventClass,
    43                                        severity=self.severity)
    44          return mmt
    45
    46  InitializeClass(ValueChangeThreshold)
    47  ValueChangeThresholdClass = ValueChangeThreshold
    48
    49 -class ValueChangeThresholdInstance(RRDThresholdInstance):
    50      """
    51      Threshold that emits an event when a value changes from its previous value. Does not send clear events.
    52      """
    53
    54 -    def __init__(self, id, context, dpNames, eventClass, severity):
    55          RRDThresholdInstance.__init__(self, id, context, dpNames, eventClass, severity)
    56          self._lastValues = {}
    57
    58 -    def _checkImpl(self, dataPoint, value):
    59          dpKey = self._getDpKey(dataPoint)
    60          lastValue = self._lastValues.get(dpKey, None)
    61          if lastValue != value:
    62              self._lastValues[dpKey] = value
    63              event = dict(
    64                  device=self.context().deviceName,
    65                  summary="Value changed from %s to %s" % (lastValue, value),
    66                  eventKey=self.id,
    67                  eventClass=self.eventClass,
    68                  component=self.context().componentName,
    69                  current=value,
    70                  previous=lastValue,
    71                  severity=self.severity)
    72              return (event,)
    73          return tuple()
    74
    75 -    def _getDpKey(self, dp):
    76          return ':'.join(self.context().key()) + ':' + dp
    77
    78
    79  from twisted.spread import pb
    80  pb.setUnjellyableForClass(ValueChangeThresholdInstance, ValueChangeThresholdInstance)
    81