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

# Source Code for Module Products.ZenModel.ThresholdClass

     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  from AccessControl import ClassSecurityInfo
    15
    16  import Globals
    17  from Products.ZenModel.ZenModelRM import ZenModelRM
    18  from Products.ZenModel.ZenPackable import ZenPackable
    19  from Products.ZenRelations.RelSchema import *
    20
    21 -class BadInstance(Exception): pass
    22
    23 -class ThresholdClass(ZenModelRM, ZenPackable):
    24      """A ThresholdClass is a threshold description stored in a
    25      Template.  The ThresholdClass will create ThresholdInstance
    26      objects when provided with a context, such as a device.  Lists of
    27      ThresholdInstances will be sent to collectors for evaluation.
    28      """
    29
    30      meta_type = 'ThresholdClass'
    31      security = ClassSecurityInfo()
    32      dsnames = []
    33      enabled = True
    34
    35 -    def __init__(self, id, buildRelations=True):
    36          self.id = id
    37          if buildRelations:
    38              self.buildRelations()
    39
    40      _properties = (
    41          {'id':'dsnames', 'type':'lines', 'mode':'w', 'label': 'DataPoints'},
    42          {'id':'enabled', 'type':'boolean', 'mode':'w', 'label': 'Enabled'},
    43          )
    44
    45      _relations =  ZenPackable._relations + (
    46          ("rrdTemplate", ToOne(ToManyCont,"Products.ZenModel.RRDTemplate", "thresholds")),
    47          )
    48
    49 -    def getTypeName(self):
    50          return self.__class__.__name__
    51
    52
    53 -    def breadCrumbs(self, terminator='dmd'):
    54          """Return the breadcrumb links for this object add ActionRules list.
    55          [('url','id'), ...]
    56          """
    57          from RRDTemplate import crumbspath
    58          crumbs = super(ThresholdClass, self).breadCrumbs(terminator)
    59          return crumbspath(self.rrdTemplate(), crumbs, -2)
    60
    61
    62 -    def createThresholdInstance(self, context):
    63          """Return a sub-class of ThresholdInstance.  May raise a
    64          BadInstance exception if the type of the context does not
    65          match this type of threshold.
    66          """
    67
    68
    69 -    def canGraph(self, graph):
    70          """Returns true if instances of this ThresholdClass can be
    71          placed on a users' graph"""
    72          return True
    73
    74
    75 -    def sync(self, eventManager, instances):
    76          "update instances with state from the event manager"
    77
    78
    79 -    def getSeverityString(self):
    80          return self.ZenEventManager.getSeverityString(self.severity)
    81
    82
    83 -    def getDataPointNamesString(self):
    84          """
    85          Return a string that lists the datapoints used in this threshold.
    86          Indicate missing datapoints with (missing) after the name.
    87          """
    88          names = []
    89          availableDPNames = self.rrdTemplate.getRRDDataPointNames()
    90          for dsName in self.dsnames:
    91              if dsName in availableDPNames:
    92                  names.append(dsName)
    93              else:
    94                  names.append('%s(<span style="color: red">missing</span>)' % dsName)
    95          return ','.join(names)
    96