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 CommandParser import CommandParser
20
22
23 command = 'netstat -an | grep 0.0.0.0:*'
24
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
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
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
59 return "run netstat -an on server to build ipservices"
60