Fix issue with adding agents and modules
This commit is contained in:
parent
f2eee8fde8
commit
dc5a0eb5b9
|
@ -15,7 +15,7 @@
|
|||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
|
||||
* Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -70,7 +70,6 @@ ui_print_page_header(
|
|||
// Recursion group filter.
|
||||
$recursion = get_parameter('recursion', $_POST['recursion']);
|
||||
|
||||
|
||||
// Initialize data.
|
||||
$id_group = (int) get_parameter('id_group');
|
||||
$name = (string) get_parameter('name');
|
||||
|
@ -181,9 +180,15 @@ if ($insert_downtime_agent === 1) {
|
|||
__('This elements cannot be modified while the downtime is being executed')
|
||||
);
|
||||
} else {
|
||||
// If is selected 'Any', get all the agents.
|
||||
if (count($agents) === 1 && (int) $agents[0] === -2) {
|
||||
$all_agents = get_parameter('all_agents');
|
||||
$agents = explode(',', $all_agents);
|
||||
}
|
||||
|
||||
foreach ($agents as $agent_id) {
|
||||
// Check module belongs to the agent.
|
||||
if ($modules_selection_mode == 'all') {
|
||||
if ($modules_selection_mode == 'all' && $all_modules === false) {
|
||||
$check = false;
|
||||
foreach ($module_names as $module_name) {
|
||||
$check_module = modules_get_agentmodule_id(
|
||||
|
@ -896,33 +901,7 @@ if ($id_downtime > 0) {
|
|||
}
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT tagente.id_agente, tagente.alias
|
||||
FROM tagente
|
||||
WHERE tagente.id_agente NOT IN (
|
||||
SELECT tagente.id_agente
|
||||
FROM tagente, tplanned_downtime_agents
|
||||
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
|
||||
AND tplanned_downtime_agents.id_downtime = %d
|
||||
) AND disabled = 0 %s
|
||||
AND tagente.id_grupo IN (%s)
|
||||
ORDER BY tagente.nombre',
|
||||
$id_downtime,
|
||||
$filter_cond,
|
||||
$id_groups_str
|
||||
);
|
||||
$agents = db_get_all_rows_sql($sql);
|
||||
if (empty($agents)) {
|
||||
$agents = [];
|
||||
}
|
||||
|
||||
$agent_ids = extract_column($agents, 'id_agente');
|
||||
$agent_names = extract_column($agents, 'alias');
|
||||
|
||||
$agents = array_combine($agent_ids, $agent_names);
|
||||
if ($agents === false) {
|
||||
$agents = [];
|
||||
}
|
||||
$agents = get_planned_downtime_agents_list($id_downtime, $filter_cond, $id_groups_str);
|
||||
|
||||
$disabled_add_button = false;
|
||||
if (empty($agents) || $disabled_in_execution) {
|
||||
|
@ -940,7 +919,7 @@ if ($id_downtime > 0) {
|
|||
// Show available agents to include into downtime
|
||||
echo '<h4>'.__('Available agents').':</h4>';
|
||||
echo "<form method=post action='index.php?sec=extensions&sec2=godmode/agentes/planned_downtime.editor&insert_downtime_agent=1&id_downtime=$id_downtime'>";
|
||||
|
||||
html_print_input_hidden('all_agents', implode(',', array_keys($agents)));
|
||||
echo html_print_select($agents, 'id_agents[]', -1, '', _('Any'), -2, false, true, true, '', false, 'width: 180px;');
|
||||
|
||||
if ($type_downtime != 'quiet') {
|
||||
|
|
|
@ -3800,3 +3800,51 @@ function agents_get_last_status_change($id_agent)
|
|||
|
||||
return $row['last_status_change'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the list of agents for a planned downtime
|
||||
*
|
||||
* @param integer $id_downtime Id of planned downtime.
|
||||
* @param string $filter_cond String-based filters.
|
||||
* @param string $id_groups_str String-based list of id group, separated with commas.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_planned_downtime_agents_list($id_downtime, $filter_cond, $id_groups_str)
|
||||
{
|
||||
$agents = [];
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT tagente.id_agente, tagente.alias
|
||||
FROM tagente
|
||||
WHERE tagente.id_agente NOT IN (
|
||||
SELECT tagente.id_agente
|
||||
FROM tagente, tplanned_downtime_agents
|
||||
WHERE tplanned_downtime_agents.id_agent = tagente.id_agente
|
||||
AND tplanned_downtime_agents.id_downtime = %d
|
||||
) AND disabled = 0 %s
|
||||
AND tagente.id_grupo IN (%s)
|
||||
ORDER BY tagente.nombre',
|
||||
$id_downtime,
|
||||
$filter_cond,
|
||||
$id_groups_str
|
||||
);
|
||||
|
||||
$agents = db_get_all_rows_sql($sql);
|
||||
|
||||
if (empty($agents)) {
|
||||
$agents = [];
|
||||
}
|
||||
|
||||
$agent_ids = extract_column($agents, 'id_agente');
|
||||
$agent_names = extract_column($agents, 'alias');
|
||||
|
||||
$agents = array_combine($agent_ids, $agent_names);
|
||||
|
||||
if ($agents === false) {
|
||||
$agents = [];
|
||||
}
|
||||
|
||||
return $agents;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue