-
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.
Merge pull request #1846 from TheHive-Project/issue-1843
Issue 1843
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
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,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)) | ||
) | ||
|
||
} |
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