Skip to content

Commit

Permalink
#221 Retrieve list of all MISP attributes for new event (remove filte…
Browse files Browse the repository at this point in the history
…r on timestamp)
  • Loading branch information
To-om committed May 23, 2017
1 parent f4ae4a3 commit ebd9b29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion thehive-misp/app/connectors/misp/JsonFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ object JsonFormat {
publishTimestamp (json \ "publish_timestamp").validate[String]
publishDate = new Date(publishTimestamp.toLong * 1000)
threatLevel (json \ "threat_level_id").validate[String]
isPublished (json \ "published").validate[Boolean]
} yield MispAlert(
org,
eventId,
date,
publishDate,
isPublished,
s"#$eventId ${info.trim}",
s"Imported from MISP Event #$eventId, created at $date",
threatLevel.toLong,
Expand All @@ -43,7 +45,7 @@ object JsonFormat {
"")
}

implicit val mispAlertWrites: Writes[MispAlert] = Json.writes[MispAlert]
implicit val mispAlertWrites: Writes[MispAlert] = Json.writes[MispAlert].transform((_: JsValue).asInstanceOf[JsObject] - "isPublished")

implicit val attributeReads: Reads[MispAttribute] = Reads(json
for {
Expand Down
1 change: 1 addition & 0 deletions thehive-misp/app/connectors/misp/MispModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ case class MispAlert(
sourceRef: String,
date: Date,
lastSyncDate: Date,
isPublished: Boolean,
title: String,
description: String,
severity: Long,
Expand Down
10 changes: 6 additions & 4 deletions thehive-misp/app/connectors/misp/MispSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,21 @@ class MispSrv @Inject() (
// get related alert
.mapAsyncUnordered(1) {
case (mcfg, lastSyncDate, event)
logger.trace(s"Looking for alert misp:${event.source}:${event.sourceRef}")
alertSrv.get("misp", event.source, event.sourceRef)
.map(a (mcfg, lastSyncDate, event, a))
}
.mapAsyncUnordered(1) {
case (mcfg, lastSyncDate, event, alert)
logger.trace(s"MISP synchro ${mcfg.name} last sync at $lastSyncDate, event ${event.sourceRef}, alert ${alert.fold("no alert")("alert" + _.alertId())}")
logger.info(s"getting MISP event ${event.sourceRef}")
getAttributes(mcfg, event.sourceRef, Some(lastSyncDate))
getAttributes(mcfg, event.sourceRef, alert.map(_ lastSyncDate))
.map((mcfg, event, alert, _))
}
.mapAsyncUnordered(1) {
// if there is no related alert, create a new one
case (mcfg, event, None, attrs)
logger.info(s"MISP event ${event.sourceRef} has no related alert, create it")
logger.info(s"MISP event ${event.sourceRef} has no related alert, create it with ${attrs.size} observable(s)")
val alertJson = Json.toJson(event).as[JsObject] +
("type" JsString("misp")) +
("caseTemplate" mcfg.caseTemplate.fold[JsValue](JsNull)(JsString)) +
Expand All @@ -193,7 +195,7 @@ class MispSrv @Inject() (

// if a related alert exists, update it
case (_, event, Some(alert), attrs)
logger.info(s"MISP event ${event.sourceRef} has related alert, update it")
logger.info(s"MISP event ${event.sourceRef} has related alert, update it with ${attrs.size} observable(s)")
val alertJson = Json.toJson(event).as[JsObject] -
"type" -
"source" -
Expand Down Expand Up @@ -247,7 +249,7 @@ class MispSrv @Inject() (
None
}
}
.filter(_.date after fromDate)
.filter(event event.isPublished && event.date.after(fromDate))

val eventJsonSize = eventJson.size
val eventsSize = events.size
Expand Down

0 comments on commit ebd9b29

Please sign in to comment.