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

# Source Code for Module Products.ZenModel.RRDThreshold

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