From ce00c4b9e5d9713204da617e0ccd8fbf8adde30d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 16 Jan 2024 17:17:07 +0100 Subject: [PATCH] #12696 fix tactical view error 500 and schedule by group --- .../include/lib/TacticalView/elements/Agents.php | 14 +++++++++----- .../include/lib/TacticalView/elements/Groups.php | 3 ++- .../TacticalView/elements/ScheduledDowntime.php | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/lib/TacticalView/elements/Agents.php b/pandora_console/include/lib/TacticalView/elements/Agents.php index a0e14313e0..659b9c31d0 100644 --- a/pandora_console/include/lib/TacticalView/elements/Agents.php +++ b/pandora_console/include/lib/TacticalView/elements/Agents.php @@ -436,12 +436,16 @@ class Agents extends Element $percentages = []; $total = array_sum($data); foreach ($data as $key => $value) { - $percentage = (($value / $total) * 100); - if ($percentage < 1 && $percentage > 0) { - $percentage = 1; - } + if ($total > 0) { + $percentage = (($value / $total) * 100); + if ($percentage < 1 && $percentage > 0) { + $percentage = 1; + } - $percentages[$key] = format_numeric($percentage, 0); + $percentages[$key] = format_numeric($percentage, 0); + } else { + $percentages[$key] = '0%'; + } } $data = $percentages; diff --git a/pandora_console/include/lib/TacticalView/elements/Groups.php b/pandora_console/include/lib/TacticalView/elements/Groups.php index 4fe07b743a..c314381b59 100644 --- a/pandora_console/include/lib/TacticalView/elements/Groups.php +++ b/pandora_console/include/lib/TacticalView/elements/Groups.php @@ -113,8 +113,9 @@ class Groups extends Element $id_groups = implode(',', $id_groups); $modules = modules_get_modules_in_group($id_groups); - $total_groups = count($modules); + $total_groups = ($modules !== false) ? count($modules) : 0; if ($total_groups === 0) { + include_once $config['homedir'].'/include/functions_graph.php'; return graph_nodata_image(['width' => '400']); } diff --git a/pandora_console/include/lib/TacticalView/elements/ScheduledDowntime.php b/pandora_console/include/lib/TacticalView/elements/ScheduledDowntime.php index 9e94e17275..563e59b0f2 100644 --- a/pandora_console/include/lib/TacticalView/elements/ScheduledDowntime.php +++ b/pandora_console/include/lib/TacticalView/elements/ScheduledDowntime.php @@ -156,13 +156,15 @@ class ScheduledDowntime extends Element 'cron_interval_from', 'cron_interval_to', ]; - + $groups = implode(',', array_keys(users_get_groups($config['user']))); $columns_str = implode(',', $columns); $sql = sprintf( 'SELECT %s FROM tplanned_downtime + WHERE id_group IN (%s) %s %s', $columns_str, + $groups, $order, $pagination, );