Merge branch 'ent-11873-paradas-planificadas-de-modulos-ponen-en-modo-quiet-agente-en-vez-de-modulos' into 'develop'

Ent 11873 paradas planificadas de modulos ponen en modo quiet agente en vez de modulos

See merge request artica/pandorafms!6345
This commit is contained in:
Matias Didier 2023-08-24 08:43:28 +00:00
commit 9e747e9952
3 changed files with 36 additions and 55 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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'});
}
}
}