-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1670 Add extra data on tags to see usage
- Loading branch information
Showing
5 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.thp.thehive.controllers.v1 | ||
|
||
import org.thp.scalligraph.auth.AuthContext | ||
import org.thp.scalligraph.traversal.TraversalOps._ | ||
import org.thp.scalligraph.traversal.{Converter, Traversal} | ||
import org.thp.thehive.models.Tag | ||
import org.thp.thehive.services.TagOps._ | ||
import play.api.libs.json._ | ||
|
||
import java.util.{Map => JMap} | ||
|
||
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`.count) | ||
.by(_.alert.count) | ||
.by(_.observable.count) | ||
).domainMap { | ||
case (caseCount, alertCount, observableCount) => | ||
Json.obj( | ||
"case" -> caseCount, | ||
"alert" -> alertCount, | ||
"observable" -> observableCount | ||
) | ||
} | ||
|
||
def tagStatsRenderer(extraData: Set[String])(implicit | ||
authContext: AuthContext | ||
): Traversal.V[Tag] => JsTraversal = { implicit traversal => | ||
baseRenderer( | ||
extraData, | ||
traversal, | ||
{ | ||
case (f, "usage") => addData("usage", f)(usageStats) | ||
case (f, _) => f | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters