Package Products :: Package ZenRRD :: Module ComponentCommandParser |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenRRD.ComponentCommandParser

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2008, 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 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13
    14  from Products.ZenRRD.CommandParser import CommandParser
    15  from Products.ZenUtils.Utils import prepId as globalPrepId
    16  import re
    17  from pprint import pformat
    18  import logging
    19
    20  log = logging.getLogger("zen.ComponentCommandParser")
    21
    22 -class ComponentCommandParser(CommandParser):
    23
    24      componentSplit = '\n'
    25
    26      componentScanner = ''
    27
    28      scanners = ()
    29
    30      componentScanValue = 'id'
    31
    32 -    def prepId(self, id, subchar='_'):
    33          return globalPrepId(id, subchar)
    34
    35 -    def dataForParser(self, context, dp):
    36          return dict(componentScanValue = getattr(context, self.componentScanValue))
    37
    38 -    def processResults(self, cmd, result):
    39
    40          # Map datapoints by data you can find in the command output
    41          ifs = {}
    42          for dp in cmd.points:
    43              dp.component = dp.data['componentScanValue']
    44              points = ifs.setdefault(dp.component, {})
    45              points[dp.id] = dp
    46
    47          # split data into component blocks
    48          parts = cmd.result.output.split(self.componentSplit)
    49
    50          for part in parts:
    51              # find the component match
    52              match = re.search(self.componentScanner, part)
    53              if not match: continue
    54              component = match.groupdict()['component'].strip()
    55              if self.componentScanValue == 'id': component = self.prepId(component)
    56              points = ifs.get(component, None)
    57              if not points: continue
    58
    59              # find any datapoints
    60              for search in self.scanners:
    61                  match = re.search(search, part)
    62                  if match:
    63                      for name, value in match.groupdict().items():
    64                          dp = points.get(name, None)
    65                          if dp is not None:
    66                              if value in ('-', ''): value = 0
    67                              result.values.append( (dp, float(value) ) )
    68
    69          log.debug(pformat(result))
    70          return result
    71