Skip to content

Commit

Permalink
#1946 Use indexQuery for tag usage and observable count in case extra…
Browse files Browse the repository at this point in the history
…Data
  • Loading branch information
To-om committed Apr 11, 2021
1 parent 9fe06fb commit 3df647a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CaseCtrl @Inject() (
Query.init[Long](
"countCase",
(graph, authContext) =>
graph.indexCountQuery(s"""v."_label":Case AND v.organisationIds:${organisationSrv.currentId(graph, authContext).value} """)
graph.indexCountQuery(s"""v."_label":Case AND v.organisationIds:${organisationSrv.currentId(graph, authContext).value}""")
),
Query[Traversal.V[Case], Traversal.V[Observable]](
"observables",
Expand Down
14 changes: 9 additions & 5 deletions thehive/app/org/thp/thehive/controllers/v1/CaseRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ import java.util.{Collection => JCollection, List => JList, Map => JMap}
trait CaseRenderer extends BaseRenderer[Case] {
val limitedCountThreshold: Long

def observableStats(implicit authContext: AuthContext): Traversal.V[Case] => Traversal[JsValue, JLong, Converter[JsValue, JLong]] =
_.share
.observables
.limitedCount(limitedCountThreshold)
.domainMap(count => Json.obj("total" -> count))
def observableStats(implicit authContext: AuthContext): Traversal.V[Case] => Traversal[JsObject, AnyRef, Converter[JsObject, AnyRef]] =
t =>
t._id.domainMap { caseId =>
Json.obj("total" -> t.graph.indexCountQuery(s"""v."_label":Case AND v.relatedId:${caseId.value}"""))
}
// _.share
// .observables
// .limitedCount(limitedCountThreshold)
// .domainMap(count => Json.obj("total" -> count))

def taskStats(implicit
authContext: AuthContext
Expand Down
44 changes: 30 additions & 14 deletions thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,36 @@ trait TagRenderer extends BaseRenderer[Tag] {
def usageStats(implicit
authContext: AuthContext
): Traversal.V[Tag] => Traversal[JsObject, JMap[String, Any], Converter[JsObject, JMap[String, Any]]] =
_.project(
_.by(_.`case`.limitedCount(limitedCountThreshold))
.by(_.alert.limitedCount(limitedCountThreshold))
.by(_.observable.limitedCount(limitedCountThreshold))
.by(_.caseTemplate.limitedCount(limitedCountThreshold))
).domainMap {
case (caseCount, alertCount, observableCount, caseTemplateCount) =>
Json.obj(
"case" -> caseCount,
"alert" -> alertCount,
"observable" -> observableCount,
"caseTemplate" -> caseTemplateCount
)
}
t =>
t.project(
_.by(_.value(_.predicate))
.by(_.caseTemplate.limitedCount(limitedCountThreshold))
).domainMap {
case (tag, caseTemplateCount) =>
Json.obj(
"case" -> t.graph.indexCountQuery(s"""v."_label":Case AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""),
"alert" -> t.graph.indexCountQuery(s"""v."_label":Alert AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""),
"observable" -> t.graph.indexCountQuery(s"""v."_label":Observable AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""),
"caseTemplate" -> caseTemplateCount
)
}
// def usageStats(implicit
// authContext: AuthContext
// ): Traversal.V[Tag] => Traversal[JsObject, JMap[String, Any], Converter[JsObject, JMap[String, Any]]] =
// _.project(
// _.by(_.`case`.limitedCount(limitedCountThreshold))
// .by(_.alert.limitedCount(limitedCountThreshold))
// .by(_.observable.limitedCount(limitedCountThreshold))
// .by(_.caseTemplate.limitedCount(limitedCountThreshold))
// ).domainMap {
// case (caseCount, alertCount, observableCount, caseTemplateCount) =>
// Json.obj(
// "case" -> caseCount,
// "alert" -> alertCount,
// "observable" -> observableCount,
// "caseTemplate" -> caseTemplateCount
// )
// }

def tagStatsRenderer(extraData: Set[String])(implicit
authContext: AuthContext
Expand Down

0 comments on commit 3df647a

Please sign in to comment.