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

Source Code for Module DataCollector.CommandParsers.Linux_netstat_an

 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 as published by 
 8  # 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 CommandParser import CommandParser 
23   
24 -class Linux_netstat_an(CommandParser):
25 26 command = 'netstat -an | grep 0.0.0.0:*' 27
28 - def condition(self, device, log):
29 pp = device.getPrimaryPath() 30 return "Linux" in pp
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 # normalize on address 0.0.0.0 means all addresses 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 #FIXME 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
61 - def description(self):
62 return "run netstat -an on server to build ipservices"
63