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 CommandParser import CommandParser
23
25
26 command = 'netstat -an | grep 0.0.0.0:*'
27
31
32 - def parse(self, device, results, log):
33 log.info('Collecting Ip Services for device %s' % device.id)
34 rm = self.newRelationshipMap("ipservices")
35 rlines = results.split("\n")
36 services = {}
37
38 for line in rlines:
39 aline = line.split()
40 if len(aline) < 5: continue
41 try:
42 proto = aline[0]
43 addr, port = aline[3].split(":")
44 if int(port) > 1024: continue
45 if addr == "0.0.0.0" or not services.has_key(port):
46 services[port] = (addr, proto)
47 except ValueError:
48 log.exception("failed to parse ipservice information")
49 for port, value in services.items():
50 addr, proto = value
51 om = self.newObjectMap("ZenModel.IpService")
52 om['id'] = "-".join((addr, proto, port))
53 om['ipaddress'] = addr
54 om['setPort'] = port
55 om['setProtocol'] = proto
56 om['discoveryAgent'] = 'IpServiceMap-' + __version__
57 rm.append(om)
58 log.debug('Adding TCP Service %s %s' % (addr, port))
59 return rm
60
62 return "run netstat -an on server to build ipservices"
63