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