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

Source Code for Module ZenModel.ThresholdGraphPoint

  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  __doc__="""ThreshGraphPoint 
 15   
 16  Handles GraphPoints that refer to RRDDataPoints 
 17  """ 
 18   
 19  from GraphPoint import GraphPoint 
 20  from Globals import InitializeClass 
 21   
 22   
23 -def manage_addThresholdGraphPoint(context, id, REQUEST = None):
24 ''' This is here so than zope will let us copy/paste/rename 25 graphpoints. 26 ''' 27 gp = ThresholdGraphPoint(id) 28 context._setObject(gp.id, gp) 29 if REQUEST: 30 return context.callZenScreen(REQUEST)
31 32
33 -class ThresholdGraphPoint(GraphPoint):
34 35 meta_type = 'ThresholdGraphPoint' 36 37 isThreshold = True 38 39 threshId = '' 40 color = '' 41 legend = GraphPoint.DEFAULT_LEGEND 42 43 _properties = GraphPoint._properties + ( 44 {'id':'threshId', 'type':'string', 'mode':'w'}, 45 {'id':'color', 'type':'string', 'mode':'w'}, 46 {'id':'legend', 'type':'string', 'mode':'w'}, 47 ) 48
49 - def getThreshClass(self, context):
50 ''' Get the related threshold class or None if it doesn't exist 51 ''' 52 threshClass = None 53 if self.graphDef.rrdTemplate(): 54 threshClass = self.graphDef.rrdTemplate.thresholds._getOb( 55 self.threshId, None) 56 return threshClass
57 58
59 - def getDescription(self):
60 return self.threshId
61 62
63 - def getType(self):
64 return 'Threshold'
65 66 67 # def getMissingDPNames(self): 68 # ''' Return a list of datapoint names that are used by this threshold 69 # but not included in any graphpoint. 70 # ''' 71 # threshClass = self.getThreshClass() 72 # if threshClass: 73 # dpNames = [dpName for dpName in threshClass.dsnames 74 # if not self.graphDef.isDataPointGraphed(dpName)] 75 # else: 76 # dpNames = [] 77 # return dpNames 78 79
80 - def getRelatedGraphPoints(self, context):
81 ''' Return a dictionary where keys are the dp names from the 82 threshold and values are a DataPointGraphPoint for that dp or 83 None if a RPGP doesn't exist. If multiple exist for any given 84 dp then return just the first one. 85 ''' 86 related = {} 87 threshClass = self.getThreshClass(context) 88 if threshClass: 89 for dpName in threshClass.dsnames: 90 gps = self.graphDef.getDataPointGraphPoints(dpName) 91 if gps: 92 gp = gps[0] 93 gp.legend = gp.talesEval(gp.legend, context) 94 else: 95 gp = None 96 related[dpName] = gp 97 return related
98 99
100 - def getGraphCmds(self, cmds, context, rrdDir, addSummary, idx, 101 multiid=-1, prefix=''):
102 ''' Build the graphing commands for this graphpoint 103 ''' 104 from Products.ZenUtils.Utils import unused 105 unused(multiid, rrdDir) 106 if getattr(context, 'isFake', False): 107 return cmds 108 relatedGps = self.getRelatedGraphPoints(context) 109 gopts = [] 110 threshClass = self.getThreshClass(context) 111 if threshClass: 112 threshInst = threshClass.createThresholdInstance(context) 113 namespace = self.addPrefix(prefix, self.id) 114 color = self.getThresholdColor(idx) 115 legend = self.talesEval(self.legend, context) 116 template = self.graphDef.rrdTemplate() or None 117 # We can't get templates when doing mgr 118 # need to refactor threshinst to not take template. 119 # Looks like it's not being used anyway. 120 gopts = threshInst.getGraphElements( 121 template, context, gopts, namespace, 122 color, legend, relatedGps) 123 return cmds + gopts
124 125 126 InitializeClass(ThresholdGraphPoint) 127