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