Skip to content
Snippets Groups Projects
Commit 1dea7ed0 authored by Marcus Scharf's avatar Marcus Scharf
Browse files

style rework / fix bug in traffic and memory / no alias.json needed

parent 63adccf6
No related branches found
No related tags found
No related merge requests found
...@@ -9,12 +9,13 @@ def call(cmdnargs): ...@@ -9,12 +9,13 @@ def call(cmdnargs):
output = subprocess.check_output(cmdnargs, stderr=subprocess.STDOUT) output = subprocess.check_output(cmdnargs, stderr=subprocess.STDOUT)
lines = output.splitlines() lines = output.splitlines()
lines = [line.decode('utf-8') for line in lines] lines = [line.decode('utf-8') for line in lines]
return lines
except subprocess.CalledProcessError as err: except subprocess.CalledProcessError as err:
print(err) print(err)
return []
except: except:
print(str(sys.exc_info()[0])) print(str(sys.exc_info()[0]))
else:
return lines
return [] return []
def merge(a, b): def merge(a, b):
......
...@@ -73,7 +73,7 @@ class Nodeinfo(Respondd): ...@@ -73,7 +73,7 @@ class Nodeinfo(Respondd):
return ret return ret
@staticmethod @staticmethod
def getVPN(batmanInterface): def getVPNFlag(batmanInterface):
lines = lib.helper.call(['batctl', '-m', batmanInterface, 'gw_mode']) lines = lib.helper.call(['batctl', '-m', batmanInterface, 'gw_mode'])
if re.match(r'^server', lines[0]): if re.match(r'^server', lines[0]):
return True return True
...@@ -115,7 +115,7 @@ class Nodeinfo(Respondd): ...@@ -115,7 +115,7 @@ class Nodeinfo(Respondd):
'owner': {}, 'owner': {},
'system': {}, 'system': {},
'location': {}, 'location': {},
'vpn': self.getVPN(self._config['batman']) 'vpn': self.getVPNFlag(self._config['batman'])
} }
if 'mesh-vpn' in self._config and len(self._config['mesh-vpn']) > 0: if 'mesh-vpn' in self._config and len(self._config['mesh-vpn']) > 0:
...@@ -127,5 +127,8 @@ class Nodeinfo(Respondd): ...@@ -127,5 +127,8 @@ class Nodeinfo(Respondd):
except: except:
pass pass
if 'nodeinfo' in self._aliasOverlay:
return lib.helper.merge(ret, self._aliasOverlay['nodeinfo']) return lib.helper.merge(ret, self._aliasOverlay['nodeinfo'])
else:
return ret
#!/usr/bin/env python3 #!/usr/bin/env python3
import time
class rateLimit: # rate limit like iptables limit (per minutes) class rateLimit: # rate limit like iptables limit (per minutes)
tLast = None tLast = None
......
...@@ -10,13 +10,14 @@ class Respondd: ...@@ -10,13 +10,14 @@ class Respondd:
self._config = config self._config = config
self._aliasOverlay = {} self._aliasOverlay = {}
try: try:
with open('alias.json', 'r') as fh: with open('alias.json', 'r') as fh: # TODO: prevent loading more then once !
self._aliasOverlay = json.load(fh) self._aliasOverlay = json.load(fh)
except IOError: except IOError:
raise print('can\'t load alias.json!')
pass
def getNodeID(self): def getNodeID(self):
if 'node_id' in self._aliasOverlay['nodeinfo']: if 'nodeinfo' in self._aliasOverlay and 'node_id' in self._aliasOverlay['nodeinfo']:
return self._aliasOverlay['nodeinfo']['node_id'] return self._aliasOverlay['nodeinfo']['node_id']
else: else:
return lib.helper.getInterfaceMAC(self._config['batman']).replace(':', '') return lib.helper.getInterfaceMAC(self._config['batman']).replace(':', '')
......
...@@ -51,7 +51,7 @@ class Statistics(Respondd): ...@@ -51,7 +51,7 @@ class Statistics(Respondd):
lineSplit = line.strip().split(':', 1) lineSplit = line.strip().split(':', 1)
name = lineSplit[0] name = lineSplit[0]
value = lineSplit[1].strip() value = lineSplit[1].strip()
traffic[name] = value traffic[name] = int(value)
ret = { ret = {
'tx': { 'tx': {
...@@ -86,7 +86,7 @@ class Statistics(Respondd): ...@@ -86,7 +86,7 @@ class Statistics(Respondd):
for line in lines: for line in lines:
lineSplit = line.split(' ', 1) lineSplit = line.split(' ', 1)
name = lineSplit[0][:-1] name = lineSplit[0][:-1]
value = lineSplit[1].strip().split(' ', 1)[0] value = int(lineSplit[1].strip().split(' ', 1)[0])
if name == 'MemTotal': if name == 'MemTotal':
ret['total'] = value ret['total'] = value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment