Added possibility to display any fields form zmq + possibility to display for objects

pull/18/head
Sami Mokaddem 2017-10-27 13:19:22 +02:00
parent 724157f9e5
commit c566cea338
3 changed files with 41 additions and 14 deletions

View File

@ -19,7 +19,7 @@ zoomlevel = 11
clusteringDistance = 10 clusteringDistance = 10
[Log] [Log]
fieldname_order=["Event.id", "Attribute.category", "Attribute.type", ["Attribute.value", "Attribute.comment"]] fieldname_order=["Event.id", "Attribute.Tag", "Attribute.category", "Attribute.type", ["Attribute.value", "Attribute.comment"]]
#fieldname_order=["id", "category", "type", ["value", "comment"]] #fieldname_order=["id", "category", "type", ["value", "comment"]]
char_separator=|| char_separator=||

View File

@ -265,18 +265,37 @@ function slideAndMax(orig, newData) {
return [curMaxDataNumLog, slided]; return [curMaxDataNumLog, slided];
} }
function addObjectToLog(name, obj, td) {
if(name == "Tag") {
td.appendChild(document.createTextNode('tag'));
} else if (name == "mispObject") {
td.appendChild(document.createTextNode('mispObj'));
} else {
td.appendChild(document.createTextNode('nop'));
}
}
function createRow(tableBody, log) { function createRow(tableBody, log) {
var tr = document.createElement('TR'); var tr = document.createElement('TR');
for (var key in log) { for (var key in log) {
if (log.hasOwnProperty(key)) { if (log.hasOwnProperty(key)) {
var td = document.createElement('TD'); var td = document.createElement('TD');
if(typeof log[key] === 'object') { //handle list of objects
theObj = log[key];
for(var objI in theObj.data) {
addObjectToLog(theObj.name, theObj.data[objI], td);
}
} else {
var textToAddArray = log[key].split(char_separator); var textToAddArray = log[key].split(char_separator);
for(var i in textToAddArray){ for(var i in textToAddArray){
if (i > 0) if (i > 0)
td.appendChild(document.createElement("br")); td.appendChild(document.createElement("br"));
td.appendChild(document.createTextNode(textToAddArray[i])); td.appendChild(document.createTextNode(textToAddArray[i]));
} }
}
tr.appendChild(td); tr.appendChild(td);
} }
} }

View File

@ -86,6 +86,22 @@ def getCoordAndPublish(zmq_name, supposed_ip, categ):
except ValueError: except ValueError:
print("can't resolve ip") print("can't resolve ip")
def getFields(obj, fields):
jsonWalker = fields.split('.')
itemToExplore = obj
lastName = ""
try:
for i in jsonWalker:
itemToExplore = itemToExplore[i]
lastName = i
if type(itemToExplore) is list:
return { 'name': lastName , 'data': itemToExplore }
else:
return itemToExplore
except KeyError as e:
return ""
############## ##############
## HANDLERS ## ## HANDLERS ##
############## ##############
@ -115,14 +131,6 @@ def handler_event(zmq_name, jsonevent):
else: else:
handler_attribute(zmq_name, attributes) handler_attribute(zmq_name, attributes)
def getFields(obj, fields):
jsonWalker = fields.split('.')
itemToExplore = obj
for i in jsonWalker:
itemToExplore = itemToExplore[i]
return itemToExplore
def handler_attribute(zmq_name, jsonobj): def handler_attribute(zmq_name, jsonobj):
# check if jsonattr is an attribute object # check if jsonattr is an attribute object
if 'Attribute' in jsonobj: if 'Attribute' in jsonobj: