Skip to content

Commit

Permalink
#1875 Fix taskId format in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 25, 2021
1 parent 710386a commit 56c37fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
37 changes: 31 additions & 6 deletions thehive/app/org/thp/thehive/models/TheHiveSchemaDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {

tags.foreach(vertex.property(Cardinality.list, "tags", _))
vertex.property("organisationId", organisationId.value)
caseId.foreach(vertex.property("caseId", _))
caseId.foreach(cid => vertex.property("caseId", cid.value))
case _ =>
}
Success(())
Expand Down Expand Up @@ -292,12 +292,12 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
traversal
.project(
_.by
.by(_.in("TaskLog")._id)
.by(_.in("TaskLog")._id.option)
.by(_.in("TaskLog").in("ShareTask").in("OrganisationShare")._id.fold)
)
.foreach {
case (vertex, taskId, organisationIds) =>
vertex.property("taskId", taskId)
taskId.foreach(tid => vertex.property("taskId", tid.value))
organisationIds.foreach(id => vertex.property(Cardinality.set, "organisationIds", id.value))
}
Success(())
Expand All @@ -312,7 +312,7 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
traversal
.project(
_.by
.by(_.out("ObservableObservableType").property("name", UMapping.string))
.by(_.out("ObservableObservableType").property("name", UMapping.string).option)
.by(_.out("ObservableTag").valueMap("namespace", "predicate", "value").fold)
.by(_.out("ObservableData").property("data", UMapping.string).option)
.by(_.out("ObservableAttachment").property("attachmentId", UMapping.string).option)
Expand All @@ -338,7 +338,7 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
(if (predicate.headOption.getOrElse('_') == '_') "" else predicate) +
value.fold("")(v => f"""="$v"""")

vertex.property("dataType", dataType)
dataType.foreach(vertex.property("dataType", _))
tags.foreach(vertex.property(Cardinality.list, "tags", _))
data.foreach(vertex.property("data", _))
attachmentId.foreach(vertex.property("attachmentId", _))
Expand Down Expand Up @@ -399,6 +399,21 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
.removeIndex("Log", IndexType.fulltext, "message")
.removeIndex("Tag", IndexType.fulltext, "description")
.removeIndex("Task", IndexType.fulltext, "description")
// .updateGraph("Set caseId in imported alerts", "Alert") { traversal =>
// traversal
// .project(
// _.by
// .by(_.out("AlertCase")._id.option)
// )
// .foreach {
// case (vertex, caseId) =>
// caseId.foreach(cid => vertex.property("caseId", cid.value))
// case _ =>
// }
// Success(())
// }
.noop
//=====[release 4.1.1]=====
.updateGraph("Set caseId in imported alerts", "Alert") { traversal =>
traversal
.project(
Expand All @@ -407,7 +422,17 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
)
.foreach {
case (vertex, caseId) =>
caseId.foreach(vertex.property("caseId", _))
caseId.foreach(cid => vertex.property("caseId", cid.value))
case _ =>
}
Success(())
}
.updateGraph("Set taskId in logs", "Log") { traversal =>
traversal
.project(_.by.by(_.in("TaskLog")._id.option))
.foreach {
case (vertex, Some(taskId)) =>
vertex.property("taskId", taskId.value)
case _ =>
}
Success(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class StatusCtrlTest extends PlaySpecification with TestAppBuilder {
"pollingDuration" -> 1000
),
"schemaStatus" -> Json.arr(
Json.obj("name" -> "thehive", "currentVersion" -> 67, "expectedVersion" -> 67, "error" -> JsNull)
Json.obj("name" -> "thehive", "currentVersion" -> 69, "expectedVersion" -> 69, "error" -> JsNull)
)
)

Expand Down

0 comments on commit 56c37fc

Please sign in to comment.