mirror of https://github.com/MISP/misp-dashboard
new: [dispatcher/livelog] Added support of ObjectAttributes
parent
999e59b5cb
commit
b207338501
|
@ -120,14 +120,14 @@ class Contributor_helper:
|
|||
if action in ['edit', None]:
|
||||
pass
|
||||
#return #not a contribution?
|
||||
|
||||
|
||||
now = datetime.datetime.now()
|
||||
nowSec = int(time.time())
|
||||
pnts_to_add = self.default_pnts_per_contribution
|
||||
|
||||
|
||||
# Do not consider contribution as login anymore
|
||||
#self.users_helper.add_user_login(nowSec, org)
|
||||
|
||||
|
||||
# is a valid contribution
|
||||
if categ is not None:
|
||||
try:
|
||||
|
@ -135,23 +135,23 @@ class Contributor_helper:
|
|||
except KeyError:
|
||||
pnts_to_add = self.default_pnts_per_contribution
|
||||
pnts_to_add *= pntMultiplier
|
||||
|
||||
|
||||
util.push_to_redis_zset(self.serv_redis_db, self.keyDay, org, count=pnts_to_add)
|
||||
#CONTRIB_CATEG retain the contribution per category, not the point earned in this categ
|
||||
util.push_to_redis_zset(self.serv_redis_db, self.keyCateg, org, count=1, endSubkey=':'+util.noSpaceLower(categ))
|
||||
self.publish_log(zmq_name, 'CONTRIBUTION', {'org': org, 'categ': categ, 'action': action, 'epoch': nowSec }, channel=self.CHANNEL_LASTCONTRIB)
|
||||
else:
|
||||
categ = ""
|
||||
|
||||
|
||||
self.serv_redis_db.sadd(self.keyAllOrg, org)
|
||||
|
||||
|
||||
keyname = "{}:{}".format(self.keyLastContrib, util.getDateStrFormat(now))
|
||||
self.serv_redis_db.zadd(keyname, nowSec, org)
|
||||
self.logger.debug('Added to redis: keyname={}, nowSec={}, org={}'.format(keyname, nowSec, org))
|
||||
self.serv_redis_db.expire(keyname, util.ONE_DAY*7) #expire after 7 day
|
||||
|
||||
|
||||
awards_given = self.updateOrgContributionRank(org, pnts_to_add, action, contribType, eventTime=datetime.datetime.now(), isLabeled=isLabeled, categ=util.noSpaceLower(categ))
|
||||
|
||||
|
||||
for award in awards_given:
|
||||
# update awards given
|
||||
keyname = "{}:{}".format(self.keyLastAward, util.getDateStrFormat(now))
|
||||
|
@ -589,4 +589,3 @@ class Contributor_helper:
|
|||
return { 'remainingPts': i-points, 'stepPts': prev }
|
||||
prev = i
|
||||
return { 'remainingPts': 0, 'stepPts': self.rankMultiplier**self.levelMax }
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ class Live_helper:
|
|||
self.serv_live.publish(channel, j_to_send)
|
||||
self.logger.debug('Published: {}'.format(j_to_send))
|
||||
if name != 'Keepalive':
|
||||
name = 'Attribute' if 'ObjectAttribute' else name
|
||||
self.add_to_stream_log_cache(name, j_to_send_keep)
|
||||
|
||||
|
||||
|
|
|
@ -121,9 +121,13 @@ class EventMessage():
|
|||
|
||||
self.name = jsonMsg['name']
|
||||
self.zmqName = jsonMsg['zmqName']
|
||||
|
||||
if self.name == 'Attribute':
|
||||
self.feed = jsonMsg['log']
|
||||
self.feed = LogItem(self.feed, filters).get_row()
|
||||
elif self.name == 'ObjectAttribute':
|
||||
self.feed = jsonMsg['log']
|
||||
self.feed = LogItem(self.feed, filters).get_row()
|
||||
else:
|
||||
self.feed = jsonMsg['log']
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ $(document).ready(function () {
|
|||
pollingFrequency: 5000,
|
||||
tableHeader: head,
|
||||
tableMaxEntries: 50,
|
||||
animate: false,
|
||||
// animate: false,
|
||||
preDataURL: urlForLogs,
|
||||
endpoint: urlForLogs
|
||||
});
|
||||
|
@ -333,45 +333,44 @@ function createHead(callback) {
|
|||
{ targets: 0, orderable: false },
|
||||
{ targets: '_all', searchable: false, orderable: false,
|
||||
render: function ( data, type, row ) {
|
||||
// return data +' ('+ row[3]+')';
|
||||
var $toRet;
|
||||
if (typeof data === 'object') {
|
||||
$toRet = $('<span></span>');
|
||||
data.data.forEach(function(cur, i) {
|
||||
switch (data.name) {
|
||||
case 'Tag':
|
||||
var $tag = $('<a></a>');
|
||||
$tag.addClass('tagElem');
|
||||
$tag.css({
|
||||
backgroundColor: cur.colour,
|
||||
color: getTextColour(cur.colour.substring(1,6))
|
||||
});
|
||||
$tag.text(cur.name)
|
||||
$toRet.append($tag);
|
||||
break;
|
||||
case 'mispObject':
|
||||
$toRet.append('MISP Object not supported yet')
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
$toRet = $toRet[0].outerHTML;
|
||||
} else if (data === undefined) {
|
||||
$toRet = '';
|
||||
} else {
|
||||
var textToAddArray = data.split(char_separator);
|
||||
var $toRet;
|
||||
if (typeof data === 'object') {
|
||||
$toRet = $('<span></span>');
|
||||
data.data.forEach(function(cur, i) {
|
||||
switch (data.name) {
|
||||
case 'Tag':
|
||||
var $tag = $('<a></a>');
|
||||
$tag.addClass('tagElem');
|
||||
$tag.css({
|
||||
backgroundColor: cur.colour,
|
||||
color: getTextColour(cur.colour.substring(1,6))
|
||||
});
|
||||
$tag.text(cur.name)
|
||||
$toRet.append($tag);
|
||||
break;
|
||||
case 'mispObject':
|
||||
$toRet.append('MISP Object not supported yet')
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
$toRet = $toRet[0].outerHTML;
|
||||
} else if (data === undefined) {
|
||||
$toRet = '';
|
||||
textToAddArray.forEach(function(e, i) {
|
||||
if (i > 0) {
|
||||
$toRet += '<br>' + e;
|
||||
} else {
|
||||
$toRet += e;
|
||||
}
|
||||
});
|
||||
}
|
||||
return $toRet;
|
||||
},
|
||||
} else {
|
||||
var textToAddArray = data.split(char_separator);
|
||||
$toRet = '';
|
||||
textToAddArray.forEach(function(e, i) {
|
||||
if (i > 0) {
|
||||
$toRet += '<br>' + e;
|
||||
} else {
|
||||
$toRet += e;
|
||||
}
|
||||
});
|
||||
}
|
||||
return $toRet;
|
||||
},
|
||||
}
|
||||
],
|
||||
};
|
||||
|
@ -474,6 +473,9 @@ function createHead(callback) {
|
|||
case 'Attribute':
|
||||
that.add_entry(entry);
|
||||
break;
|
||||
case 'ObjectAttribute':
|
||||
that.add_entry(entry, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -499,6 +501,9 @@ function createHead(callback) {
|
|||
case 'Attribute':
|
||||
that.add_entry(entry);
|
||||
break;
|
||||
case 'ObjectAttribute':
|
||||
that.add_entry(entry, true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -577,14 +582,21 @@ function createHead(callback) {
|
|||
}
|
||||
},
|
||||
|
||||
add_entry: function(entry) {
|
||||
add_entry: function(entry, isObjectAttribute) {
|
||||
var rowNode = this.dt.row.add(entry).draw().node();
|
||||
if (this.animate) {
|
||||
if (this._options.animate) {
|
||||
$( rowNode )
|
||||
.css( 'background-color', '#5cb85c' )
|
||||
.animate( { 'background-color': '', duration: 600 } );
|
||||
.css( 'background-color', '#5cb85c !important' )
|
||||
.animate( { 'background-color': '' }, { duration: 1500 } );
|
||||
}
|
||||
if (isObjectAttribute === true) {
|
||||
console.log(entry);
|
||||
$( rowNode ).children().last()
|
||||
.css('position', 'relative')
|
||||
.append(
|
||||
$('<it class="fa fa-th rowTableIsObject" title="This attribute belong to an Object"></it>')
|
||||
);
|
||||
}
|
||||
// this.dt.row.add(entry).draw( false );
|
||||
// remove entries
|
||||
var numRows = this.dt.rows().count();
|
||||
var rowsToRemove = numRows - this._options.tableMaxEntries;
|
||||
|
|
|
@ -189,10 +189,17 @@ div.dataTables_scrollHead table.dataTable {
|
|||
left: 15px !important;
|
||||
right: 10px !important;
|
||||
z-index: 1001 !important;
|
||||
bottom: 5px !important;
|
||||
bottom: -7px !important;
|
||||
height: unset !important;
|
||||
}
|
||||
|
||||
.rowTableIsObject {
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 0px;
|
||||
color: #3465a4;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -122,7 +122,16 @@ def handler_conversation(zmq_name, jsonevent):
|
|||
|
||||
def handler_object(zmq_name, jsondata):
|
||||
logger.info('Handling object')
|
||||
return
|
||||
# check if jsonattr is an mispObject object
|
||||
if 'Object' in jsondata:
|
||||
jsonobj = jsondata['Object']
|
||||
soleObject = copy.deepcopy(jsonobj)
|
||||
del soleObject['Attribute']
|
||||
for jsonattr in jsonobj['Attribute']:
|
||||
jsonattrcpy = copy.deepcopy(jsonobj)
|
||||
jsonattrcpy['Event'] = jsondata['Event']
|
||||
jsonattrcpy['Attribute'] = jsonattr
|
||||
handler_attribute(zmq_name, jsonattrcpy, False, parentObject=soleObject)
|
||||
|
||||
def handler_sighting(zmq_name, jsondata):
|
||||
logger.info('Handling sighting')
|
||||
|
@ -168,6 +177,16 @@ def handler_event(zmq_name, jsonobj):
|
|||
else:
|
||||
handler_attribute(zmq_name, attributes)
|
||||
|
||||
if 'Object' in jsonevent:
|
||||
objects = jsonevent['Object']
|
||||
if type(objects) is list:
|
||||
for obj in objects:
|
||||
jsoncopy = copy.deepcopy(jsonobj)
|
||||
jsoncopy['Object'] = obj
|
||||
handler_object(zmq_name, jsoncopy)
|
||||
else:
|
||||
handler_object(zmq_name, objects)
|
||||
|
||||
action = jsonobj.get('action', None)
|
||||
eventLabeled = len(jsonobj.get('EventTag', [])) > 0
|
||||
org = jsonobj.get('Orgc', {}).get('name', None)
|
||||
|
@ -179,11 +198,15 @@ def handler_event(zmq_name, jsonobj):
|
|||
action,
|
||||
isLabeled=eventLabeled)
|
||||
|
||||
def handler_attribute(zmq_name, jsonobj, hasAlreadyBeenContributed=False):
|
||||
def handler_attribute(zmq_name, jsonobj, hasAlreadyBeenContributed=False, parentObject=False):
|
||||
logger.info('Handling attribute')
|
||||
# check if jsonattr is an attribute object
|
||||
if 'Attribute' in jsonobj:
|
||||
jsonattr = jsonobj['Attribute']
|
||||
else:
|
||||
jsonattr = jsonobj
|
||||
|
||||
attributeType = 'Attribute' if jsonattr['object_id'] == '0' else 'ObjectAttribute'
|
||||
|
||||
#Add trending
|
||||
categName = jsonattr['category']
|
||||
|
@ -210,12 +233,12 @@ def handler_attribute(zmq_name, jsonobj, hasAlreadyBeenContributed=False):
|
|||
eventLabeled = len(jsonobj.get('EventTag', [])) > 0
|
||||
action = jsonobj.get('action', None)
|
||||
contributor_helper.handleContribution(zmq_name, jsonobj['Event']['Orgc']['name'],
|
||||
'Attribute',
|
||||
attributeType,
|
||||
jsonattr['category'],
|
||||
action,
|
||||
isLabeled=eventLabeled)
|
||||
# Push to log
|
||||
live_helper.publish_log(zmq_name, 'Attribute', jsonobj)
|
||||
live_helper.publish_log(zmq_name, attributeType, jsonobj)
|
||||
|
||||
|
||||
###############
|
||||
|
|
Loading…
Reference in New Issue