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

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

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, 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 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13
    14  __doc__ = """CommandParser
    15
    16  CommandParser parses the output of a command to return a datamap
    17
    18  $Id: Uname_A.py,v 1.2 2003/10/01 23:40:51 edahl Exp $"""
    19
    20  __version__ = '$Revision: 1.2 $'[11:-2]
    21
    22  from Products.ZenUtils.IpUtil import isip, maskToBits
    23
    24  from CommandParser import CommandParser
    25
    26  TARGET=0
    27  GATEWAY=1
    28  NETMASK=2
    29  FLAGS=3
    30  INTERFACE=7
    31
    32 -class Linux_netstat_rn(CommandParser):
    33
    34      command = 'netstat -rn'
    35      componentName = "os"
    36
    37 -    def condition(self, device, log):
    38          osver = device.os.getProductName()
    39          return osver.find("Linux") > -1
    40
    41 -    def parse(self, device, results, log):
    42          log.info('Collecting routes for device %s' % device.id)
    43          indirectOnly = getattr(device, 'zRouteMapCollectOnlyIndirect', False)
    44          rm = self.newRelationshipMap("routes", "os")
    45          rlines = results.split("\n")
    46          for line in rlines:
    47              aline = line.split()
    48              if len(aline) != 8 or not isip(aline[0]): continue
    49              route = self.newObjectMap("Products.ZenModel.IpRouteEntry")
    50
    51              route['routemask'] = maskToBits(aline[NETMASK])
    52              if route['routemask'] == 32: continue
    53
    54              if "G" in aline[FLAGS]:
    55                  route['routetype'] = 'indirect'
    56              else:
    57                  route['routetype'] = 'direct'
    58              if indirectOnly and route['routetype'] != 'indirect':
    59                  continue
    60
    61              route['id'] = aline[TARGET]
    62              route['setTarget'] = route['id'] + "/" + str(route['routemask'])
    63              route['id'] = route['id'] + "_" + str(route['routemask'])
    64              route['setInterfaceName'] = aline[INTERFACE]
    65              route['setNextHopIp'] = aline[GATEWAY]
    66              rm.append(route)
    67          return rm
    68
    69 -    def description(self):
    70          return "run netstat -an on server to build ipservices"
    71