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

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

     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 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 nagios command
    16  NagParser = re.compile(r"""([^ =']+|'(.*)'+)=([-0-9.eE]+)([^;]*;?){0,5}""")
    17  # how to parse each value from a cacti command
    18  CacParser = re.compile(r"""([^ :']+|'(.*)'+):([-0-9.]+)""")
    19
    20  from Products.ZenUtils.Utils import getExitMessage
    21  from Products.ZenRRD.CommandParser import CommandParser
    22
    23 -class Auto(CommandParser):
    24
    25 -    def processResults(self, cmd, result):
    26          output = cmd.result.output
    27          output = output.split('\n')[0].strip()
    28          exitCode = cmd.result.exitCode
    29          severity = cmd.severity
    30          if output.find('|') >= 0:
    31              msg, values = output.split('|', 1)
    32          elif CacParser.search(output):
    33              msg, values = '', output
    34          else:
    35              msg, values = output, ''
    36          msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % (
    37              cmd.command, exitCode, getExitMessage(exitCode))
    38          if exitCode != 0:
    39              if exitCode == 2:
    40                  severity = min(severity + 1, 5)
    41              result.events.append(dict(device=cmd.deviceConfig.device,
    42                                        summary=msg,
    43                                        severity=severity,
    44                                        message=msg,
    45                                        performanceData=values,
    46                                        eventKey=cmd.eventKey,
    47                                        eventClass=cmd.eventClass,
    48                                        component=cmd.component))
    49
    50          for value in values.split(' '):
    51              if value.find('=') > 0:
    52                  parts = NagParser.match(value)
    53              else:
    54                  parts = CacParser.match(value)
    55              if not parts: continue
    56              label = parts.group(1).replace("''", "'")
    57              try:
    58                  value = float(parts.group(3))
    59              except:
    60                  value = 'U'
    61              for dp in cmd.points:       # FIXME: linear search
    62                  if dp.id == label:
    63                      result.values.append( (dp, value) )
    64                      break
    65