From 35a7c409bf3f381e5de93c2028e4bcbf9905df9c Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Mon, 21 Aug 2023 13:03:44 +0200 Subject: [PATCH] #11873 Fixed Scheduled Downtime quiet mode for modules --- .../agentes/planned_downtime.editor.php | 6 +-- .../include/functions_planned_downtimes.php | 54 ++++++++----------- pandora_server/lib/PandoraFMS/Core.pm | 31 +++++------ 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/pandora_console/godmode/agentes/planned_downtime.editor.php b/pandora_console/godmode/agentes/planned_downtime.editor.php index 79516b3670..75ef5bb65b 100644 --- a/pandora_console/godmode/agentes/planned_downtime.editor.php +++ b/pandora_console/godmode/agentes/planned_downtime.editor.php @@ -1558,7 +1558,7 @@ function insert_downtime_agent($id_downtime, $user_groups_ad) $all_modules = true; } - if ($all_common_modules === true) { + if ($all_common_modules === true || $all_modules === true) { $module_names = explode(',', get_parameter('all_common_modules')); } @@ -1602,7 +1602,7 @@ function insert_downtime_agent($id_downtime, $user_groups_ad) foreach ($agents as $agent_id) { $agent_id = (int) $agent_id; // Check module belongs to the agent. - if ($modules_selection_mode == 'all' && $all_modules === false) { + if ($modules_selection_mode == 'all' && ($all_modules === false || $all_modules === true)) { $check = false; foreach ($module_names as $module_name) { $check_module = modules_get_agentmodule_id( @@ -1666,7 +1666,7 @@ function insert_downtime_agent($id_downtime, $user_groups_ad) ); } - if ($result !== false && (bool) $all_modules === false) { + if ($result !== false && ((bool) $all_modules === false || (bool) $all_modules === true)) { foreach ($module_names as $module_name) { $module = modules_get_agentmodule_id( $module_name, diff --git a/pandora_console/include/functions_planned_downtimes.php b/pandora_console/include/functions_planned_downtimes.php index e577f50e97..772611fa29 100644 --- a/pandora_console/include/functions_planned_downtimes.php +++ b/pandora_console/include/functions_planned_downtimes.php @@ -620,45 +620,33 @@ function planned_downtimes_stop($downtime) $count = 0; foreach ($agents as $agent) { - if ($agent['all_modules']) { + $modules = db_get_all_rows_filter( + 'tplanned_downtime_modules', + [ + 'id_agent' => $agent['id_agent'], + 'id_downtime' => $id_downtime, + ] + ); + if (empty($modules)) { + $modules = []; + } + + foreach ($modules as $module) { $result = db_process_sql_update( - 'tagente', - ['quiet' => 0], - ['id_agente' => $agent['id_agent']] + 'tagente_modulo', + [ + 'quiet' => 0, + 'quiet_by_downtime' => 0, + ], + [ + 'quiet_by_downtime' => 1, + 'id_agente_modulo' => $module['id_agent_module'], + ] ); if ($result) { $count++; } - } else { - $modules = db_get_all_rows_filter( - 'tplanned_downtime_modules', - [ - 'id_agent' => $agent['id_agent'], - 'id_downtime' => $id_downtime, - ] - ); - if (empty($modules)) { - $modules = []; - } - - foreach ($modules as $module) { - $result = db_process_sql_update( - 'tagente_modulo', - [ - 'quiet' => 0, - 'quiet_by_downtime' => 0, - ], - [ - 'quiet_by_downtime' => 1, - 'id_agente_modulo' => $module['id_agent_module'], - ] - ); - - if ($result) { - $count++; - } - } } } break; diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 89ae55f6c1..284f224023 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2660,30 +2660,23 @@ sub pandora_planned_downtime_set_quiet_elements($$$) { WHERE id_downtime = ' . $downtime_id); foreach my $downtime_agent (@downtime_agents) { - if ($downtime_agent->{'all_modules'}) { - db_do ($dbh, 'UPDATE tagente - SET quiet = 1 - WHERE id_agente = ?', $downtime_agent->{'id_agent'}); - } - else { - my @downtime_modules = get_db_rows($dbh, 'SELECT * + my @downtime_modules = get_db_rows($dbh, 'SELECT * FROM tplanned_downtime_modules WHERE id_agent = ' . $downtime_agent->{'id_agent'} . ' AND id_downtime = ' . $downtime_id); - foreach my $downtime_module (@downtime_modules) { - # If traversed module was already quiet, do not set quiet_by_downtime flag. - # quiet_by_downtime is used to avoid setting the module back to quiet=0 when downtime is over for those modules that were quiet before the downtime. - db_do ($dbh, 'UPDATE tagente_modulo - SET quiet_by_downtime = 1 - WHERE quiet = 0 && id_agente_modulo = ?', - $downtime_module->{'id_agent_module'}); + foreach my $downtime_module (@downtime_modules) { + # If traversed module was already quiet, do not set quiet_by_downtime flag. + # quiet_by_downtime is used to avoid setting the module back to quiet=0 when downtime is over for those modules that were quiet before the downtime. + db_do ($dbh, 'UPDATE tagente_modulo + SET quiet_by_downtime = 1 + WHERE quiet = 0 && id_agente_modulo = ?', + $downtime_module->{'id_agent_module'}); - db_do ($dbh, 'UPDATE tagente_modulo - SET quiet = 1 - WHERE id_agente_modulo = ?', - $downtime_module->{'id_agent_module'}); - } + db_do ($dbh, 'UPDATE tagente_modulo + SET quiet = 1 + WHERE id_agente_modulo = ?', + $downtime_module->{'id_agent_module'}); } } }