Package ZenRRD :: Module Thresholds
[hide private]
[frames] | no frames]

Source Code for Module ZenRRD.Thresholds

 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 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  import os 
15   
16  import logging 
17  log = logging.getLogger('zen.thresholds') 
18   
19 -class Thresholds:
20 "Class for holding multiple Thresholds, used in most collectors" 21
22 - def __init__(self):
23 self.thresholds = {} 24 self.map = {}
25
26 - def remove(self, threshold):
27 doomed = self.thresholds.get(threshold.key(), None) 28 if doomed: 29 del self.thresholds[doomed.key()] 30 ctx = doomed.context() 31 for dp in doomed.dataPoints(): 32 lst = self.map[ctx.fileKey(dp)] 33 if (doomed, dp) in lst: 34 lst.remove( (doomed, dp) ) 35 if not lst: 36 del self.map[ctx.fileKey(dp)] 37 return doomed
38
39 - def add(self, threshold):
40 self.thresholds[threshold.key()] = threshold 41 ctx = threshold.context() 42 for dp in threshold.dataPoints(): 43 self.map.setdefault(ctx.fileKey(dp), []).append((threshold, dp))
44
45 - def update(self, threshold):
46 "Store a threshold instance for future computation" 47 log.debug("Updating threshold %r", threshold.key()) 48 doomed = self.remove(threshold) 49 if doomed: 50 threshold.count = doomed.count 51 self.add(threshold)
52
53 - def updateList(self, thresholds):
54 "Store a threshold instance for future computation" 55 for threshold in thresholds: 56 self.update(threshold)
57
58 - def check(self, filename, timeAt, value):
59 "Check a given threshold based on an updated value" 60 result = [] 61 if filename in self.map: 62 log.debug("Checking value %s on %s", value, filename) 63 for t, dp in self.map[filename]: 64 result += t.checkRaw(dp, timeAt, value) 65 return result
66
67 -def test():
68 pass
69 70 if __name__ == '__main__': 71 test() 72