mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Merge branch 'ent-9392-no-funciona-insertar-agentes-en-paradas-planificadas' into 'develop'
Fix planned downtime issues Ref: pandora_enterprise#9392 See merge request artica/pandorafms!5166
This commit is contained in:
commit
aaedb39849
@ -1104,11 +1104,7 @@ $table->data[1][0] = __('Available agents');
|
|||||||
$table->data[1][1] = html_print_select($agents, 'id_agents[]', -1, '', _('Any'), -2, true, true, true, '', false, 'min-width: 250px;width: 70%;');
|
$table->data[1][1] = html_print_select($agents, 'id_agents[]', -1, '', _('Any'), -2, true, true, true, '', false, 'min-width: 250px;width: 70%;');
|
||||||
|
|
||||||
|
|
||||||
if ($type_downtime != 'quiet') {
|
$table->rowid[2] = 'available_modules_selection_mode';
|
||||||
echo '<div id="available_modules_selection_mode" style="padding-top:20px;display: none;">';
|
|
||||||
} else {
|
|
||||||
echo '<div id="available_modules_selection_mode" style="padding-top:20px">';
|
|
||||||
}
|
|
||||||
|
|
||||||
$table->data[2][1] = html_print_select(
|
$table->data[2][1] = html_print_select(
|
||||||
[
|
[
|
||||||
@ -1128,19 +1124,13 @@ $table->data[2][1] = html_print_select(
|
|||||||
'min-width:180px;'
|
'min-width:180px;'
|
||||||
);
|
);
|
||||||
|
|
||||||
echo '</div>';
|
|
||||||
|
|
||||||
|
$table->rowid[3] = 'available_modules';
|
||||||
$table->data[3][0] = __('Available modules:').ui_print_help_tip(
|
$table->data[3][0] = __('Available modules:').ui_print_help_tip(
|
||||||
__('Only for type Quiet for downtimes.'),
|
__('Only for type Quiet for downtimes.'),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($type_downtime != 'quiet') {
|
|
||||||
echo '<div id="available_modules" style="display: none;">';
|
|
||||||
} else {
|
|
||||||
echo '<div id="available_modules" style="">';
|
|
||||||
}
|
|
||||||
|
|
||||||
$table->data[3][1] = html_print_select(
|
$table->data[3][1] = html_print_select(
|
||||||
[],
|
[],
|
||||||
'module[]',
|
'module[]',
|
||||||
@ -1155,7 +1145,6 @@ $table->data[3][1] = html_print_select(
|
|||||||
false,
|
false,
|
||||||
'min-width: 250px;width: 70%;'
|
'min-width: 250px;width: 70%;'
|
||||||
);
|
);
|
||||||
echo '</div>';
|
|
||||||
|
|
||||||
// Print agent table.
|
// Print agent table.
|
||||||
html_print_table($table);
|
html_print_table($table);
|
||||||
@ -1184,7 +1173,6 @@ if ($id_downtime > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
html_print_input_hidden('all_agents', implode(',', array_keys($agents)));
|
|
||||||
html_print_input_hidden('all_common_modules', '');
|
html_print_input_hidden('all_common_modules', '');
|
||||||
echo '</form>';
|
echo '</form>';
|
||||||
|
|
||||||
@ -1405,12 +1393,19 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$agents = (array) get_parameter('id_agents');
|
$agents = (array) get_parameter('id_agents');
|
||||||
|
$filter_group = (int) get_parameter('filter_group', 0);
|
||||||
$module_names = (array) get_parameter('module');
|
$module_names = (array) get_parameter('module');
|
||||||
$modules_selection_mode = (string) get_parameter('modules_selection_mode');
|
$modules_selection_mode = (string) get_parameter('modules_selection_mode');
|
||||||
|
$type_downtime = (string) get_parameter('type_downtime', 'quiet');
|
||||||
|
$recursion = (bool) get_parameter_checkbox('recursion', false);
|
||||||
|
|
||||||
$all_modules = ($modules_selection_mode === 'all' && (empty($module_names) || (string) $module_names[0] === '0'));
|
$all_modules = ($modules_selection_mode === 'all' && (empty($module_names) || (string) $module_names[0] === '0'));
|
||||||
$all_common_modules = ($modules_selection_mode === 'common' && (empty($module_names) || (string) $module_names[0] === '0'));
|
$all_common_modules = ($modules_selection_mode === 'common' && (empty($module_names) || (string) $module_names[0] === '0'));
|
||||||
|
|
||||||
|
if ($type_downtime === 'disable_agents') {
|
||||||
|
$all_modules = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($all_common_modules === true) {
|
if ($all_common_modules === true) {
|
||||||
$module_names = explode(',', get_parameter('all_common_modules'));
|
$module_names = explode(',', get_parameter('all_common_modules'));
|
||||||
}
|
}
|
||||||
@ -1429,11 +1424,33 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
} else {
|
} else {
|
||||||
// If is selected 'Any', get all the agents.
|
// If is selected 'Any', get all the agents.
|
||||||
if (count($agents) === 1 && (int) $agents[0] === -2) {
|
if (count($agents) === 1 && (int) $agents[0] === -2) {
|
||||||
$all_agents = get_parameter('all_agents');
|
if ($recursion === true) {
|
||||||
$agents = explode(',', $all_agents);
|
$filter_group = groups_get_children_ids(
|
||||||
|
$filter_group,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
'AW'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
$agents = db_get_all_rows_filter(
|
||||||
|
'tagente',
|
||||||
|
['id_grupo' => $filter_group],
|
||||||
|
'id_agente'
|
||||||
|
);
|
||||||
|
|
||||||
|
$agents = array_reduce(
|
||||||
|
$agents,
|
||||||
|
function ($carry, $item) {
|
||||||
|
$carry[] = $item['id_agente'];
|
||||||
|
|
||||||
|
return $carry;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($agents as $agent_id) {
|
foreach ($agents as $agent_id) {
|
||||||
|
$agent_id = (int) $agent_id;
|
||||||
// Check module belongs to the agent.
|
// Check module belongs to the agent.
|
||||||
if ($modules_selection_mode == 'all' && $all_modules === false) {
|
if ($modules_selection_mode == 'all' && $all_modules === false) {
|
||||||
$check = false;
|
$check = false;
|
||||||
@ -1466,17 +1483,40 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = [
|
// Check if agent is already in downtime.
|
||||||
'id_downtime' => $id_downtime,
|
$agent_in_downtime = db_get_value_filter(
|
||||||
'id_agent' => $agent_id,
|
'id_downtime',
|
||||||
'all_modules' => $all_modules,
|
|
||||||
];
|
|
||||||
$result = db_process_sql_insert(
|
|
||||||
'tplanned_downtime_agents',
|
'tplanned_downtime_agents',
|
||||||
$values
|
[
|
||||||
|
'id_agent' => $agent_id,
|
||||||
|
'id_downtime' => $id_downtime,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($result && !$all_modules) {
|
if ($agent_in_downtime !== false) {
|
||||||
|
$values = ['all_modules' => $all_modules];
|
||||||
|
|
||||||
|
$result = db_process_sql_update(
|
||||||
|
'tplanned_downtime_agents',
|
||||||
|
$values,
|
||||||
|
[
|
||||||
|
'id_downtime' => $id_downtime,
|
||||||
|
'id_agent' => $agent_id,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$values = [
|
||||||
|
'id_downtime' => $id_downtime,
|
||||||
|
'id_agent' => $agent_id,
|
||||||
|
'all_modules' => $all_modules,
|
||||||
|
];
|
||||||
|
$result = db_process_sql_insert(
|
||||||
|
'tplanned_downtime_agents',
|
||||||
|
$values
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result !== false && (bool) $all_modules === false) {
|
||||||
foreach ($module_names as $module_name) {
|
foreach ($module_names as $module_name) {
|
||||||
$module = modules_get_agentmodule_id(
|
$module = modules_get_agentmodule_id(
|
||||||
$module_name,
|
$module_name,
|
||||||
@ -1487,17 +1527,32 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = [
|
// Check if modules are already in downtime.
|
||||||
'id_downtime' => $id_downtime,
|
$module_in_downtime = db_get_value_filter(
|
||||||
'id_agent' => $agent_id,
|
'id_downtime',
|
||||||
'id_agent_module' => $module['id_agente_modulo'],
|
|
||||||
];
|
|
||||||
$result = db_process_sql_insert(
|
|
||||||
'tplanned_downtime_modules',
|
'tplanned_downtime_modules',
|
||||||
$values
|
[
|
||||||
|
'id_downtime' => $id_downtime,
|
||||||
|
'id_agent' => $agent_id,
|
||||||
|
'id_agent_module' => $module['id_agente_modulo'],
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($result) {
|
if ($module_in_downtime !== false) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
$values = [
|
||||||
|
'id_downtime' => $id_downtime,
|
||||||
|
'id_agent' => $agent_id,
|
||||||
|
'id_agent_module' => $module['id_agente_modulo'],
|
||||||
|
];
|
||||||
|
$result = db_process_sql_insert(
|
||||||
|
'tplanned_downtime_modules',
|
||||||
|
$values
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result !== false) {
|
||||||
$values = ['id_user' => $config['id_user']];
|
$values = ['id_user' => $config['id_user']];
|
||||||
$result = db_process_sql_update(
|
$result = db_process_sql_update(
|
||||||
'tplanned_downtime',
|
'tplanned_downtime',
|
||||||
@ -1526,6 +1581,7 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
$("#available_modules_selection_mode").hide();
|
$("#available_modules_selection_mode").hide();
|
||||||
break;
|
break;
|
||||||
case 'quiet':
|
case 'quiet':
|
||||||
|
case 'disable_agent_modules':
|
||||||
$("#available_modules_selection_mode").show();
|
$("#available_modules_selection_mode").show();
|
||||||
$("#available_modules").show();
|
$("#available_modules").show();
|
||||||
break;
|
break;
|
||||||
@ -1840,7 +1896,6 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
$('input.hasDatepicker[readonly]').disable();
|
$('input.hasDatepicker[readonly]').disable();
|
||||||
|
|
||||||
$("#checkbox-recursion").click(function() {
|
$("#checkbox-recursion").click(function() {
|
||||||
recursion = this.checked;
|
|
||||||
$("#filter_group").trigger("change");
|
$("#filter_group").trigger("change");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1850,6 +1905,7 @@ function insert_downtime_agent($id_downtime, $user_groups_ad)
|
|||||||
});
|
});
|
||||||
|
|
||||||
function populate_agents_selector() {
|
function populate_agents_selector() {
|
||||||
|
recursion = $("#checkbox-recursion").prop('checked');
|
||||||
jQuery.post ("ajax.php",
|
jQuery.post ("ajax.php",
|
||||||
{"page": "operation/agentes/ver_agente",
|
{"page": "operation/agentes/ver_agente",
|
||||||
"get_agents_group_json": 1,
|
"get_agents_group_json": 1,
|
||||||
|
@ -137,12 +137,49 @@ if (is_ajax() === true) {
|
|||||||
'filters' => get_parameter('filter', []),
|
'filters' => get_parameter('filter', []),
|
||||||
];
|
];
|
||||||
|
|
||||||
$modules = get_agents_modules_planned_dowtime($id, $options);
|
$type_downtime = db_get_value_filter(
|
||||||
|
'type_downtime',
|
||||||
|
'tplanned_downtime',
|
||||||
|
['id' => $id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($type_downtime === 'disable_agents') {
|
||||||
|
$sql = sprintf(
|
||||||
|
'SELECT ta.alias as agent_name
|
||||||
|
FROM tplanned_downtime_agents tpa JOIN tagente ta
|
||||||
|
ON tpa.id_agent = ta.id_agente
|
||||||
|
WHERE tpa.id_downtime = %d',
|
||||||
|
$id
|
||||||
|
);
|
||||||
|
$data = db_get_all_rows_sql($sql);
|
||||||
|
|
||||||
|
if (empty($data) === false) {
|
||||||
|
$data = array_reduce(
|
||||||
|
$data,
|
||||||
|
function ($carry, $item) {
|
||||||
|
global $config;
|
||||||
|
// Transforms array of arrays $data into an array
|
||||||
|
// of objects, making a post-process of certain fields.
|
||||||
|
$tmp = (object) $item;
|
||||||
|
|
||||||
|
$tmp->agent_name = io_safe_output($item['agent_name']);
|
||||||
|
$tmp->module_name = __('All modules');
|
||||||
|
|
||||||
|
$carry[] = $tmp;
|
||||||
|
return $carry;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$data = get_agents_modules_planned_dowtime($id, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$count = get_agents_modules_planned_dowtime($id, $options, $count);
|
$count = get_agents_modules_planned_dowtime($id, $options, $count);
|
||||||
|
|
||||||
echo json_encode(
|
echo json_encode(
|
||||||
[
|
[
|
||||||
'data' => $modules,
|
'data' => $data,
|
||||||
'recordsTotal' => $count[0]['total'],
|
'recordsTotal' => $count[0]['total'],
|
||||||
'recordsFiltered' => $count[0]['total'],
|
'recordsFiltered' => $count[0]['total'],
|
||||||
]
|
]
|
||||||
|
@ -196,6 +196,13 @@ function agent_changed_by_multiple_agents(event, id_agent, selected) {
|
|||||||
serialized = "";
|
serialized = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var id_group = null;
|
||||||
|
if (typeof $("#filter_group") !== "undefined") {
|
||||||
|
try {
|
||||||
|
id_group = $("#filter_group").val();
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
|
||||||
$("#module")
|
$("#module")
|
||||||
.prop("disabled", true)
|
.prop("disabled", true)
|
||||||
.empty()
|
.empty()
|
||||||
@ -238,7 +245,8 @@ function agent_changed_by_multiple_agents(event, id_agent, selected) {
|
|||||||
selection_mode: selection_mode,
|
selection_mode: selection_mode,
|
||||||
serialized: serialized,
|
serialized: serialized,
|
||||||
id_server: id_server,
|
id_server: id_server,
|
||||||
status_module: module_status
|
status_module: module_status,
|
||||||
|
id_group: id_group
|
||||||
},
|
},
|
||||||
function(data) {
|
function(data) {
|
||||||
$("#module").empty();
|
$("#module").empty();
|
||||||
@ -575,7 +583,8 @@ function module_changed_by_multiple_modules(event, id_module, selected) {
|
|||||||
status_module: status_module,
|
status_module: status_module,
|
||||||
"module_name[]": idModules,
|
"module_name[]": idModules,
|
||||||
selection_mode: selection_mode,
|
selection_mode: selection_mode,
|
||||||
tags: tags_selected
|
tags: tags_selected,
|
||||||
|
id_group: id_group
|
||||||
},
|
},
|
||||||
function(data) {
|
function(data) {
|
||||||
$("#agents").append(
|
$("#agents").append(
|
||||||
|
@ -480,6 +480,7 @@ if (is_ajax()) {
|
|||||||
$serialized = get_parameter('serialized', '');
|
$serialized = get_parameter('serialized', '');
|
||||||
$id_server = (int) get_parameter('id_server', 0);
|
$id_server = (int) get_parameter('id_server', 0);
|
||||||
$status_modulo = (int) get_parameter('status_module', -1);
|
$status_modulo = (int) get_parameter('status_module', -1);
|
||||||
|
$id_group_selected = (int) get_parameter('id_group', 0);
|
||||||
$metaconsole_server_name = null;
|
$metaconsole_server_name = null;
|
||||||
if (!empty($id_server)) {
|
if (!empty($id_server)) {
|
||||||
$metaconsole_server_name = db_get_value(
|
$metaconsole_server_name = db_get_value(
|
||||||
@ -707,14 +708,18 @@ if (is_ajax()) {
|
|||||||
// Get all user's groups.
|
// Get all user's groups.
|
||||||
$id_group = array_keys(users_get_groups($config['id_user']));
|
$id_group = array_keys(users_get_groups($config['id_user']));
|
||||||
|
|
||||||
if (is_array($id_group)) {
|
if (is_array($id_group) && empty($id_group_selected) === true) {
|
||||||
$id_group = implode(',', $id_group);
|
$id_group = implode(',', $id_group);
|
||||||
|
} else {
|
||||||
|
if (in_array($id_group_selected, $id_group) === true) {
|
||||||
|
$id_group = $id_group_selected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$where_tags .= ' AND tagente.id_grupo IN ('.$id_group.')';
|
$where_tags .= ' AND tagente.id_grupo IN ('.$id_group.')';
|
||||||
|
|
||||||
if ($selection_mode == 'common') {
|
if ($selection_mode == 'common') {
|
||||||
$sql_agent_total = 'SELECT count(*) FROM tagente WHERE disabled=0';
|
$sql_agent_total = 'SELECT count(*) FROM tagente WHERE disabled=0'.$where_tags;
|
||||||
$agent_total = db_get_value_sql($sql_agent_total);
|
$agent_total = db_get_value_sql($sql_agent_total);
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
"SELECT t1.nombre, t1.id_agente_modulo FROM tagente_modulo t1
|
"SELECT t1.nombre, t1.id_agente_modulo FROM tagente_modulo t1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user