Commit 2a993ec5 authored by Matus Kubis's avatar Matus Kubis

add script

parent 76b6b6ce
import logging
import argparse
import os
from pysnmp.hlapi import *
from cassandra.cluster import Cluster
def setup_logging():
logging.basicConfig(level='INFO')
logging.info('Lgging started')
def mib_walk(ip, mib):
data = {}
for (errorIndication,
errorStatus,
errorIndex,
varBinds) in nextCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget((ip, 161)),
ContextData(),
ObjectType(ObjectIdentity(mib))):
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
break
else:
done = False
for varBind in varBinds:
id = str(varBind[0])
done = not str(varBind[0]).startswith(mib)
if done:
break
data[id] = varBind[1].prettyPrint()
if done:
break
return data
def main():
setup_logging()
mib = '1.3.6.1.4.1.14988.1.1.1.5.1.11'
ip = '147.175.186.234'
data = mib_walk(ip, mib)
for k in data:
idsplit = k.split('.')
cat = '.'.join(idsplit[:13])
usr = '.'.join(idsplit[13:])
print(cat, usr, data[k])
print("Cassandra thing")
cluster = Cluster()
session = cluster.connect()
session.execute('CREATE KEYSPACE IF NOT EXISTS wifi WITH REPLICATION = {\'class\' : \'SimpleStrategy\', \'replication_factor\' : 1 }')
session.execute('USE wifi')
# session.execute('DROP TABLE devices')
session.execute('''CREATE TABLE IF NOT EXISTS devices (
mac text,
time timestamp,
cap text,
strength int,
txbytes bigint,
rxbytes bigint,
txpackets bigint,
rxpackets bigint,
txrate text,
rxrate text,
assoctime int,
PRIMARY KEY (mac, time)
) WITH CLUSTERING ORDER BY (time DESC)''')
session.execute('INSERT INTO devices (mac, time) VALUES (\'aa:bb:cc:dd:ee:ff\', \'2018-01-01 11:00:02\')')
dat = session.execute('SELECT * FROM devices')
for d in dat:
print(d)
if __name__ == '__main__':
main()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment