#11474 Fix metaconsole inventory

This commit is contained in:
miguel angel rasteu 2023-06-07 11:23:12 +02:00
parent eada3f7079
commit 0ca464846d
2 changed files with 127 additions and 118 deletions

View File

@ -744,6 +744,7 @@ function inventory_get_datatable(
if ($inventory_module_name[0] !== '0'
&& $inventory_module_name !== ''
&& $inventory_module_name !== 'all'
&& $inventory_module_name !== '0'
) {
array_push($where, "tmodule_inventory.name IN ('".implode("','", (array) $inventory_module_name)."')");
}
@ -807,7 +808,8 @@ function inventory_get_datatable(
}
foreach ($agent_data as $id_agent => $data_agent) {
$rows_tmp['agent'] = $data_agent['name_agent'];
$rows_tmp['agent'] = $data_agent[0]['name_agent'];
foreach ($data_agent as $key => $agent_row) {
$data_agent[$key]['timestamp'] = $agent_row['last_update_timestamp'];
$data_agent[$key]['utimestamp'] = $agent_row['last_update'];

View File

@ -150,6 +150,7 @@ if (is_ajax() === true) {
}
$id = !empty($agent['id_agente']) ? $agent['id_agente'] : $agent['id_agent'];
$id = !empty($id) ? $id : $agent['id_tagente'];
$tmp->alias .= $agent['alias'];
$ip = '<em>'.__('N/A').'</em>';
@ -329,7 +330,7 @@ $inventory_search_string = (string) get_parameter('search_string');
$order_by_agent = (bool) get_parameter('order_by_agent');
$export = (string) get_parameter('export');
$utimestamp = (int) get_parameter('utimestamp');
$submit_filter = (bool) get_parameter('submit_filter');
$submit_filter = (bool) get_parameter('srcbutton');
$pagination_url_parameters = [
'inventory_id_agent' => $inventory_id_agent,
@ -361,6 +362,7 @@ if ($is_metaconsole === true) {
if ($is_metaconsole === true) {
$nodo_image_url = $config['homeurl'].'/images/node.png';
if ($id_server > 0) {
// $agent_selected = io_safe_output($inventory_agent), true);
$connection = metaconsole_get_connection_by_id($id_server);
$agents_node = metaconsole_get_agents_servers($connection['server_name'], $inventory_id_group);
$node = metaconsole_get_servers($id_server);
@ -377,6 +379,7 @@ if ($is_metaconsole === true) {
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory';
if ($inventory_id_agent > 0) {
$sql .= ' AND id_agente = '.$inventory_id_agent;
$agents_node = [$inventory_id_agent => $inventory_id_agent];
}
$result_module = db_get_all_rows_sql($sql);
@ -422,10 +425,10 @@ if ($is_metaconsole === true) {
WHERE tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory';
if ($inventory_id_agent > 0) {
$sql .= ' AND id_agente = '.$inventory_id_agent;
$agents_node = [$inventory_id_agent => $inventory_id_agent];
}
$result = db_get_all_rows_sql($sql);
if ($result !== false) {
$result_module = array_merge($result_module, $result);
if ($submit_filter === true) {
@ -446,7 +449,6 @@ if ($is_metaconsole === true) {
$data_tmp['dbhost'] = $server['dbhost'];
$data_tmp['server_uid'] = $server['server_uid'];
$data_tmp['data'] = $rows_meta;
$nodos[$server['id']] = $data_tmp;
if ($result_data !== ERR_NODATA) {
$inventory_data .= $result_data;
@ -728,8 +730,8 @@ ui_toggle(
'white-box-content',
'box-flat white_table_graph fixed_filter_bar'
);
if (is_metaconsole() === true) {
/*
if (is_metaconsole() === true) {
$filteringFunction = 'active_inventory_submit()';
ui_print_info_message(['no_close' => true, 'message' => __('You must select at least one filter.'), 'force_class' => 'select_one_filter']);
?>
@ -750,10 +752,11 @@ if (is_metaconsole() === true) {
}
</script>
<?php
} else {
} else {
$filteringFunction = '';
}
}
*/
$filteringFunction = '';
if ($inventory_module !== 'basic') {
if (is_metaconsole() === true) {
if ($order_by_agent === true) {
@ -766,11 +769,11 @@ if ($inventory_module !== 'basic') {
foreach ($nodos as $nodo) {
$agents = '';
$data = [];
foreach ($nodo['data'] as $agent_rows) {
$modules = '';
foreach ($agent_rows['row'] as $row) {
$data = [];
foreach ($agent_rows['row'] as $key => $row) {
$columns = explode(';', io_safe_output($row['data_format']));
array_push($columns, 'Timestamp');
@ -793,66 +796,68 @@ if ($inventory_module !== 'basic') {
array_push($data, (object) $row_tmp);
}
}
$id_table = 'id_'.$row['id_module_inventory'].'_'.$nodo['server_uid'];
$table = ui_print_datatable(
[
'id' => $id_table,
'class' => 'info_table',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $columns,
'no_sortable_columns' => [],
'data_element' => $data,
'searching' => true,
'dom_elements' => 'lftipB',
'order' => [
'field' => $columns[0],
'direction' => 'asc',
],
'zeroRecords' => __('No inventory found'),
'emptyTable' => __('No inventory found'),
'return' => true,
'default_pagination' => 10,
'no_sortable_columns' => [-1],
]
);
$modules .= ui_toggle(
$table,
'<span class="title-blue">'.$row['name'].'</span>',
'',
'',
true,
true,
'',
'white-box-content w100p',
'box-shadow white_table_graph w100p',
'images/arrow_down_green.png',
'images/arrow_right_green.png',
false,
false,
false,
'',
'',
null,
null,
false,
$id_table
);
}
$agents .= ui_toggle(
$modules,
$agent_rows['agent'],
$id_table = 'id_'.$row['id_module_inventory'].'_'.$nodo['server_uid'];
$table = ui_print_datatable(
[
'id' => $id_table,
'class' => 'info_table w100p',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $columns,
'no_sortable_columns' => [],
'data_element' => $data,
'searching' => true,
'dom_elements' => 'ftip',
'order' => [
'field' => $columns[0],
'direction' => 'asc',
],
'zeroRecords' => __('No inventory found'),
'emptyTable' => __('No inventory found'),
'return' => true,
'default_pagination' => 10,
'no_sortable_columns' => [-1],
]
);
$modules .= ui_toggle(
$table,
'<span class="title-blue">'.$row['name'].'</span>',
'',
'',
true,
true
true,
'',
'white-box-content w100p',
'box-shadow white_table_graph w100p',
'images/arrow_down_green.png',
'images/arrow_right_green.png',
false,
false,
false,
'',
'',
null,
null,
false,
$id_table
);
}
$agents .= ui_toggle(
$modules,
$agent_rows['agent'],
'',
'',
true,
true,
'',
'white-box-content w100p',
'box-shadow white_table_graph w100p',
);
$node_name = $nodo['server_name'];
if ($count[$nodo['server_name']] > 1) {
$node_name .= ' ('.$nodo['dbhost'].')';
@ -877,12 +882,12 @@ if ($inventory_module !== 'basic') {
foreach ($nodos as $nodo_key => $nodo) {
$agents = '';
foreach ($nodo['data'] as $module_rows) {
$data = [];
foreach ($nodo['data'] as $module_key => $module_rows) {
$agent = '';
foreach ($module_rows as $row) {
$columns = explode(';', io_safe_output($row['data_format']));
array_push($columns, 'Timestamp');
$data = [];
$data_explode = explode(PHP_EOL, $row['data']);
foreach ($data_explode as $values) {
@ -903,67 +908,69 @@ if ($inventory_module !== 'basic') {
array_push($data, $data_tmp);
}
}
$id_table = 'id_'.$row['id_module_inventory'].'_'.$nodo['server_uid'];
$table = ui_print_datatable(
[
'id' => $id_table,
'class' => 'info_table',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $columns,
'no_sortable_columns' => [],
'data_element' => $data,
'searching' => true,
'dom_elements' => 'lftipB',
'order' => [
'field' => $columns[0],
'direction' => 'asc',
],
'zeroRecords' => __('No inventory found'),
'emptyTable' => __('No inventory found'),
'return' => true,
'default_pagination' => 10,
'no_sortable_columns' => [-1],
]
);
$agent .= ui_toggle(
$table,
'<span class="title-blue">'.$row['name_agent'].'</span>',
'',
'',
true,
true,
'',
'white-box-content w100p',
'box-shadow white_table_graph w100p',
'images/arrow_down_green.png',
'images/arrow_right_green.png',
false,
false,
false,
'',
'',
null,
null,
false,
$id_table
);
}
$agents .= ui_toggle(
$agent,
$module_rows[0]['name'],
$id_table = 'id_'.$row['id_module_inventory'].'_'.$nodo['server_uid'];
$table = ui_print_datatable(
[
'id' => $id_table,
'class' => 'info_table w100p',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $columns,
'no_sortable_columns' => [],
'data_element' => $data,
'searching' => true,
'dom_elements' => 'ftip',
'order' => [
'field' => $columns[0],
'direction' => 'asc',
],
'zeroRecords' => __('No inventory found'),
'emptyTable' => __('No inventory found'),
'return' => true,
'default_pagination' => 10,
'no_sortable_columns' => [-1],
]
);
$agent .= ui_toggle(
$table,
'<span class="title-blue">'.$row['name_agent'].'</span>',
'',
'',
true,
true
true,
'',
'white-box-content w100p',
'box-shadow white_table_graph w100p',
'images/arrow_down_green.png',
'images/arrow_right_green.png',
false,
false,
false,
'',
'',
null,
null,
false,
$id_table
);
}
$agents .= ui_toggle(
$agent,
$module_key,
'',
'',
true,
true,
'',
'white-box-content w100p',
'box-shadow white_table_graph w100p',
);
$node_name = $nodo['server_name'];
if ($count[$nodo['server_name']] > 1) {
$node_name .= ' ('.$nodo['dbhost'].')';