count clients and add clientcount attribute to each node

This commit is contained in:
Nils Schneider 2014-04-10 17:17:11 +02:00
parent fbc5c636df
commit ac3366ff13
4 changed files with 24 additions and 1 deletions

View file

@ -64,6 +64,8 @@ if options['alfred']:
af = alfred() af = alfred()
db.import_aliases(af.aliases()) db.import_aliases(af.aliases())
db.count_clients()
if options['obscure']: if options['obscure']:
db.obscure_clients() db.obscure_clients()

View file

@ -16,7 +16,8 @@ class D3MapBuilder:
'macs': ', '.join(x.macs), 'macs': ', '.join(x.macs),
'geo': [float(x) for x in x.gps.split(" ")] if x.gps else None, 'geo': [float(x) for x in x.gps.split(" ")] if x.gps else None,
'firmware': x.firmware, 'firmware': x.firmware,
'flags': x.flags 'flags': x.flags,
'clientcount': x.clientcount
} for x in nodes] } for x in nodes]
links = self._db.get_links() links = self._db.get_links()

View file

@ -11,6 +11,7 @@ class Node():
}) })
self.gps = None self.gps = None
self.firmware = None self.firmware = None
self.clientcount = 0
def add_mac(self, mac): def add_mac(self, mac):
mac = mac.lower() mac = mac.lower()

View file

@ -218,6 +218,25 @@ class NodeDB:
link.type = "vpn" link.type = "vpn"
def count_clients(self):
for link in self._links:
try:
a = self.maybe_node_by_id(link.source.interface)
b = self.maybe_node_by_id(link.target.interface)
if a.flags['client']:
client = a
node = b
elif b.flags['client']:
client = b
node = a
else:
continue
node.clientcount += 1
except:
pass
def obscure_clients(self): def obscure_clients(self):
globalIdCounter = 0 globalIdCounter = 0