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

# Source Code for Module Products.ZenModel.RRDDataPoint

      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__="""RRDDataPoint
     15
     16  Defines attributes for how a datasource will be graphed
     17  and builds the nessesary DEF and CDEF statements for it.
     18
     19  $Id:$"""
     20
     21  __version__ = "$Revision:$"[11:-2]
     22
     23  import Globals
     24  from AccessControl import ClassSecurityInfo, Permissions
     25  from Products.ZenModel.ZenossSecurity import ZEN_VIEW, ZEN_MANAGE_DMD
     26
     27  from Products.ZenRelations.RelSchema import *
     28  from Products.ZenWidgets import messaging
     29
     30  from ZenModelRM import ZenModelRM
     31  from ZenPackable import ZenPackable
     32
     33  from Products.ZenUtils.Utils import unused
     34  from Products.ZenModel.RRDDataPointAlias import manage_addDataPointAlias
     35
     36 -def manage_addRRDDataPoint(context, id, REQUEST = None):
     37      """make a RRDDataPoint"""
     38      dp = RRDDataPoint(id)
     39      context._setObject(dp.id, dp)
     40      if REQUEST is not None:
     41          REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
     42
     43 -def getDataPointsByAliases( context, aliases ):
     44      """
     45      Retrieve the datapoint/alias pairs for the passed aliases.
     46      """
     47      if not aliases: return
     48      for brains in context.dmd.searchRRDTemplates():
     49          template = brains.getObject()
     50          for datasource in template.datasources():
     51              for datapoint in datasource.datapoints():
     52                  thisDatapointsAliases = dict(
     53                          [ ( dpAlias.id, dpAlias ) for dpAlias in
     54                             datapoint.aliases() ] )
     55                  found = False
     56                  foundAlias = None
     57                  for alias in aliases:
     58                      if thisDatapointsAliases.has_key( alias ):
     59                          found = True
     60                          yield thisDatapointsAliases[alias], datapoint
     61                  if alias == datapoint.id:
     62                      yield None, datapoint
     63
     64 -def getDataPointsByAlias( context, alias ):
     65      """
     66      Retrieve the datapoint/alias pairs for the passed alias.
     67      """
     68      return getDataPointsByAliases( context, [alias] )
     69
     70
     71  #addRRDDataPoint = DTMLFile('dtml/addRRDDataPoint',globals())
     72
     73  SEPARATOR = '_'
     74
     75 -def convertMethodParameter(value, type):
     76      __pychecker__='no-returnvalues'
     77      if type == "integer":
     78          return int(value)
     79      elif type == "string":
     80          return str(value)
     81      elif type == "float":
     82          return float(value)
     83      else:
     84          raise TypeError('Unsupported method parameter type: %s' % type)
     85
     86 -class RRDDataPointError(Exception): pass
     87
     88 -class RRDDataPoint(ZenModelRM, ZenPackable):
     89
     90      meta_type = 'RRDDataPoint'
     91
     92      rrdtypes = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE')
     93
     94      createCmd = ""
     95      rrdtype = 'GAUGE'
     96      isrow = True
     97      rrdmin = None
     98      rrdmax = None
     99
    100      ## These attributes can be removed post 2.1
    101      ## They should remain in 2.1 so the migrate script works correctly
    102      linetypes = ('', 'AREA', 'LINE')
    103      rpn = ""
    104      color = ""
    105      linetype = ''
    106      limit = -1
    107      format = '%5.2lf%s'
    108
    109
    110      _properties = (
    111          {'id':'rrdtype', 'type':'selection',
    112          'select_variable' : 'rrdtypes', 'mode':'w'},
    113          {'id':'createCmd', 'type':'text', 'mode':'w'},
    114          {'id':'isrow', 'type':'boolean', 'mode':'w'},
    115          {'id':'rrdmin', 'type':'string', 'mode':'w'},
    116          {'id':'rrdmax', 'type':'string', 'mode':'w'},
    117          )
    118
    119
    120      _relations = ZenPackable._relations + (
    121          ("datasource", ToOne(ToManyCont,"Products.ZenModel.RRDDataSource","datapoints")),
    122          ("aliases", ToManyCont(ToOne, "Products.ZenModel.RRDDataPointAlias","datapoint"))
    123          )
    124
    125      # Screen action bindings (and tab definitions)
    126      factory_type_information = (
    127      {
    128          'immediate_view' : 'editRRDDataPoint',
    129          'actions'        :
    130          (
    131              { 'id'            : 'edit'
    132              , 'name'          : 'Data Point'
    133              , 'action'        : 'editRRDDataPoint'
    134              , 'permissions'   : ( Permissions.view, )
    135              },
    136          )
    137      },
    138      )
    139
    140      security = ClassSecurityInfo()
    141
    142
    143 -    def breadCrumbs(self, terminator='dmd'):
    144          """Return the breadcrumb links for this object add ActionRules list.
    145          [('url','id'), ...]
    146          """
    147          from RRDTemplate import crumbspath
    148          crumbs = super(RRDDataPoint, self).breadCrumbs(terminator)
    149          return crumbspath(self.rrdTemplate(), crumbs, -3)
    150
    151
    152
    153      security.declareProtected(ZEN_VIEW, 'getPrimaryUrlPath')
    154 -    def getPrimaryUrlPath(self, ignored=None):
    155          """get the physicalpath as a url"""
    156          return self.absolute_url_path()
    157
    158
    159 -    def name(self):
    160          """Include the data source name in our name,
    161          useful for lists of DataPoints"""
    162          return '%s%c%s' % (self.datasource().id, SEPARATOR, self.id)
    163
    164
    165 -    def getRRDCreateCommand(self, performanceConf):
    166          """Get the create command.
    167          Return '' for the default from performanceConf"""
    168          unused(performanceConf)
    169          if self.createCmd:
    170              return self.createCmd
    171          return ''
    172
    173
    174 -    def addAlias(self, id, formula=None):
    175          """
    176          Add a new alias to this datapoint
    177          """
    178          manage_addDataPointAlias( self, id, formula )
    179
    180
    181 -    def hasAlias(self, aliasId):
    182          """
    183          Whether this datapoint has an alias of this id
    184          """
    185          return hasattr( self.aliases, aliasId )
    186
    187
    188 -    def removeAlias(self, aliasId):
    189          """
    190          Remove any alias with the given id
    191          """
    192          if self.hasAlias( aliasId ):
    193              self.aliases._delObject( aliasId )
    194
    195
    196 -    def getAliasNames(self):
    197          """
    198          Return all the ids of this datapoint's aliases
    199          """
    200          return [ alias.id for alias in self.aliases() ]
    201
    202
    203      security.declareProtected(ZEN_MANAGE_DMD, 'manage_addDataPointAlias')
    204 -    def manage_addDataPointAlias(self, id, formula, REQUEST=None ):
    205          """
    206          Add an alias to this datapoint
    207          """
    208          alias = manage_addDataPointAlias( self, id, formula )
    209          if REQUEST:
    210              return self.callZenScreen(REQUEST)
    211          return alias
    212
    213
    214      security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
    215 -    def manage_removeDataPointAliases(self, ids=(), REQUEST=None ):
    216          """
    217          Remove aliases from this datapoint
    218          """
    219          for id in ids:
    220              self.removeAlias( id )
    221          if REQUEST:
    222              return self.callZenScreen(REQUEST)
    223
    224
    225      security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
    226 -    def zmanage_editProperties(self, REQUEST=None, redirect=False):
    227          """Edit a ZenModel object and return its proper page template
    228          """
    229          unused(redirect)
    230          if REQUEST:
    231              msgs = []
    232              for optional in 'rrdmin', 'rrdmax':
    233                  v = REQUEST.form.get(optional, None)
    234                  if v:
    235                      try:
    236                          REQUEST.form[optional] = long(v)
    237                      except ValueError:
    238                          msgs.append('Unable to convert "%s" to a number' % v)
    239              msgs = ', '.join(msgs)
    240              if msgs:
    241                  messaging.IMessageSender(self).sendToBrowser(
    242                      'Properties Saved',
    243                      msgs[0].capitalize() + msgs[1:]
    244                  )
    245                  return self.callZenScreen(REQUEST, False)
    246
    247          return ZenModelRM.zmanage_editProperties(self, REQUEST)
    248