summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-17 17:16:18 +0100
committerFelix Richter <Felix.Richter@syntax-fehler.de>2011-01-17 17:16:18 +0100
commitbcf8f6653e09d9b1072c6fbe87d03ae0257cba36 (patch)
tree34d286e65c2774d41c7243787808adf7062c2cce
parentf95bf3d9f1c824f16205d29db24c5dcc0c5cb288 (diff)
added main class for sending data to mq
-rw-r--r--main.py38
-rwxr-xr-xsnmp_users.py2
2 files changed, 39 insertions, 1 deletions
diff --git a/main.py b/main.py
index 0e1d5dde..868b5f7e 100644
--- a/main.py
+++ b/main.py
@@ -1 +1,37 @@
-#!/usr/bin/python2
+#!/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')
+
+SNMP_EXCHANGE='snmp_src'
+
+parser = argparse.ArgumentParser(description='generates dummy package on given exchange against AMQP')
+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')
+args = parser.parse_args()
+
+connection = pika.AsyncoreConnection(pika.ConnectionParameters(
+ credentials = pika.PlainCredentials(args.username,args.password),
+ host=args.host,port=args.port))
+channel = connection.channel()
+
+channel.exchange_declare(exchange=SNMP_EXCHANGE,
+ type='fanout')
+
+log.info('Starting StatsForUser Module (mongodb)')
+s = snmp_users()
+print ' [*] Sending Messages in Intervals. To exit press CTRL+C'
+while True:
+ log.info("collecting data from network")
+ ret = s.collect()
+ data = { 'type' : 'snmp', 'subtype' : 0, 'data' : ret}
+ log.debug("writing data to queue : %s" % data)
+ channel.basic_publish(exchange=SNMP_EXCHANGE,
+ routing_key='',
+ body=json.dumps(data))
diff --git a/snmp_users.py b/snmp_users.py
index 481938d3..6eb5c33c 100755
--- a/snmp_users.py
+++ b/snmp_users.py
@@ -74,7 +74,9 @@ class snmp_users:
output = self.call_external()
self.parse_output(output)
self.print_results()
+ return self.mac_list
def print_results(self):
+ log.debug('printing results:')
print '\n'.join([ mac + " => " + ip['ip'] + " ( %d active leases )" %
ip['counter'] for mac,ip in self.mac_list.items() ])
print '%d *unique* nodes in network' % len(self.mac_list)