summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-18 01:48:38 +0100
committerFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-18 01:48:38 +0100
commit5a55c1b82a26244fb8a2584fa35887d9637bd2e2 (patch)
treea8809b57e6139d480ed2a882b462d1daae2716a7
parentbcf8f6653e09d9b1072c6fbe87d03ae0257cba36 (diff)
fixed logging bug,updated protocol
-rw-r--r--main.py22
-rwxr-xr-xsnmp_users.py4
2 files changed, 18 insertions, 8 deletions
diff --git a/main.py b/main.py
index 868b5f7e..bb463d3b 100644
--- a/main.py
+++ b/main.py
@@ -1,19 +1,28 @@
#!/usr/bin/env python2
-import pika
-import json,argparse
-from snmp_users import snmp_users
+
import logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger('snmp_exchange')
+import pika
+import json,argparse,hashlib,sys,time
+from snmp_users import snmp_users
+
SNMP_EXCHANGE='snmp_src'
+PROTO_VERSION='1'
-parser = argparse.ArgumentParser(description='generates dummy package on given exchange against AMQP')
+parser = argparse.ArgumentParser(description='Generates a list of mac-addresses currently in the network via snmp ')
parser.add_argument('--host',default='141.31.8.11', help='AMQP host ip address')
parser.add_argument('--port',type=int,default=5672, help='AMQP host port')
parser.add_argument('-u','--username',default='guest', help='AMQP username')
parser.add_argument('-p','--password',default='guest', help='AMQP password')
parser.add_argument('-r','--repeat',type=int,default=20, help='SNMP_Polling Delay')
+parser.add_argument('--unique-key',action='store_true', help='Unique Key')
+args = parser.parse_args()
+if args.unique_key:
+ print hashlib.sha1(PROTO_VERSION+args.host+str(args.port)).hexdigest()
+ sys.exit(0)
+
args = parser.parse_args()
connection = pika.AsyncoreConnection(pika.ConnectionParameters(
@@ -24,9 +33,9 @@ channel = connection.channel()
channel.exchange_declare(exchange=SNMP_EXCHANGE,
type='fanout')
-log.info('Starting StatsForUser Module (mongodb)')
+log.info('Starting up snmp_users')
s = snmp_users()
-print ' [*] Sending Messages in Intervals. To exit press CTRL+C'
+print ' Sending Messages in Intervals. To exit press CTRL+C'
while True:
log.info("collecting data from network")
ret = s.collect()
@@ -35,3 +44,4 @@ while True:
channel.basic_publish(exchange=SNMP_EXCHANGE,
routing_key='',
body=json.dumps(data))
+ time.sleep(args.repeat)
diff --git a/snmp_users.py b/snmp_users.py
index 6eb5c33c..8e2fb05d 100755
--- a/snmp_users.py
+++ b/snmp_users.py
@@ -45,11 +45,11 @@ class snmp_users:
if mac in self.mac_list.keys():
log.info( "%s already assigned for ip %s (new IP %s) " %
( mac ,self.mac_list[mac], ip))
- self.mac_list[mac]['counter'] +=1
+ self.mac_list[mac].append ( ip)
continue
else:
log.debug("%s => %s" % (mac,ip))
- self.mac_list[mac] = { 'ip' : ip, 'counter' : 1}
+ self.mac_list[mac] = [ ip ]
else:
log.warning("Verification failed %s => %s" % (mac,ip))