|
@@ -117,6 +117,11 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
self.__respond_findnode(query)
|
|
|
return
|
|
|
|
|
|
+ # /identify?ident=xyz
|
|
|
+ if path == 'identify':
|
|
|
+ self.__respond_identify([query.get('ident')])
|
|
|
+ return
|
|
|
+
|
|
|
# /node/<id>.json - node's data
|
|
|
# /node/<id>/field - return specific field from node's data
|
|
|
match = REGEX_URL_NODEINFO.match(path)
|
|
@@ -152,6 +157,11 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
|
|
|
return
|
|
|
params = self.__parse_post_params()
|
|
|
|
|
|
+ # identify listed macs
|
|
|
+ if path == 'identify':
|
|
|
+ self.__respond_identify(params)
|
|
|
+ return
|
|
|
+
|
|
|
# node id/mac to name mapping
|
|
|
if path == 'idmac2name':
|
|
|
self.__respond_nodeidmac2name(params)
|
|
@@ -432,6 +442,30 @@ angesprochen und sollte aus einer Mehrzahl von Gründen nicht
|
|
|
nodename = node.get('hostname', nodeid) if node is not None else nodeid
|
|
|
self.wfile.write('{0}={1}\n'.format(nodeid, nodename))
|
|
|
|
|
|
+ def __respond_identify(self, idents):
|
|
|
+ self.__send_headers('application/json')
|
|
|
+ nodes = {n['node_id']: n for n in self.server.storage.get_nodes()}
|
|
|
+ answers = {}
|
|
|
+ for ident in idents:
|
|
|
+ ident = ident.lower()
|
|
|
+ answer = []
|
|
|
+ answers[ident] = answer
|
|
|
+
|
|
|
+ if ident in nodes:
|
|
|
+ answer.append('node id of "%s"' % nodes[ident].get('hostname'))
|
|
|
+ continue
|
|
|
+
|
|
|
+ for nodeid in nodes:
|
|
|
+ node = nodes[nodeid]
|
|
|
+ if ident == node.get('mac', '').lower() or \
|
|
|
+ ident in [x.lower() for x in node.get('macs', [])]:
|
|
|
+ answer.append('mac of node "%s" (id %s)' % (node.get('hostname', '?'), node.get('node_id')))
|
|
|
+
|
|
|
+ if ident in [c.lower() for c in node.get('clients', [])]:
|
|
|
+ answer.append('client at node "%s"' % node.get('hostname', '?'))
|
|
|
+
|
|
|
+ self.wfile.write(json.dumps(answers))
|
|
|
+
|
|
|
def __respond_nodedetail(self, nodeid, field):
|
|
|
"""
|
|
|
Return a field from the given node.
|