Update handling of submetric values in index.php

Refactor condition to set submetric value based on fallback.
This commit is contained in:
Jeroen De Meerleer 2024-06-04 19:39:08 +02:00
parent 8d0959b21c
commit 81255d0b27
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -77,7 +77,7 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') {
if (is_bool($submetric['value'])) $submetric['value'] = $submetric['value'] ? 1 : 0; if (is_bool($submetric['value'])) $submetric['value'] = $submetric['value'] ? 1 : 0;
if(!empty($oldconfig) && empty($submetric['value']) && (isset($submetric['fallback']) && !empty($submetric['fallback']))) { if(!empty($oldconfig) && !isset($submetric['value']) && (isset($submetric['fallback']) && !empty($submetric['fallback']))) {
if(!isset($submetric['fallback']['maxage']) || time() < ($oldconfig[$key]['submetrics'][$subkey]['time'] + $submetric['fallback']['maxage'])) { if(!isset($submetric['fallback']['maxage']) || time() < ($oldconfig[$key]['submetrics'][$subkey]['time'] + $submetric['fallback']['maxage'])) {
if($submetric['fallback']['type'] == 'previous') { if($submetric['fallback']['type'] == 'previous') {
$submetric['value'] = $oldconfig[$key]['submetrics'][$subkey]['value']; $submetric['value'] = $oldconfig[$key]['submetrics'][$subkey]['value'];