Merge pull request #1743 from othyn/master

Add in the ability to set a manual UPS capacity override in `dynamix.apcupsd`
This commit is contained in:
tom mortensen
2024-06-04 14:14:37 -07:00
committed by GitHub
5 changed files with 29 additions and 2 deletions

View File

@@ -1958,6 +1958,10 @@ Enter the *device* which corresponds to your situation, only applicable when *UP
+ **modbus** - /dev/tty**
:end
:apc_ups_override_ups_capacity_help:
If your device doesn't natively report Nominal Power (`NOMPOWER`) from `apcupsd`, but does report the Load Percentage (`LOADPCT`), you can manually define the UPS capacity rating in Watts (W) (this is the 'real power' value in Watts (W), not the 'apparent power' in Volt Amps (VA), and should be detailed on your UPS manual or product listing) and the plugin will dynamically calculate a virtual Nominal Power estimate (`≈`) by comparing the Override UPS Capacity (W) and the current Load Percentage. It is only an estimate, as it doesn't factor in things like the UPS' efficiency.
:end
:apc_battery_level_help:
If during a power failure, the remaining battery percentage (as reported by the UPS) is below or equal to *Battery level*, apcupsd will initiate a system shutdown.
:end

View File

@@ -91,6 +91,11 @@ _(Device)_:
:apc_ups_device_help:
_(Override UPS Capacity (Watts))_:
: <input type="number" name="OVERRIDE_UPS_CAPACITY" maxlength="5" class="narrow" value="<?=htmlspecialchars($cfg['OVERRIDE_UPS_CAPACITY']);?>">
:apc_ups_override_ups_capacity_help:
_(Battery level to initiate shutdown)_ (%):
: <input type="text" name="BATTERYLEVEL" class="narrow" maxlength="3" value="<?=htmlspecialchars($cfg['BATTERYLEVEL']);?>">

View File

@@ -3,6 +3,7 @@ UPSCABLE="usb"
CUSTOMUPSCABLE=""
UPSTYPE="usb"
DEVICE=""
OVERRIDE_UPS_CAPACITY=""
BATTERYLEVEL="10"
MINUTES="10"
TIMEOUT="0"

View File

@@ -18,6 +18,10 @@ $docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp');
$_SERVER['REQUEST_URI'] = 'settings';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
$cfg = parse_plugin_cfg('dynamix.apcupsd');
$overrideUpsCapacity = (int) htmlspecialchars($cfg['OVERRIDE_UPS_CAPACITY'] ?: 0);
$state = [
'ONLINE' => _('Online'),
'SLAVE' => '('._('slave').')',
@@ -34,7 +38,8 @@ $state = [
$red = "class='red-text'";
$green = "class='green-text'";
$orange = "class='orange-text'";
$status = array_fill(0,7,"<td>-</td>");
$defaultCell = "<td>-</td>";
$status = array_fill(0,7,$defaultCell);
$result = [];
$level = $_POST['level'] ?: 10;
$runtime = $_POST['runtime'] ?: 5;
@@ -89,6 +94,11 @@ if (file_exists("/var/run/apcupsd.pid")) {
if ($power && isset($load)) $status[5] = ($load<90 ? "<td $green>" : "<td $red>").round($power*$load/100)." W (".$status[5].")</td>";
elseif (isset($load)) $status[5] = ($load<90 ? "<td $green>" : "<td $red>").$status[5]."</td>";
$status[6] = isset($output) ? ((!$volt || ($minv<$output && $output<$maxv) ? "<td $green>" : "<td $red>").$status[6].(isset($freq) ? " ~ $freq Hz" : "")."</td>") : $status[6];
if ($status[4] == $defaultCell && $overrideUpsCapacity > 0 && isset($load) && $load > 0) {
$nominalPower = round($load * 0.01 * $overrideUpsCapacity);
$status[4] = ($nominalPower > 0 ? "<td $green>" : "<td $red>") . "≈ $nominalPower W</td>";
}
}
if (empty($rows)) $result[] = "<tr><td colspan='4' style='text-align:center'>"._('No information available')."</td></tr>";

View File

@@ -69,12 +69,14 @@ while (true) {
update_translation($locale_init);
}
unset($echo,$rows,$power,$load,$freq,$output,$volt);
$echo = array_fill(0,7,"<span>-</span>");
$defaultCell = "<span>-</span>";
$echo = array_fill(0,7,$defaultCell);
if (file_exists("/var/run/apcupsd.pid")) {
// get battery-level and runtime settings
$cfg = parse_plugin_cfg('dynamix.apcupsd');
$level = $cfg['BATTERYLEVEL'] ?: 10;
$runtime = $cfg['MINUTES'] ?: 5;
$overrideUpsCapacity = (int) htmlspecialchars($cfg['OVERRIDE_UPS_CAPACITY'] ?: 0);
exec("/sbin/apcaccess -u 2>/dev/null", $rows);
foreach ($rows as $row) {
[$key, $val] = array_map('trim', explode(':', $row, 2));
@@ -120,6 +122,11 @@ while (true) {
if (isset($power) && isset($load)) $echo[5] = ($load<90 ? "<span $green>" : "<span $red>").round($power*$load/100)." W (".$echo[5].")</span>";
elseif (isset($load)) $echo[5] = ($load<90 ? "<span>" : "<span $red>").$echo[5]."</span>";
$echo[6] = isset($output) ? ((empty($volt) || ($minv<$output && $output<$maxv) ? "<span $green>" : "<span $red>").$echo[6].(isset($freq) ? " ~ $freq Hz" : "")."</span>") : $echo[6];
if ($echo[4] == $defaultCell && $overrideUpsCapacity > 0 && isset($load) && $load > 0) {
$nominalPower = round($load * 0.01 * $overrideUpsCapacity);
$echo[4] = ($nominalPower > 0 ? "<span $green>" : "<span $red>") . "≈ $nominalPower W</span>";
}
}
$echo = json_encode($echo);
$md5_new = md5($echo,true);