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

Source Code for Module Products.ZenModel.ThresholdClass

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