Merge branch 'ent-6833-planned-downtimes-any-no-funciona' into 'develop'
Fix issue with adding agents and modules Closes pandora_enterprise#6833 See merge request artica/pandorafms!3723
This commit is contained in:
commit
b2ed2f5511
|
@ -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');
|
||||
|
@ -180,7 +179,12 @@ if ($insert_downtime_agent === 1) {
|
|||
$agents = (array) get_parameter('id_agents');
|
||||
$module_names = (array) get_parameter('module');
|
||||
|
||||
$all_modules = (empty($module_names) || ($module_names[0] === '0'));
|
||||
$all_modules = ($modules_selection_mode === 'all' && (empty($module_names) || (int) $modules[0] === 0));
|
||||
$all_common_modules = ($modules_selection_mode === 'common' && (empty($module_names) || (int) $modules[0] === 0));
|
||||
|
||||
if ($all_common_modules === true) {
|
||||
$module_names = explode(',', get_parameter('all_common_modules'));
|
||||
}
|
||||
|
||||
// 'Is running' check.
|
||||
$is_running = (bool) db_get_value(
|
||||
|
@ -194,9 +198,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(
|
||||
|
@ -918,33 +928,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) {
|
||||
|
@ -962,7 +946,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') {
|
||||
|
@ -971,6 +955,7 @@ if ($id_downtime > 0) {
|
|||
echo '<div id="available_modules_selection_mode" style="padding-top:20px">';
|
||||
}
|
||||
|
||||
html_print_input_hidden('all_common_modules', '');
|
||||
echo html_print_select(
|
||||
[
|
||||
'common' => __('Show common modules'),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -275,7 +275,10 @@ function agent_changed_by_multiple_agents(event, id_agent, selected) {
|
|||
);
|
||||
}
|
||||
}
|
||||
jQuery.each(data, function(i, val) {
|
||||
|
||||
var all_common_modules = [];
|
||||
|
||||
$.each(data, function(i, val) {
|
||||
var s = js_html_entity_decode(val);
|
||||
|
||||
$("#module").append(
|
||||
|
@ -285,8 +288,12 @@ function agent_changed_by_multiple_agents(event, id_agent, selected) {
|
|||
.attr("title", s)
|
||||
);
|
||||
|
||||
all_common_modules.push(i);
|
||||
$("#module").fadeIn("normal");
|
||||
});
|
||||
|
||||
$("#hidden-all_common_modules").val(all_common_modules.toString());
|
||||
|
||||
if (typeof selected !== "undefined") $("#module").attr("value", selected);
|
||||
|
||||
$("#module")
|
||||
|
|
Loading…
Reference in New Issue