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

# Source Code for Module Products.ZenModel.ThresholdGraphPoint

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