diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index c7dd995dbe..16db89b622 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -62,6 +62,20 @@ $show_sort_options = []; $show_sort_options[1] = __('Ascending'); $show_sort_options[2] = __('Descending'); +// Agents inventory display options. +$agents_inventory_display_options = []; +$agents_inventory_display_options['alias'] = __('Alias'); +$agents_inventory_display_options['direccion'] = __('IP'); +$agents_inventory_display_options['id_os'] = __('OS'); +$agents_inventory_display_options['id_grupo'] = __('Group'); +$agents_inventory_display_options['secondary_groups'] = __('Secondary groups'); +$agents_inventory_display_options['comentarios'] = __('Description'); +$agents_inventory_display_options['url_address'] = __('URL'); +$agents_inventory_display_options['custom_fields'] = __('Custom fields'); +$agents_inventory_display_options['estado'] = __('Status'); +$agents_inventory_display_options['agent_version'] = __('Version'); +$agents_inventory_display_options['remote'] = __('Remote configuration'); + enterprise_include('/godmode/reporting/reporting_builder.item_editor.php'); require_once $config['homedir'].'/include/functions_agents.php'; if (enterprise_include_once('include/functions_metaconsole.php')) { @@ -725,6 +739,26 @@ switch ($action) { $idAgentModule = $module; break; + case 'agents_inventory': + + + + $description = $item['description']; + $es = json_decode($item['external_source'], true); + // hd($es); + $date = $es['date']; + $selected_agent_group_filter = $es['agent_group_filter']; + $selected_agents_inventory_display_options = $es['agents_inventory_display_options']; + $selected_agent_os_filter = $es['agent_os_filter']; + $selected_agent_custom_field_filter = $es['agent_custom_field_filter']; + $selected_agent_status_filter = $es['agent_status_filter']; + $selected_agent_module_search_filter = $es['agent_module_search_filter']; + $selected_agent_version_filter = $es['agent_version_filter']; + + $idAgent = $es['id_agents']; + $idAgentModule = $inventory_modules; + break; + case 'inventory': $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -3020,18 +3054,64 @@ $class = 'databox filters'; + + + + + + + + + + + + + + + + + + @@ -3082,8 +3162,8 @@ $class = 'databox filters'; html_print_select( $fields, - 'users_groups[]', - [], + 'agent_status_filter', + $selected_agent_status_filter, '', false, '', @@ -3101,14 +3181,14 @@ $class = 'databox filters'; $value) { + if (array_search('secondary_groups', $es_agents_inventory_display_options) !== false) { + $sql_agent_sec_group = sprintf( + 'SELECT id_group + FROM tagent_secondary_group + WHERE id_agent = %d', + $value['id_agente'] + ); + + $agent_secondary_groups = []; + $agent_secondary_groups = db_get_all_rows_sql($sql_agent_sec_group); + + $agents[$key]['secondary_groups'] = $agent_secondary_groups; + } + + if (array_search('custom_fields', $es_agents_inventory_display_options) !== false) { + $sql_agent_custom_fields = sprintf( + 'SELECT tacd.description, tacf.name + FROM tagent_custom_data tacd INNER JOIN tagent_custom_fields tacf + ON tacd.id_field = tacf.id_field + WHERE tacd.description != "" AND tacd.id_agent = %d', + $value['id_agente'] + ); + + $agent_custom_fields = []; + $agent_custom_fields = db_get_all_rows_sql($sql_agent_custom_fields); + + $agents[$key]['custom_fields'] = $agent_custom_fields; + } + } + + foreach ($agents as $key => $value) { + foreach ($value as $agent_val_key => $agent_val) { + // Exclude from data to be displayed in report those fields that were not selected to be displayed by user. + if (array_search($agent_val_key, $es_agents_inventory_display_options) === false) { + unset($agents[$key][$agent_val_key]); + } + } + } + + $return['data'] = $agents; + + return reporting_check_structure_content($return); } @@ -2286,7 +2406,7 @@ function reporting_inventory_changes($report, $content, $type) metaconsole_connect($server); } - $es = json_decode($content['external_source'], true); + $es = json_decode($content['external_source'], true); $id_agent = $es['id_agents']; $module_name = $es['inventory_modules']; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 211d8b193d..ceba581f11 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -247,7 +247,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1) } $table->colspan['description_row']['description'] = 3; - hd($item['type']); + switch ($item['type']) { case 'availability': default: @@ -1440,46 +1440,129 @@ function reporting_html_event_report_module($table, $item, $pdf=0) */ function reporting_html_agents_inventory($table, $item, $pdf=0) { - hd('agents inventory'); - hd($item); - global $config; - if (empty($item['data']) === false) { - $table_data = new stdClass(); - $table_data->width = '100%'; - $table_data->headstyle = []; - $table_data->headstyle[0] = 'text-align: left;'; - $table_data->style = []; - $table_data->style[0] = 'text-align: left;'; - $table_data->head = [ - __('Name'), - __('Date'), - __('Data'), - __('Status'), - ]; + $table1 = new stdClass(); + $table1->width = '100%'; - $table_data->data = []; - $table_data->data[1][0] = $item['data']['agent_name']; - $table_data->data[1][0] .= ' / '; - $table_data->data[1][0] .= $item['data']['module_name']; + $table1->style[0] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->class = 'databox data'; + $table1->cellpadding = 1; + $table1->cellspacing = 1; + $table1->styleTable = 'overflow: wrap; table-layout: fixed;'; - $table_data->data[1][1] = date( - 'Y-m-d H:i:s', - $item['data']['utimestamp'] - ); + $table1->style[0] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[1] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[2] = 'text-align: left;vertical-align: top; min-width: 100px'; + $table1->style[3] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[4] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[5] = 'text-align: left;vertical-align: top; min-width: 100px'; + $table1->style[6] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[7] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[8] = 'text-align: left;vertical-align: top; min-width: 100px'; + $table1->style[9] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[10] = 'text-align: left;vertical-align: top;min-width: 100px;'; + $table1->style[11] = 'text-align: left;vertical-align: top; min-width: 100px'; + + $table1->head = []; + + foreach ($item['data'][0] as $field_key => $field_value) { + switch ($field_key) { + case 'alias': + $table1->head[] = __('Alias'); + break; + + case 'direccion': + $table1->head[] = __('IP Address'); + break; + + case 'id_os': + $table1->head[] = __('OS'); + break; + + case 'id_grupo': + $table1->head[] = __('Group'); + break; + + case 'comentarios': + $table1->head[] = __('Description'); + break; + + case 'secondary_groups': + $table1->head[] = __('Sec. groups'); + break; + + case 'url_address': + $table1->head[] = __('URL'); + break; + + case 'custom_fields': + $table1->head[] = __('Custom fields'); + break; + + case 'estado': + $table1->head[] = __('Status'); + break; + + case 'agent_version': + $table1->head[] = __('Version'); + break; + + case 'remote': + $table1->head[] = __('Remote conf.'); + break; + } + } + + $table1->headstyle[0] = 'text-align: left'; + $table1->headstyle[1] = 'text-align: left'; + $table1->headstyle[2] = 'text-align: left'; + $table1->headstyle[3] = 'text-align: left'; + $table1->headstyle[4] = 'text-align: left'; + $table1->headstyle[5] = 'text-align: left'; + $table1->headstyle[6] = 'text-align: left'; + $table1->headstyle[7] = 'text-align: left'; + $table1->headstyle[8] = 'text-align: left'; + $table1->headstyle[9] = 'text-align: left'; + $table1->headstyle[10] = 'text-align: left'; + $table1->headstyle[11] = 'text-align: left'; + + $table1->data = []; + + foreach ($item['data'] as $data) { + $row = []; + + foreach ($data as $data_field_key => $data_field_value) { + $column_value = $data_field_value; + + if ($data_field_key === 'id_os') { + $column_value = get_os_name((int) $data_field_value); + } else if ($data_field_key === 'estado') { + $column_value = ui_print_module_status((int) $data_field_value, true); + } else if ($data_field_key === 'id_grupo') { + $column_value = ui_print_group_icon((int) $data_field_value, true); + } + + $row[] = $column_value; + } + + $table1->data[] = $row; + + if ($pdf !== 0) { + $table1->data[] = '
'; + } } if ($pdf === 0) { - $table->colspan['last_value']['cell'] = 3; - $table->cellstyle['last_value']['cell'] = 'text-align: center;'; - $table->data['last_value']['cell'] = html_print_table( - $table_data, + $table->colspan['permissions']['cell'] = 3; + $table->cellstyle['permissions']['cell'] = 'text-align: center;'; + $table->data['permissions']['cell'] = html_print_table( + $table1, true ); } else { return html_print_table( - $table_data, + $table1, true ); }