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

# Source Code for Module Products.DataCollector.CommandParsers.Linux_netstat_an

     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  __doc__ = """CommandParser
    12
    13  CommandParser parses the output of a command to return a datamap
    14
    15  $Id: Uname_A.py,v 1.2 2003/10/01 23:40:51 edahl Exp $"""
    16
    17  __version__ = '$Revision: 1.2 $'[11:-2]
    18
    19  from CommandParser import CommandParser
    20
    21 -class Linux_netstat_an(CommandParser):
    22
    23      command = 'netstat -an | grep 0.0.0.0:*'
    24
    25 -    def condition(self, device, log):
    26          pp = device.getPrimaryPath()
    27          return "Linux" in pp
    28
    29 -    def parse(self, device, results, log):
    30          log.info('Collecting Ip Services for device %s' % device.id)
    31          rm = self.newRelationshipMap("ipservices")
    32          rlines = results.split("\n")
    33          services = {}
    34          # normalize on address 0.0.0.0 means all addresses
    35          for line in rlines:
    36              aline = line.split()
    37              if len(aline) < 5: continue
    38              try:
    39                  proto = aline[0]
    40                  addr, port = aline[3].split(":")
    41                  if int(port) > 1024: continue #FIXME
    42                  if addr == "0.0.0.0" or not port in services:
    43                      services[port] = (addr, proto)
    44              except ValueError:
    45                  log.exception("failed to parse ipservice information")
    46          for port, value in services.items():
    47              addr, proto = value
    48              om = self.newObjectMap("ZenModel.IpService")
    49              om['id'] = "-".join((addr, proto, port))
    50              om['ipaddress'] = addr
    51              om['setPort'] = port
    52              om['setProtocol'] = proto
    53              om['discoveryAgent'] = 'IpServiceMap-' + __version__
    54              rm.append(om)
    55              log.debug('Adding TCP Service %s %s' % (addr, port))
    56          return rm
    57
    58 -    def description(self):
    59          return "run netstat -an on server to build ipservices"
    60