Commit 13a9f4be authored by root's avatar root

Removing influxDB and addind additional output

parent d343eb2e
......@@ -10,7 +10,7 @@ import threading
import alfred
import batadv
import copy
import alfred_to_influxdb as db
#import alfred_to_influxdb as db
def client(config, channels):
......@@ -24,12 +24,14 @@ def alfred_cleaner(config, alfred_channels,batadv,alfredLock,batadvLock):
count = 0
while True:
count += 1
#print("Aquire alfed")
print("Aquire alfed for cleanup")
alfredLock.acquire(True)
#print("Nice!")
print("Nice!")
for channel in alfred_channels.keys():
#print('a')
to_del = []
for node in alfred_channels[channel].keys():
#print('b')
try:
if time.time() - alfred_channels[channel][node]['time'] > config['update_interval'] * 2:
to_del.append(node)
......@@ -41,14 +43,19 @@ def alfred_cleaner(config, alfred_channels,batadv,alfredLock,batadvLock):
for node in to_del:
del alfred_channels[channel][node]
# wait 5 min befor writing new data into influxdb
if count % 30 == 0:
db.toInfluxdb('', hostname='localhost', port=8086, username='freifunk', password='freifunk', database='freifunk',jsond=alfred_channels[channel])
#if count % 30 == 0:
# db.toInfluxdb('', hostname='localhost', port=8086, username='freifunk', password='freifunk', database='freifunk',jsond=alfred_channels[channel])
#print("worked all channels")
f = open(config['alfred_out'],'w')
#print("opened file")
json.dump(alfred_channels,f)
#print("json dumped")
f.close()
#print("file closed")
alfredLock.release()
print("Release alfed")
#print("Aquireing bamän..")
print("Aquireing bamän..")
batadvLock.acquire(True)
#print("ok =)")
new = list(filter(lambda entry: time.time() - entry['time'] > config['update_interval'] * 2, batadv))
......@@ -59,11 +66,12 @@ def alfred_cleaner(config, alfred_channels,batadv,alfredLock,batadvLock):
output = ""
for entry in batadv:
output += entry['data']+'\n'
print("writing data")
#print("writing data")
#print(output)
f.write(output)
f.close()
batadvLock.release()
print("Release bamän..")
time.sleep(10)
......@@ -77,6 +85,7 @@ def alfred_server(config, alfred_channels,batadv_data,alfredLock,batadvLock):
data = gzip.zlib.decompress(data)
rdata = json.loads(data.decode('utf-8'))
if rdata[0] == "alfred":
print("got alfred data")
alfredLock.acquire(True)
channel = rdata[1]
message = rdata[2]
......@@ -88,7 +97,7 @@ def alfred_server(config, alfred_channels,batadv_data,alfredLock,batadvLock):
try:
mac = node['network']['mac']
except KeyError as e:
print(node)
#print(node)
alfredLock.release()
continue
else: #fuck you
......@@ -103,6 +112,7 @@ def alfred_server(config, alfred_channels,batadv_data,alfredLock,batadvLock):
alfredLock.release()
elif rdata[0] == "batadv-vis":
print("got batadv-vis data")
batadvLock.acquire(True)
line = rdata[1]
entry = {'time': time.time()}
......@@ -128,7 +138,7 @@ def main():
f = open(args.configFile)
config=json.load(f)
except :
print('config file error')
#print('config file error')
parser.print_help()
exit(0)
......
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