Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1843 #1846

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.scala
Original file line number Diff line number Diff line change
@@ -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))
)

}
3 changes: 3 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Router @Inject() (
// dashboardCtrl: DashboardCtrl,
describeCtrl: DescribeCtrl,
logCtrl: LogCtrl,
monitoringCtrl: MonitoringCtrl,
observableCtrl: ObservableCtrl,
observableTypeCtrl: ObservableTypeCtrl,
organisationCtrl: OrganisationCtrl,
Expand Down Expand Up @@ -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
}
}