];
}
+ /**
+ * Check if volume type is disk type.
+ *
+ * @return boolean true if it is disk type, otherwise false
+ */
+ private function isDiskVolType($voltype) {
+ $disk_vt = $this->getDiskVolTypes();
+ return in_array($voltype, $disk_vt);
+ }
+
+ /**
+ * Check if volume type is cloud type.
+ *
+ * @return boolean true if it is cloud type, otherwise false
+ */
+ private function isCloudVolType($voltype) {
+ $cloud_vt = $this->getCloudVolTypes();
+ return in_array($voltype, $cloud_vt);
+ }
+
+ /**
+ * Check if volume type is tape type.
+ *
+ * @return boolean true if it is tape type, otherwise false
+ */
+ private function isTapeVolType($voltype) {
+ $tape_vt = $this->getTapeVolTypes();
+ return in_array($voltype, $tape_vt);
+ }
+
public function getVolumes($criteria = array(), $props = [], $limit_val = 0, $offset_val = 0, $order_by = null, $order_direction = 'DESC') {
$order_pool_id = 'PoolId';
$order_volume = 'VolumeName';
$volumes = array_keys($result);
return $volumes;
}
+
+ /**
+ * Get volume statistics per volume type (disk, cloud, tape...)
+ *
+ * @return array statistics or empty array if no volume record found
+ */
+ public function getVolumeStatsByType() {
+ $sql = 'SELECT VolType AS voltype,
+ SUM(VolBytes) AS total_size,
+ COUNT(1) AS count
+ FROM Media
+ GROUP BY voltype';
+ $statement = Database::runQuery($sql);
+ $result = $statement->fetchAll(\PDO::FETCH_GROUP);
+ $stats = [];
+ foreach ($result as $voltype => $item) {
+ $res = [
+ 'total_size' => (int)$item[0]['total_size'],
+ 'count' => $item[0]['count']
+ ];
+ if ($this->isDiskVolType($voltype)) {
+ $stats[self::VOLTYPE_GROUP_DISK] = $res;
+ } elseif ($this->isCloudVolType($voltype)) {
+ $stats[self::VOLTYPE_GROUP_CLOUD] = $res;
+ } elseif ($this->isTapeVolType($voltype)) {
+ $stats[self::VOLTYPE_GROUP_TAPE] = $res;
+ }
+ }
+ return $stats;
+ }
}
?>
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2024 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\VolumeError;
+
+/**
+ * Volumes endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class VolumeStatsByVolType extends BaculumAPIServer {
+
+ public function get() {
+ $result = $this->getModule('volume')->getVolumeStatsByType();
+ $this->output = $result;
+ $this->error = VolumeError::ERROR_NO_ERRORS;
+ }
+}
<url ServiceParameter="VolumeLabelBarcodes" pattern="api/v2/volumes/label/barcodes/" />
<url ServiceParameter="SlotsUpdate" pattern="api/v2/volumes/update/" />
<url ServiceParameter="SlotsUpdate" pattern="api/v2/volumes/update/{barcodes}/" parameters.barcodes="barcodes" />
+ <url ServiceParameter="VolumeStatsByVolType" pattern="api/v2/volumes/stats/" />
<url ServiceParameter="VolumeNames" pattern="api/v2/volumes/names/" />
<!-- pools endpoints -->
<url ServiceParameter="Pools" pattern="api/v2/pools/" />
]
}
},
+ "/api/v2/volumes/stats": {
+ "get": {
+ "tags": ["volumes"],
+ "summary": "Volume statistics.",
+ "description": "Get volume statistics.",
+ "responses": {
+ "200": {
+ "description": "Volume statistics per volume type.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "object",
+ "properties": {
+ "disk": {
+ "type": "object",
+ "properties": {
+ "total_size": {
+ "type": "integer",
+ "description": "Total size of disk volumes"
+ },
+ "count": {
+ "type": "integer",
+ "description": "Disk volume count"
+ }
+ }
+ },
+ "cloud": {
+ "type": "object",
+ "properties": {
+ "total_size": {
+ "type": "integer",
+ "description": "Total size of cloud volumes"
+ },
+ "count": {
+ "type": "integer",
+ "description": "Cloud volume count"
+ }
+ }
+ },
+ "tape": {
+ "type": "object",
+ "properties": {
+ "total_size": {
+ "type": "integer",
+ "description": "Total size of tape volumes"
+ },
+ "count": {
+ "type": "integer",
+ "description": "Tape volume count"
+ }
+ }
+ }
+ }
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 1, 2, 3, 5, 6, 7, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/api/v2/volumes/names": {
"get": {
"tags": ["volumes"],