1
2
3
4
5
6
7
8
9
10
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
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
56 """A ThresholdInstance is a threshold to be evaluated in a
57 collector within a given context."""
58
59
60 count = None
61
63 "return the name of this threshold (from the ThresholdClass)"
64
66 "Return the ThresholdContext for this ThresholdInstance"
67
69 "Unique data that refers to this object within a collector"
70 return self.name(), self.context().key()
71
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