Package ZenModel :: Module RRDThreshold
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.RRDThreshold

  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  from Globals import DTMLFile 
 15  from Globals import InitializeClass 
 16  from AccessControl import ClassSecurityInfo, Permissions 
 17   
 18  from ZenModelRM import ZenModelRM 
 19  from ZenPackable import ZenPackable 
 20   
 21  from Products.ZenRelations.RelSchema import * 
 22  from Products.ZenUtils.ZenTales import talesEval 
 23  from Products.ZenEvents.ZenEventClasses import Perf_Snmp 
 24   
 25   
26 -def rpneval(value, rpn):
27 """totally bogus rpn valuation only works with one level stack""" 28 if value is None: return value 29 operators = ('+','-','*','/') 30 rpn = rpn.split(',') 31 operator = '' 32 for i in range(len(rpn)): 33 symbol = rpn.pop() 34 symbol = symbol.strip() 35 if symbol in operators: 36 operator = symbol 37 else: 38 expr = str(value) + operator + symbol 39 value = eval(expr) 40 return value
41 42
43 -def manage_addRRDThreshold(context, id, REQUEST = None):
44 """make a RRDThreshold""" 45 tt = RRDThreshold(id) 46 context._setObject(tt.id, tt) 47 if REQUEST is not None: 48 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
49 50 addRRDThreshold = DTMLFile('dtml/addRRDThreshold',globals()) 51
52 -class RRDThreshold(ZenModelRM, ZenPackable):
53 54 meta_type = 'RRDThreshold' 55 56 security = ClassSecurityInfo() 57 58 dsnames = [] 59 minval = "" 60 maxval = "" 61 eventClass = Perf_Snmp 62 severity = 3 63 escalateCount = 0 64 enabled = True 65 66 _properties = ( 67 {'id':'dsnames', 'type':'lines', 'mode':'w'}, 68 {'id':'minval', 'type':'string', 'mode':'w'}, 69 {'id':'maxval', 'type':'string', 'mode':'w'}, 70 {'id':'eventClass', 'type':'string', 'mode':'w'}, 71 {'id':'severity', 'type':'int', 'mode':'w'}, 72 {'id':'escalateCount', 'type':'int', 'mode':'w'}, 73 {'id':'enabled', 'type':'boolean', 'mode':'w'}, 74 ) 75 76 _relations = ZenPackable._relations + ( 77 ("rrdTemplate", ToOne(ToManyCont,"Products.ZenModel.RRDTemplate", "thresholds")), 78 ) 79 80 81 factory_type_information = ( 82 { 83 'immediate_view' : 'editRRDThreshold', 84 'actions' : 85 ( 86 { 'id' : 'edit' 87 , 'name' : 'RRD Threshold' 88 , 'action' : 'editRRDThreshold' 89 , 'permissions' : ( Permissions.view, ) 90 }, 91 ) 92 }, 93 ) 94
95 - def breadCrumbs(self, terminator='dmd'):
96 """Return the breadcrumb links for this object add ActionRules list. 97 [('url','id'), ...] 98 """ 99 from RRDTemplate import crumbspath 100 crumbs = super(RRDThreshold, self).breadCrumbs(terminator) 101 return crumbspath(self.rrdTemplate(), crumbs, -2)
102 103
104 - def getConfig(self, context):
105 """Return the config used by the collector to process simple min/max 106 thresholds. (id, minval, maxval, severity, escalateCount) 107 """ 108 return (self.id,self.getMinval(context),self.getMaxval(context), 109 self.eventClass, self.severity,self.escalateCount)
110 111
112 - def getMinval(self, context):
113 """Build the min value for this threshold. 114 """ 115 minval = None 116 if self.minval: 117 minval = talesEval("python:"+self.minval, context) 118 return minval
119 120
121 - def getMaxval(self, context):
122 """Build the max value for this threshold. 123 """ 124 maxval = None 125 if self.maxval: 126 maxval = talesEval("python:"+self.maxval, context) 127 return maxval
128 129
130 - def getGraphMinval(self, context):
131 return self.getGraphValue(context, self.getMinval)
132 133
134 - def getGraphMaxval(self, context):
135 return self.getGraphValue(context, self.getMaxval)
136 137
138 - def getGraphValue(self, context, getfunc):
139 """when graphing use this so that rpn conversions are accounted for""" 140 val = getfunc(context) 141 if val is None or len(self.dsnames) == 0: return 142 dp = self.getRRDDataPoint(self.dsnames[0]) 143 if dp and dp.rpn: 144 #When VDEF does full rpn 145 #val = "%s,%s" % (val, dp.rpn) 146 val = rpneval(val, dp.rpn) 147 return val
148 149
150 - def getMinLabel(self, context):
151 """build a label for a min threshold""" 152 return "%s < %s" % (self.id,self.setPower(self.getGraphMinval(context)))
153 154
155 - def getMaxLabel(self, context):
156 """build a label for a max threshold""" 157 return "%s > %s" % (self.id,self.setPower(self.getGraphMaxval(context)))
158 159
160 - def setPower(self, number):
161 powers = ("k", "M", "G") 162 if number < 1000: return number 163 for power in powers: 164 number = number / 1000 165 if number < 1000: 166 return "%0.2f%s" % (number, power) 167 return "%.2f%s" % (number, powers[-1])
168 169
170 - def getSeverityString(self):
171 return self.ZenEventManager.getSeverityString(self.severity)
172 173 174 InitializeClass(RRDThreshold) 175