diff --git a/ScalliGraph b/ScalliGraph index 499de18528..0657450b06 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 499de18528e24013c5b0280c8d88a870ebfb33b9 +Subproject commit 0657450b06a9b35b1bfa3a7e8ed89c1246140637 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..f4e210599c --- /dev/null +++ b/thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala @@ -0,0 +1,48 @@ +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 diskLocations: ConfigItem[Seq[PartitionConfig], Seq[PartitionConfig]] = + appConfig.item[Seq[PartitionConfig]]("monitor.disk", "disk locations to monitor") + + def monitorDiskUsage: Action[AnyContent] = + entrypoint("monitor disk usage") + .authPermittedTransaction(db, Permissions.managePlatform)(implicit request => + implicit graph => + for { + _ <- Success(()) + locations = + diskLocations + .get + .foldLeft[JsArray](JsArray.empty)((array, p) => + array :+ Json.obj( + "location" -> p.location, + "freeSpace" -> new File(p.location).getFreeSpace, + "totalSpace" -> new File(p.location).getTotalSpace + ) + ) + } yield Results.Ok(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..7c42c78230 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.monitorDiskUsage } }