diff --git a/ScalliGraph b/ScalliGraph index 499de18528..b403c2c2db 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 499de18528e24013c5b0280c8d88a870ebfb33b9 +Subproject commit b403c2c2db7e163550022283512c1f6d0c9fe91a diff --git a/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala new file mode 100644 index 0000000000..3729b0a96d --- /dev/null +++ b/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala @@ -0,0 +1,47 @@ +package org.thp.thehive.controllers.v1 + +import org.thp.scalligraph.controllers.Entrypoint +import org.thp.scalligraph.models.Database +import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} +import org.thp.thehive.models.Permissions +import play.api.libs.json.{Format, JsArray, Json} +import play.api.mvc.{Action, AnyContent, Results} + +import java.io.File +import javax.inject.{Inject, Singleton} +import scala.util.Success + +@Singleton +class MonitoringCtrl @Inject() ( + appConfig: ApplicationConfig, + entrypoint: Entrypoint, + db: Database +) { + case class PartitionConfig(location: String) + + object PartitionConfig { + implicit val format: Format[PartitionConfig] = Json.format[PartitionConfig] + } + + val diskLocationsConfig: ConfigItem[Seq[PartitionConfig], Seq[PartitionConfig]] = + appConfig.item[Seq[PartitionConfig]]("monitor.disk", "disk locations to monitor") + def diskLocations: Seq[PartitionConfig] = diskLocationsConfig.get + + def diskUsage: Action[AnyContent] = + entrypoint("monitor disk usage") + .authPermittedTransaction(db, Permissions.managePlatform)(implicit request => + implicit graph => + for { + _ <- Success(()) + locations = diskLocations.map { dl => + val file = new File(dl.location) + Json.obj( + "location" -> dl.location, + "freeSpace" -> file.getFreeSpace, + "totalSpace" -> file.getTotalSpace + ) + } + } yield Results.Ok(JsArray(locations)) + ) + +} diff --git a/thehive/app/org/thp/thehive/controllers/v1/Router.scala b/thehive/app/org/thp/thehive/controllers/v1/Router.scala index 39e95117d6..652fbdd85d 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Router.scala @@ -20,6 +20,7 @@ class Router @Inject() ( // dashboardCtrl: DashboardCtrl, describeCtrl: DescribeCtrl, logCtrl: LogCtrl, + monitoringCtrl: MonitoringCtrl, observableCtrl: ObservableCtrl, observableTypeCtrl: ObservableTypeCtrl, organisationCtrl: OrganisationCtrl, @@ -177,5 +178,7 @@ class Router @Inject() ( case GET(p"/observable/type/$idOrName") => observableTypeCtrl.get(idOrName) case POST(p"/observable/type") => observableTypeCtrl.create case DELETE(p"/observable/type/$idOrName") => observableTypeCtrl.delete(idOrName) + + case GET(p"/monitor/disk") => monitoringCtrl.diskUsage } }