Skip to content

Commit

Permalink
#1210 Fix computed metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 30, 2020
1 parent a8fbcff commit 39d8d2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions thehive-backend/app/models/Alert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ trait AlertAttributes {
@Singleton
class AlertModel @Inject()(dblists: DBLists) extends ModelDef[AlertModel, Alert]("alert", "Alert", "/alert") with AlertAttributes with AuditedModel {

private[AlertModel] lazy val logger = Logger(getClass)
override val defaultSortBy: Seq[String] = Seq("-date")
override val removeAttribute: JsObject = Json.obj("status" AlertStatus.Ignored)
override val computedMetrics: Map[String, String] = Map("observableCount" "_source['artifacts']?.size()")
private[AlertModel] lazy val logger = Logger(getClass)
override val defaultSortBy: Seq[String] = Seq("-date")
override val removeAttribute: JsObject = Json.obj("status" AlertStatus.Ignored)
override val computedMetrics: Map[String, String] = Map(
"observableCount" "if (params._source.containsKey('artifacts')) { params._source['artifacts'].size() } else 0",
"handlingDurationInSeconds" "(doc['updatedAt'].date.getMillis() - doc['createdAt'].date.getMillis()) / 1000",
"handlingDurationInHours" "(doc['updatedAt'].date.getMillis() - doc['createdAt'].date.getMillis()) / 3600000",
"handlingDurationInDays" "(doc['updatedAt'].date.getMillis() - doc['createdAt'].date.getMillis()) / (3600000 * 24)"
)

override def creationHook(parent: Option[BaseEntity], attrs: JsObject): Future[JsObject] = {
// check if data attribute is present on all artifacts
Expand Down
6 changes: 3 additions & 3 deletions thehive-backend/app/models/Case.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ class CaseModel @Inject()(
}

override val computedMetrics = Map(
"handlingDurationInSeconds" "(doc['endDate'].value - doc['startDate'].value) / 1000",
"handlingDurationInHours" "(doc['endDate'].value - doc['startDate'].value) / 3600000",
"handlingDurationInDays" "(doc['endDate'].value - doc['startDate'].value) / (3600000 * 24)"
"handlingDurationInSeconds" "(doc['endDate'].date.getMillis() - doc['startDate'].date.getMillis()) / 1000",
"handlingDurationInHours" "(doc['endDate'].date.getMillis() - doc['startDate'].date.getMillis()) / 3600000",
"handlingDurationInDays" "(doc['endDate'].date.getMillis() - doc['startDate'].date.getMillis()) / (3600000 * 24)"
)
}

Expand Down

0 comments on commit 39d8d2e

Please sign in to comment.