Simplify dhcp

This commit is contained in:
Ely Deckers 2022-02-16 15:15:56 +01:00
parent 1229bf6370
commit 798ffa8b8b

View File

@ -124,6 +124,12 @@ define('SMART_DEV_STATUS', [
SMART_DEV_UNKNOWN => SMART_UNKNOWN SMART_DEV_UNKNOWN => SMART_UNKNOWN
]); ]);
define("DHCP_SECTIONS", [
"failover" => function () {
echo pfz_dhcp_check_failover();
},
]);
require_once('globals.inc'); require_once('globals.inc');
require_once('functions.inc'); require_once('functions.inc');
require_once('config.inc'); require_once('config.inc');
@ -1128,27 +1134,24 @@ function pfz_dhcpfailover_discovery(){
echo $json_string; echo $json_string;
} }
function pfz_dhcp_check_failover(){ function pfz_dhcp_check_failover()
// Check DHCP Failover Status {
// Returns number of failover pools which state is not normal or // Check DHCP Failover Status
// different than peer state // Returns number of failover pools which state is not normal or
$failover = pfz_dhcp_get("failover"); // different than peer state
$ret = 0; $failover = pfz_dhcp_get("failover");
foreach ($failover as $f){
if ( ($f["mystate"]!="normal") || ($f["mystate"]!=$f["peerstate"])) { return count(array_filter($failover, fn($f) => ($f["mystate"] != "normal") || ($f["mystate"] != $f["peerstate"])));
$ret++;
}
}
return $ret;
} }
function pfz_dhcp($section, $valuekey=""){ function pfz_dhcp($section, $valuekey = "")
switch ($section){ {
case "failover": $is_known_section = array_key_exists($section, DHCP_SECTIONS);
echo pfz_dhcp_check_failover(); if (!$is_known_section) {
break; return;
default: }
}
DHCP_SECTIONS[$section]();
} }
// Packages // Packages