-
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.
#1843 WIP added disk monitoring route
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
thehive/app/org/thp/thehive/controllers/v1/MonitoringCtrl.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,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) | ||
) | ||
|
||
} |
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