diff options
author | Felix Richter <Felix.Richter@syntax-fehler.de> | 2011-01-31 22:16:58 +0100 |
---|---|---|
committer | Felix Richter <Felix.Richter@syntax-fehler.de> | 2011-01-31 22:16:58 +0100 |
commit | c40db19a0214bdc6aa4807d3f704815fad833992 (patch) | |
tree | 2cda1c8d4316a9239135200040fa059eb17006c9 /src | |
parent | da06f1c3d243477e7481c2cc07d86843b14a65a4 (diff) |
updated code to work again
Added changes to make it work with python-genericore version 6.0
Added example configuration
Diffstat (limited to 'src')
-rwxr-xr-x | src/main.py | 7 | ||||
-rwxr-xr-x | src/snmp_users.py | 17 |
2 files changed, 14 insertions, 10 deletions
diff --git a/src/main.py b/src/main.py index 473729f4..c70bffd4 100755 --- a/src/main.py +++ b/src/main.py @@ -3,15 +3,16 @@ import sys,json,time from snmp_users import snmp_users import logging import genericore as gen -log = logging.getLogger('mail_proc_main') +MODULE_NAME='snmp_users' +log = logging.getLogger(MODULE_NAME) PROTO_VERSION = 1 DESCRIPTION = 'performes statistical analysis against mails from stream' # set up instances of needed modules conf = gen.Configurator(PROTO_VERSION,DESCRIPTION) -amqp = gen.auto_amqp() -s = snmp_users() # the magic mail parsing class +amqp = gen.auto_amqp(MODULE_NAME) +s = snmp_users(MODULE_NAME) # the magic mail parsing class conf.configure([amqp,s]) #set up parser and eval parsed stuff diff --git a/src/snmp_users.py b/src/snmp_users.py index 12c6efb9..871ed9dd 100755 --- a/src/snmp_users.py +++ b/src/snmp_users.py @@ -24,13 +24,15 @@ def arping_helper(dic): class snmp_users(Configurable): mac_list = {} - def __init__(self,config=None): - Configurable.__init__(self,DEFAULT_CONFIG) + def __init__(self,MODULE_NAME,config=None): + self.NAME=MODULE_NAME + newConf = { MODULE_NAME : DEFAULT_CONFIG } + Configurable.__init__(self,newConf) self.load_conf(config) def call_external(self): """returns an array of lines produced by snmpwalk """ - conf = self.config['snmp'] + conf = self.config[self.NAME]['snmp'] out = subprocess.Popen( ['snmpwalk', @@ -56,12 +58,10 @@ class snmp_users(Configurable): """ Verifies ip and mac via ARP Scan in addition it adds the correct ip to the mac_list """ macl = self.mac_list = {} - for ip,mac in new: # fill the mac_list if not macl.get(mac,None): macl[mac] = [] macl[mac].append(ip) - return True def verify(self,snmp_data): @@ -69,14 +69,15 @@ class snmp_users(Configurable): [0] is the ip and [1] is the mac (space-delimited)""" arp_data = self.arping_parallel(snmp_data) self.update_results(arp_data) + def get_own_addr(self): - data = subprocess.Popen(['/sbin/ifconfig',self.config['arping']['dev']], + data = subprocess.Popen(['/sbin/ifconfig',self.config[self.NAME]['arping']['dev']], stdout=subprocess.PIPE).communicate()[0].replace('\n','') return re.sub(r'.*HWaddr ([0-9:A-F]*).*inet addr:([0-9.]*).*' ,r'\1 \2',data).split() def arping_parallel(self,data): - conf = self.config['arping'] + conf = self.config[self.NAME]['arping'] if conf['active']: tmp = [ {'iprange':dat[0],'iface':conf['dev']} for dat in data] try: @@ -94,6 +95,8 @@ class snmp_users(Configurable): def collect(self): output = self.call_external() data = self.parse_output(output) + if not data: + raise Exception('External tool had not returned any parsable output') log.debug('Got following output from snmpwalk program: ' +str(data)) macs = self.verify(data) #self.print_results(self.mac_list) |