1
2
3
4
5
6
7
8
9
10
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
33
34 command = 'netstat -rn'
35 componentName = "os"
36
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
70 return "run netstat -an on server to build ipservices"
71