summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-31 22:16:58 +0100
committerFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-31 22:16:58 +0100
commitc40db19a0214bdc6aa4807d3f704815fad833992 (patch)
tree2cda1c8d4316a9239135200040fa059eb17006c9
parentda06f1c3d243477e7481c2cc07d86843b14a65a4 (diff)
updated code to work again
Added changes to make it work with python-genericore version 6.0 Added example configuration
-rw-r--r--.gitignore1
-rw-r--r--TODO.md4
-rw-r--r--conf/example.json22
-rwxr-xr-xsrc/main.py7
-rwxr-xr-xsrc/snmp_users.py17
5 files changed, 41 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..0d20b648
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.pyc
diff --git a/TODO.md b/TODO.md
new file mode 100644
index 00000000..dfefa9a0
--- /dev/null
+++ b/TODO.md
@@ -0,0 +1,4 @@
+BUGS
+=====
+- an exception is thrown but handled wrong when snmp servers and arping is
+ unreachable
diff --git a/conf/example.json b/conf/example.json
new file mode 100644
index 00000000..f34c20f0
--- /dev/null
+++ b/conf/example.json
@@ -0,0 +1,22 @@
+{
+ "snmp_users": {
+ "amqp": {
+ "connection": {
+ "login": "guest",
+ "password": "guest",
+ "host": "localhost"
+ },
+ "out": {
+ "exchange": "snmp_src"
+ }
+ },
+ "snmp": {
+ "server": "127.0.0.1",
+ "community": "community"
+ },
+ "arping": {
+ "active": true,
+ "dev": "eth0"
+ }
+ }
+}
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)