From bade6328f9ce9440a65e6ac420635dfc25fbbb55 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 4 Apr 2024 16:52:34 +0200 Subject: [PATCH 1/4] #13331 added filter status in inventory and fixed date --- .../include/functions_inventory.php | 6 +++++ .../operation/inventory/inventory.php | 22 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 5f9e3bd62d..376e3c9837 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -890,6 +890,12 @@ function get_data_basic_info_sql($params, $count=false) $where .= sprintf(' AND %s.id_agente = %d', $table, $params['id_agent']); } + if ($params['status'] >= 0 && $count === true) { + $where .= sprintf(' AND disabled = %d', $params['status']); + } else if ($params['status'] >= 0 && $count === false) { + $where .= sprintf(' AND %s.disabled = %d', $table, $params['status']); + } + if ($params['id_group'] > 0) { $where .= sprintf(' AND id_grupo = %d', $params['id_group']); } else { diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index 5f812f67e9..6b569289a3 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -91,6 +91,7 @@ if ($custom_date === '1') { $date_init = strtotime($date_init); $utimestamp = strtotime($date_end); +$status_agent = (int) get_parameter('status', -1); if (is_ajax() === true) { $get_csv_url = (bool) get_parameter('get_csv_url'); @@ -192,8 +193,9 @@ if (is_ajax() === true) { 'order' => $order, 'id_agent' => $id_agent, 'id_group' => $id_group, - 'utimestamp' => strtotime($utimestamp), + 'utimestamp' => $utimestamp, 'period' => $period, + 'status' => $status_agent, ]; $data = get_data_basic_info_sql($params); @@ -764,6 +766,23 @@ if (is_metaconsole() === false) { ); } +$table->data[2][0] = html_print_label_input_block( + __('Status agent'), + html_print_select( + [ + -1 => __('All'), + 0 => __('Enabled'), + 1 => __('Disabled'), + ], + 'status', + $status_agent, + '', + '', + 0, + true + ) +); + $searchForm .= html_print_table($table, true); $searchForm .= html_print_div( [ @@ -1355,6 +1374,7 @@ if ($inventory_module !== 'basic') { 'id_agent' => $id_agente, 'id_group' => $inventory_id_group, 'search' => $search, + 'status' => $status_agent, ], 'zeroRecords' => __('Agent info not found'), 'emptyTable' => __('Agent info not found'), From 915a7b95aee2f31a7bb6ad87c729fdd8936a9da0 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 4 Apr 2024 17:21:52 +0200 Subject: [PATCH 2/4] #13331 fixed date filter --- .../include/functions_inventory.php | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 376e3c9837..932b1c23d7 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -884,15 +884,11 @@ function get_data_basic_info_sql($params, $count=false) } $where = 'WHERE 1=1 '; - if ($params['id_agent'] > 0 && $count === true) { - $where .= sprintf(' AND id_agente = %d', $params['id_agent']); - } else if ($params['id_agent'] > 0 && $count === false) { + if ($params['id_agent'] > 0) { $where .= sprintf(' AND %s.id_agente = %d', $table, $params['id_agent']); } - if ($params['status'] >= 0 && $count === true) { - $where .= sprintf(' AND disabled = %d', $params['status']); - } else if ($params['status'] >= 0 && $count === false) { + if ($params['status'] >= 0) { $where .= sprintf(' AND %s.disabled = %d', $table, $params['status']); } @@ -916,7 +912,7 @@ function get_data_basic_info_sql($params, $count=false) ); } - if ($params['utimestamp'] > 0 && $count === false) { + if ($params['utimestamp'] > 0) { $where .= sprintf( ' AND utimestamp BETWEEN %d AND %d', ($params['utimestamp'] - $params['period']), @@ -983,21 +979,20 @@ function get_data_basic_info_sql($params, $count=false) $limit_condition = ''; $order_condition = ''; - $fields = 'count(*)'; $innerjoin = ''; $groupby = ''; - if ($count !== true) { - if (is_metaconsole() === true) { - $fields = 'tmetaconsole_agent.*, tagent_secondary_group.*, tagent_custom_data.*'; - } else { - $fields = 'tagente.*, tagent_secondary_group.*, tagent_custom_data.*'; - } + if (is_metaconsole() === true) { + $fields = 'tmetaconsole_agent.*, tagent_secondary_group.*, tagent_custom_data.*'; + } else { + $fields = 'tagente.*, tagent_secondary_group.*, tagent_custom_data.*'; + } - $innerjoin = 'LEFT JOIN tagente_estado ON '.$table.'.id_agente = tagente_estado.id_agente '; - $innerjoin .= 'LEFT JOIN tagent_secondary_group ON '.$table.'.id_agente = tagent_secondary_group.id_agent '; - $innerjoin .= 'LEFT JOIN tagent_custom_data ON '.$table.'.id_agente = tagent_custom_data.id_agent '; - $groupby = 'GROUP BY '.$table.'.id_agente'; + $innerjoin = 'LEFT JOIN tagente_estado ON '.$table.'.id_agente = tagente_estado.id_agente '; + $innerjoin .= 'LEFT JOIN tagent_secondary_group ON '.$table.'.id_agente = tagent_secondary_group.id_agent '; + $innerjoin .= 'LEFT JOIN tagent_custom_data ON '.$table.'.id_agente = tagent_custom_data.id_agent '; + + if ($count !== true) { $limit_condition = sprintf( 'LIMIT %d, %d', $params['start'], @@ -1005,8 +1000,12 @@ function get_data_basic_info_sql($params, $count=false) ); $order_condition = sprintf('ORDER BY %s', $params['order']); + } else { + $fields = 'COUNT(*)'; } + $groupby = 'GROUP BY '.$table.'.id_agente'; + $sql = sprintf( 'SELECT %s FROM %s @@ -1024,13 +1023,19 @@ function get_data_basic_info_sql($params, $count=false) $limit_condition ); + $sql_count = sprintf( + 'SELECT COUNT(*) + FROM (%s) AS sub_sql', + $sql + ); + if ($count !== true) { $result = db_get_all_rows_sql($sql); if ($result === false) { $result = []; } } else { - $result = db_get_sql($sql); + $result = db_get_sql($sql_count); if ($result === false) { $result = 0; } From 6a3c9024e134e1916c00ab5aa896d641eff90e99 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 4 Apr 2024 18:54:36 +0200 Subject: [PATCH 3/4] #13331 fixed filter in inventory --- .../include/functions_inventory.php | 19 ++++++++------ .../operation/inventory/inventory.php | 26 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 932b1c23d7..dbf58e79f0 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -710,7 +710,8 @@ function inventory_get_datatable( $inventory_search_string='', $export_csv=false, $return_mode=false, - $order_by_agent=false + $order_by_agent=false, + $date_init=false, ) { global $config; @@ -750,21 +751,23 @@ function inventory_get_datatable( } if ($utimestamp > 0) { - array_push($where, 'tagente_datos_inventory.utimestamp <= '.$utimestamp.' '); + array_push($where, 'tagent_module_inventory.utimestamp <= '.$utimestamp.' '); + } + + if ($date_init !== false) { + array_push($where, 'tagent_module_inventory.utimestamp >= '.$date_init.' '); } $sql = sprintf( 'SELECT tmodule_inventory.*, tagent_module_inventory.*, tagente.alias as name_agent, - tagente_datos_inventory.utimestamp as last_update, - tagente_datos_inventory.timestamp as last_update_timestamp, - tagente_datos_inventory.data as data_inventory + tagent_module_inventory.utimestamp as last_update, + tagent_module_inventory.timestamp as last_update_timestamp, + tagent_module_inventory.data as data_inventory FROM tmodule_inventory - INNER JOIN tagent_module_inventory + LEFT JOIN tagent_module_inventory ON tmodule_inventory.id_module_inventory = tagent_module_inventory.id_module_inventory - INNER JOIN tagente_datos_inventory - ON tagent_module_inventory.id_agent_module_inventory = tagente_datos_inventory.id_agent_module_inventory LEFT JOIN tagente ON tagente.id_agente = tagent_module_inventory.id_agente diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index 6b569289a3..b6e53403a0 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -451,6 +451,8 @@ if ($is_metaconsole === true) { if ($inventory_id_agent > 0) { $sql .= ' AND id_agente = '.$inventory_id_agent; $agents_node = [$inventory_id_agent => $inventory_id_agent]; + } else { + $agents_node = [-1 => true]; } $result_module = db_get_all_rows_sql($sql); @@ -464,8 +466,7 @@ if ($is_metaconsole === true) { $export, false, $order_by_agent, - $server, - $pagination_url_parameters + $date_init ); $data_tmp['server_name'] = $connection['server_name']; @@ -497,6 +498,8 @@ if ($is_metaconsole === true) { if ($inventory_id_agent > 0) { $sql .= ' AND id_agente = '.$inventory_id_agent; $agents_node = [$inventory_id_agent => $inventory_id_agent]; + } else { + $agents_node = [-1 => true]; } $result = db_get_all_rows_sql($sql); @@ -512,8 +515,7 @@ if ($is_metaconsole === true) { $export, false, $order_by_agent, - $server, - $pagination_url_parameters + $date_init ); $data_tmp['server_name'] = $server['server_name']; @@ -1073,12 +1075,17 @@ if ($inventory_module !== 'basic') { } } } else { - // Single agent selected. - if ($inventory_id_agent > 0 && isset($agents[$inventory_id_agent]) === true) { - $agents = [$inventory_id_agent => $agents[$inventory_id_agent]]; + if ($inventory_id_agent > 0) { + // Single agent selected. + if ($inventory_id_agent > 0 && isset($agents[$inventory_id_agent]) === true) { + $agents = [$inventory_id_agent => $agents[$inventory_id_agent]]; + } + + $agents_ids = array_keys($agents); + } else { + $agents_ids = [-1]; } - $agents_ids = array_keys($agents); if (count($agents_ids) > 0) { $rows = inventory_get_datatable( $agents_ids, @@ -1087,7 +1094,8 @@ if ($inventory_module !== 'basic') { $inventory_search_string, $export, false, - $order_by_agent + $order_by_agent, + $date_init ); } From 68a53b8a5723e7ef0ddd96b4565fc2be546cb4c9 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 4 Apr 2024 19:19:50 +0200 Subject: [PATCH 4/4] #13331 added status filter in datatables inventory --- pandora_console/include/functions_inventory.php | 5 +++++ pandora_console/operation/inventory/inventory.php | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index dbf58e79f0..a6fc8b248d 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -712,6 +712,7 @@ function inventory_get_datatable( $return_mode=false, $order_by_agent=false, $date_init=false, + $status_agent=-1, ) { global $config; @@ -738,6 +739,10 @@ function inventory_get_datatable( array_push($where, 'tagent_module_inventory.id_agente IN ('.implode(',', $agents_ids).')'); } + if ($status_agent > -1) { + array_push($where, 'tagente.disabled ='.$status_agent); + } + if ($inventory_module_name[0] !== '0' && $inventory_module_name !== '' && $inventory_module_name !== 'all' diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index b6e53403a0..950326a9fc 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -466,7 +466,8 @@ if ($is_metaconsole === true) { $export, false, $order_by_agent, - $date_init + $date_init, + $status_agent ); $data_tmp['server_name'] = $connection['server_name']; @@ -515,7 +516,8 @@ if ($is_metaconsole === true) { $export, false, $order_by_agent, - $date_init + $date_init, + $status_agent ); $data_tmp['server_name'] = $server['server_name']; @@ -1095,7 +1097,8 @@ if ($inventory_module !== 'basic') { $export, false, $order_by_agent, - $date_init + $date_init, + $status_agent ); }