Skip to content

Commit

Permalink
#1946 Improve diagnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 8, 2021
1 parent 8041ff2 commit c9d16fa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
4 changes: 3 additions & 1 deletion conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
<appender-ref ref="STDOUT"/>
</appender>

<!--
<logger name="org.thp.scalligraph.models" level="TRACE"/>
<logger name="org.thp.scalligraph.traversal" level="TRACE"/>
<logger name="org.thp.thehive.services.StreamSrv" level="INFO"/>
<logger name="org.thp.thehive.services.StreamActor" level="INFO"/>
-->
<logger name="org.reflections8.Reflections" level="ERROR" />
<!--
<logger name="org.janusgraph.graphdb" level="INFO" />
Expand All @@ -46,7 +48,7 @@
<logger name="org.thp.scalligraph.graphql" level="TRACE" />
<logger name="org.janusgraph.graphdb.transaction.StandardJanusGraphTx" level="ERROR" />
-->
<logger name="org.thp.thehive" level="TRACE"/>
<logger name="org.thp.thehive" level="ERROR"/>

<root level="INFO">
<appender-ref ref="ASYNCFILE"/>
Expand Down
21 changes: 21 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/AdminCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import scala.collection.immutable
import scala.concurrent.duration.DurationInt
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Success
import ch.qos.logback.classic.{Level, LoggerContext}
import org.slf4j.LoggerFactory

@Singleton
class AdminCtrl @Inject() (
Expand All @@ -40,6 +42,25 @@ class AdminCtrl @Inject() (
}
lazy val logger: Logger = Logger(getClass)

def setLogLevel(packageName: String, levelName: String): Action[AnyContent] =
entrypoint("Update log level")
.authPermitted(Permissions.managePlatform) { _ =>
val level = levelName match {
case "ALL" => Level.ALL
case "DEBUG" => Level.DEBUG
case "INFO" => Level.INFO
case "WARN" => Level.WARN
case "ERROR" => Level.ERROR
case "OFF" => Level.OFF
case "TRACE" => Level.TRACE
case _ => Level.INFO
}
val loggerContext = LoggerFactory.getILoggerFactory.asInstanceOf[LoggerContext]
val logger = loggerContext.getLogger(packageName)
logger.setLevel(level)
Success(Results.NoContent)
}

def triggerCheck(name: String): Action[AnyContent] =
entrypoint("Trigger check")
.authPermitted(Permissions.managePlatform) { _ =>
Expand Down
9 changes: 5 additions & 4 deletions thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class Router @Inject() (
case GET(p"/status") => statusCtrl.get
// GET /health controllers.StatusCtrl.health

case GET(p"/admin/check/stats") => adminCtrl.checkStats
case GET(p"/admin/check/$name/trigger") => adminCtrl.triggerCheck(name)
case GET(p"/admin/index/status") => adminCtrl.indexStatus
case GET(p"/admin/index/$name/reindex") => adminCtrl.reindex(name)
case GET(p"/admin/check/stats") => adminCtrl.checkStats
case GET(p"/admin/check/$name/trigger") => adminCtrl.triggerCheck(name)
case GET(p"/admin/index/status") => adminCtrl.indexStatus
case GET(p"/admin/index/$name/reindex") => adminCtrl.reindex(name)
case GET(p"/admin/log/set/$packageName/$level") => adminCtrl.setLogLevel(packageName, level)

// GET /logout controllers.AuthenticationCtrl.logout()
case GET(p"/logout") => authenticationCtrl.logout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class IntegrityCheckActor() extends Actor {
Success(integrityCheck.initialCheck())
}
}
integrityCheckOps.foreach { integrityCheck =>
self ! DuplicationCheck(integrityCheck.name)
}
// integrityCheckOps.foreach { integrityCheck =>
// self ! DuplicationCheck(integrityCheck.name)
// }
globalTimers = integrityCheckOps.map { integrityCheck =>
val interval = globalInterval(integrityCheck.name)
val initialDelay = FiniteDuration((interval.toNanos * Random.nextDouble()).round, NANOSECONDS)
Expand Down

0 comments on commit c9d16fa

Please sign in to comment.