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

# Source Code for Module Products.ZenRRD.parsers.Cacti

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2008, 2009 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  import re
    15  # how to parse each value from a Cacti plugin
    16  CacParser = re.compile(r"""([^ :']+|'(.*)'+):([-0-9.]+)""")
    17
    18  from Products.ZenUtils.Utils import getExitMessage
    19  from Products.ZenRRD.CommandParser import CommandParser
    20
    21 -class Cacti(CommandParser):
    22
    23 -    def processResults(self, cmd, result):
    24          output = cmd.result.output
    25          output = output.split('\n')[0].strip()
    26          exitCode = cmd.result.exitCode
    27          severity = cmd.severity
    28          if output.find('|') >= 0:
    29              msg, values = output.split('|', 1)
    30              msg, values = output, ''
    31
    32          elif CacParser.search(output):
    33              msg, values = '', output
    34
    35          elif len(cmd.points) == 1:
    36              # Special case for plugins that only return one datapoint
    37              try:
    38                  number = float(output)
    39                  result.values.append( (cmd.points[0], number) )
    40                  msg, values = '', output
    41              except:
    42                  msg, values = output, ''
    43
    44          else:
    45              msg, values = output, ''
    46
    47          msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % (
    48              cmd.command, exitCode, getExitMessage(exitCode))
    49          if exitCode != 0:
    50              if exitCode == 2:
    51                  severity = min(severity + 1, 5)
    52              result.events.append(dict(device=cmd.deviceConfig.device,
    53                                        summary=msg,
    54                                        severity=severity,
    55                                        message=msg,
    56                                        performanceData=values,
    57                                        eventKey=cmd.eventKey,
    58                                        eventClass=cmd.eventClass,
    59                                        component=cmd.component))
    60
    61          for value in values.split():
    62              parts = CacParser.match(value)
    63
    64              if not parts: continue
    65              label = parts.group(1).replace("''", "'")
    66              try:
    67                  value = float(parts.group(3))
    68              except:
    69                  value = 'U'
    70              for dp in cmd.points:       # FIXME: linear search
    71                  if dp.id == label:
    72                      result.values.append( (dp, value) )
    73                      break
    74