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

# Source Code for Module Products.ZenRRD.CommandParser

     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  import logging
    12  log = logging.getLogger('zen.ZenRRD.CommandParser')
    13
    14  from pprint import pformat
    15
    16 -class ParsedResults(object):
    17
    18 -    def __init__(self):
    19          self.events = []                # list of event dictionaries
    20          self.values = []                # list of (DataPointConfig, value)
    21
    22 -    def __repr__(self):
    23          args = (pformat(self.events), pformat(self.values))
    24          return "ParsedResults\n  events: %s\n  values: %s}" % args
    25
    26 -class CommandParser(object):
    27
    28 -    def dataForParser(self, context, datapoint):
    29          return {}
    30
    31 -    def preprocessResults(self, cmd, log):
    32          """
    33          Preprocess the results of running a command.
    34
    35          @type cmd: Products.ZenRRD.zencommand.Cmd
    36          @param cmd: the results of running a command, with the
    37          configuration from ZenHub
    38          @return: None.
    39          """
    40
    41          # If the command was echoed back, strip it off
    42          if cmd.result.output.lstrip().startswith(cmd.command):
    43              cmd.result.output = cmd.result.output.lstrip()[len(cmd.command):]
    44
    45 -    def processResults(self, cmd, results):
    46          """
    47          Process the results of a running a command.
    48
    49          @type cmd: Products.ZenRRD.zencommand.Cmd
    50
    51          @param cmd: the results of running a command, with the
    52          configuration from ZenHub
    53          @param results: the values and events from the command output
    54          @return: None.
    55          """
    56          raise NotImplementedError
    57
    58      @property
    59 -    def createDefaultEventUsingExitCode(self):
    60          """
    61          Property which can control whether events will be created
    62          based on the exit code of the command if no events are
    63          generated in the processResults function.
    64          """
    65          return True
    66