Package Products :: Package DataCollector :: Module ProcessCommandPlugin |
[hide private]
[frames] | no frames]

# Source Code for Module Products.DataCollector.ProcessCommandPlugin

     1  ##############################################################################
     2  #
     3  # Copyright (C) Zenoss, Inc. 2009, 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 pprint import pformat
    12
    13  from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin
    14
    15
    16 -class ProcessCommandPlugin(CommandPlugin):
    17      """
    18      Base class for Linux and AIX command plugins for parsing ps command output
    19      and modeling processes.
    20      """
    21
    22      compname = "os"
    23      relname = "processes"
    24      modname = "Products.ZenModel.OSProcess"
    25      classname = "createFromObjectMap"
    26
    27 -    def _filterLines(self, lines):
    28          """
    29          Filter out any unwanted lines.  The base implementation returns all
    30          the lines.
    31          """
    32          return lines
    33
    34 -    def process(self, device, results, log):
    35          log.info('Processing %s for device %s', self.name(), device.id)
    36          if not results:
    37              log.error("Unable to get data for %s -- skipping model",
    38                        device.id)
    39              return None
    40
    41          relMap = self.relMap()
    42          for line in self._filterLines(results.splitlines()):
    43              words = line.split()
    44
    45              relMap.append(self.objectMap({
    46                  "procName": words[0],
    47                  "parameters": " ".join(words[1:])}))
    48
    49          log.debug("First three modeled processes:\n%s" %
    50                  pformat(relMap.maps[:3]))
    51
    52          return relMap
    53