#13636 vc performance recursive loops change image and title

This commit is contained in:
Jonathan 2024-05-07 14:06:07 +02:00
parent 1718e8b5c5
commit 45e777b184
3 changed files with 35 additions and 31 deletions

View File

@ -258,6 +258,7 @@ define('VISUAL_MAP_STATUS_NORMAL', 0);
define('VISUAL_MAP_STATUS_WARNING', 2);
define('VISUAL_MAP_STATUS_UNKNOWN', 3);
define('VISUAL_MAP_STATUS_WARNING_ALERT', 10);
define('VISUAL_MAP_STATUS_LOOPING', 33);
// Wizard.
define('VISUAL_MAP_WIZARD_PARENTS_NONE', 0);
define('VISUAL_MAP_WIZARD_PARENTS_ITEM_MAP', 1);

View File

@ -3221,6 +3221,10 @@ function visual_map_get_image_status_element($layoutData, $status=false)
$img .= '_warning.png';
break;
case 33:
$img = 'images/alert-yellow@svg.svg';
break;
case 3:
// Unknown.
default:
@ -3898,12 +3902,13 @@ function visual_map_get_layout_status(
VISUAL_MAP_STATUS_WARNING => 0,
VISUAL_MAP_STATUS_UNKNOWN => 0,
VISUAL_MAP_STATUS_WARNING_ALERT => 0,
VISUAL_MAP_STATUS_LOOPING => 0,
]
) {
global $config;
if (in_array($layout_id, $exclude_recursive) === true) {
return VISUAL_MAP_STATUS_UNKNOWN;
return VISUAL_MAP_STATUS_LOOPING;
}
$exclude_recursive[] = $layout_id;
@ -4095,6 +4100,10 @@ function visual_map_get_layout_status(
if (isset($status_data['linked_layout_status_type']) === true) {
// Status calculation.
if (isset($num_elements_by_status[VISUAL_MAP_STATUS_LOOPING]) === true && empty($num_elements_by_status[VISUAL_MAP_STATUS_LOOPING]) === false) {
return VISUAL_MAP_STATUS_LOOPING;
}
switch ($status_data['linked_layout_status_type']) {
default:
case 'default':

View File

@ -150,7 +150,7 @@ final class StaticGraph extends Item
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
$tooltip_infinite_loop = null;
/*
* Retrieve extra data.
*/
@ -189,41 +189,30 @@ final class StaticGraph extends Item
// There's no need to connect to the metaconsole before searching
// for the image status cause the function itself does that for us.
$imagePath = \visual_map_get_image_status_element($data);
if (str_contains($imagePath, '_bad.png') === true) {
// Critical or critical alert (BAD).
$data['colorStatus'] = COL_CRITICAL;
} else if (str_contains($imagePath, '_ok.png') === true) {
// Normal (OK).
$data['colorStatus'] = COL_NORMAL;
} else if (str_contains($imagePath, '_warning.png') === true) {
// Warning or warning alert.
$data['colorStatus'] = COL_WARNING;
} else if (str_contains($imagePath, 'alert-yellow@svg.svg') === true) {
// Default is Grey (Other).
$data['colorStatus'] = COL_UNKNOWN;
$tooltip_infinite_loop = __('Infinite link loop found. Can not determine status.');
} else {
// Default is Grey (Other).
$data['colorStatus'] = COL_UNKNOWN;
}
$data['statusImageSrc'] = \ui_get_full_url(
$imagePath,
false,
false,
false
);
$status = \visual_map_get_status_element($data);
// Magic numbers from the hell.
switch ($status) {
case 1:
case 4:
// Critical or critical alert (BAD).
$data['colorStatus'] = COL_CRITICAL;
break;
case 0:
// Normal (OK).
$data['colorStatus'] = COL_NORMAL;
break;
case 2:
case 10:
// Warning or warning alert.
$data['colorStatus'] = COL_WARNING;
break;
case 3:
// Unknown.
default:
// Default is Grey (Other).
$data['colorStatus'] = COL_UNKNOWN;
break;
}
} else {
$data['colorStatus'] = COL_UNKNOWN;
$imagePath = 'images/console/icons/'.$data['image'].'.png';
@ -295,6 +284,11 @@ final class StaticGraph extends Item
}
}
if (empty($tooltip_infinite_loop) === false) {
$data['lastValue'] = $tooltip_infinite_loop;
$data['showLastValueTooltip'] = 'enabled';
}
return $data;
}