system: add disk space status check

above 95% usage triggers a persistent banner.

while here, fix a small issue that excluded persistent notification
types from counting towards the icon color used.
This commit is contained in:
Stephan de Wit 2025-01-13 10:38:21 +01:00
parent 0733e3bd4d
commit 9e660d360b
3 changed files with 81 additions and 3 deletions

1
plist
View File

@ -571,6 +571,7 @@
/usr/local/opnsense/mvc/app/library/OPNsense/OpenVPN/ViscosityVisz.php
/usr/local/opnsense/mvc/app/library/OPNsense/System/AbstractStatus.php
/usr/local/opnsense/mvc/app/library/OPNsense/System/Status/CrashReporterStatus.php
/usr/local/opnsense/mvc/app/library/OPNsense/System/Status/DiskSpaceStatus.php
/usr/local/opnsense/mvc/app/library/OPNsense/System/Status/FirewallStatus.php
/usr/local/opnsense/mvc/app/library/OPNsense/System/Status/LiveMediaStatus.php
/usr/local/opnsense/mvc/app/library/OPNsense/System/Status/SystemBootingStatus.php

View File

@ -84,9 +84,7 @@ class SystemController extends ApiControllerBase
}
/* Sort on the highest notification (non-persistent) error level after the ACL check */
$statusCodes = array_map(function ($v) {
return $v['persistent'] ? SystemStatusCode::OK : $v['statusCode'];
}, array_values($statuses));
$statusCodes = array_column($statuses, 'statusCode');
sort($statusCodes);
$response['metadata'] = [

View File

@ -0,0 +1,79 @@
<?php
/*
* Copyright (C) 2025 Deciso B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
namespace OPNsense\System\Status;
use OPNsense\System\AbstractStatus;
use OPNsense\System\SystemStatusCode;
use OPNsense\Core\Backend;
class DiskSpaceStatus extends AbstractStatus
{
public function __construct()
{
$this->internalPriority = 5;
$this->internalPersistent = false;
$this->internalTitle = gettext('Disk Space');
$backend = new Backend();
$output = json_decode($backend->configdRun('system diag disk'), true);
if (!isset($output['storage-system-information']) || !isset($output['storage-system-information']['filesystem'])) {
return;
}
foreach ($output['storage-system-information']['filesystem'] as $filesystem) {
if ($filesystem['mounted-on'] === '/') {
$usedPercent = intval($filesystem['used-percent']);
if ($usedPercent >= 90 && $usedPercent <= 95) {
$this->internalStatus = SystemStatusCode::WARNING;
$this->internalMessage = sprintf(
gettext('Disk space on the root filesystem is nearly full (' .
'%d%% used). Please consider cleaning up or expanding storage.'),
$usedPercent
);
} elseif ($usedPercent > 95) {
$this->internalPersistent = true;
$this->internalStatus = SystemStatusCode::ERROR;
$this->internalMessage = sprintf(
gettext('Disk space on the root filesystem is critically full (' .
'%d%% used). Please consider cleaning up or expanding storage.'),
$usedPercent
);
}
break;
}
}
}
public function dismissStatus()
{
/* XXX not applicable */
}
}