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 elif self.graphDef.report() and None: 57 for temp in context.getRRDTemplates(): 58 threshClass = temp.thresholds._getOb(self.threshId, None) 59 if threshClass: 60 break 61 return threshClass
62 63
64 - def getDescription(self):
65 return self.threshId
66 67
68 - def getType(self):
69 return 'Threshold'
70 71 72 # def getMissingDPNames(self): 73 # ''' Return a list of datapoint names that are used by this threshold 74 # but not included in any graphpoint. 75 # ''' 76 # threshClass = self.getThreshClass() 77 # if threshClass: 78 # dpNames = [dpName for dpName in threshClass.dsnames 79 # if not self.graphDef.isDataPointGraphed(dpName)] 80 # else: 81 # dpNames = [] 82 # return dpNames 83 84
85 - def getRelatedGraphPoints(self, context):
86 ''' Return a dictionary where keys are the dp names from the 87 threshold and values are a DataPointGraphPoint for that dp or 88 None if a RPGP doesn't exist. If multiple exist for any given 89 dp then return just the first one. 90 ''' 91 from DataPointGraphPoint import DataPointGraphPoint 92 related = {} 93 threshClass = self.getThreshClass(context) 94 if threshClass: 95 for dpName in threshClass.dsnames: 96 gps = self.graphDef.getDataPointGraphPoints(dpName) 97 if gps: 98 gp = gps[0] 99 else: 100 gp = None 101 related[dpName] = gp 102 return related
103 104
105 - def getGraphCmds(self, cmds, context, rrdDir, addSummary, idx, 106 multiid=-1, prefix=''):
107 ''' Build the graphing commands for this graphpoint 108 ''' 109 if getattr(context, 'isFake', False): 110 return cmds 111 relatedGps = self.getRelatedGraphPoints(context) 112 gopts = [] 113 threshClass = self.getThreshClass(context) 114 if threshClass: 115 threshInst = threshClass.createThresholdInstance(context) 116 namespace = self.addPrefix(prefix, self.id) 117 color = self.getThresholdColor(idx) 118 template = self.graphDef.rrdTemplate() or None 119 # We can't get templates when doing mgr 120 # need to refactor threshinst to not take template. 121 # Looks like it's not being used anyway. 122 gopts = threshInst.getGraphElements( 123 template, gopts, namespace, 124 color, relatedGps) 125 return cmds + gopts
126 127 128 InitializeClass(ThresholdGraphPoint) 129