1
2
3
4
5
6
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 Products.ZenUtils.IpUtil import isip, maskToBits
20
21 from CommandParser import CommandParser
22
23 TARGET=0
24 GATEWAY=1
25 NETMASK=2
26 FLAGS=3
27 INTERFACE=7
28
30
31 command = 'netstat -rn'
32 componentName = "os"
33
37
38 - def parse(self, device, results, log):
39 log.info('Collecting routes for device %s' % device.id)
40 indirectOnly = getattr(device, 'zRouteMapCollectOnlyIndirect', False)
41 rm = self.newRelationshipMap("routes", "os")
42 rlines = results.split("\n")
43 for line in rlines:
44 aline = line.split()
45 if len(aline) != 8 or not isip(aline[0]): continue
46 route = self.newObjectMap("Products.ZenModel.IpRouteEntry")
47
48 route['routemask'] = maskToBits(aline[NETMASK])
49 if route['routemask'] == 32: continue
50
51 if "G" in aline[FLAGS]:
52 route['routetype'] = 'indirect'
53 else:
54 route['routetype'] = 'direct'
55 if indirectOnly and route['routetype'] != 'indirect':
56 continue
57
58 route['id'] = aline[TARGET]
59 route['setTarget'] = route['id'] + "/" + str(route['routemask'])
60 route['id'] = route['id'] + "_" + str(route['routemask'])
61 route['setInterfaceName'] = aline[INTERFACE]
62 route['setNextHopIp'] = aline[GATEWAY]
63 rm.append(route)
64 return rm
65
67 return "run netstat -an on server to build ipservices"
68