created new report item

This commit is contained in:
alejandro.campos@artica.es 2021-06-01 09:43:55 +02:00
parent 3362106afe
commit 9cbe6a2924
3 changed files with 88 additions and 46 deletions

View File

@ -3199,7 +3199,7 @@ $class = 'databox filters';
?>
</td>
</tr>
<?php hd($selected_agent_remote); ?>
<tr id="row_agent_remote_conf" class="datos">
<td class="bolder">
<?php

View File

@ -2266,7 +2266,7 @@ function reporting_event_report_module(
function reporting_agents_inventory($report, $content)
{
global $config;
hd($content);
$return['name'] = $content['name'];
$return['type'] = 'agents_inventory';
$return['title'] = $content['name'];
@ -2285,7 +2285,7 @@ function reporting_agents_inventory($report, $content)
$es_agent_group_filter = $external_source['agent_group_filter'];
$es_users_groups = $external_source['users_groups'];
$es_agent_remote_conf = $external_source['agent_remote_conf'];
hd($es_agent_group_filter);
$search_sql = '';
if ($es_custom_fields != '') {
@ -2301,24 +2301,23 @@ function reporting_agents_inventory($report, $content)
}
if ($es_agent_version_filter != '') {
$search_sql .= ' AND tagente.agent_version = "'.$es_agent_version_filter.'"';
$search_sql .= ' AND tagente.agent_version LIKE "%'.$es_agent_version_filter.'%"';
}
if ($es_agent_module_search_filter != '') {
$search_sql .= ' AND tam.nombre = '.$es_agent_module_search_filter;
$search_sql .= ' AND tam.nombre LIKE "%'.$es_agent_module_search_filter.'%"';
}
if ($es_agent_group_filter != 0) {
$search_sql .= ' AND tagente.id_grupo = '.$es_agent_group_filter;
}
hd($es_agent_remote);
if ($es_agent_remote_conf != '') {
if ($es_agent_remote_conf != 0) {
$search_sql .= ' AND tagente.remote = '.$es_agent_remote_conf;
}
$user_groups_to_sql = implode(',', array_keys(users_get_groups()));
hd($search_sql);
$sql = sprintf(
'SELECT DISTINCT(tagente.id_agente) AS id_agente,
tagente.id_os,
@ -2347,49 +2346,68 @@ function reporting_agents_inventory($report, $content)
$search_sql
);
$agents = db_get_all_rows_sql($sql);
foreach ($agents as $key => $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;
}
if (is_metaconsole()) {
$servers_ids = array_column(metaconsole_get_servers(), 'id');
} else {
$servers_ids = [0];
}
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'] = [];
foreach ($servers_ids as $server_id) {
if (is_metaconsole()) {
$server = metaconsole_get_connection_by_id($server_id);
metaconsole_connect($server);
}
$agents = db_get_all_rows_sql($sql);
foreach ($agents as $key => $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;
}
}
}
$return['data'] = $agents;
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'] = array_merge($return['data'], $agents);
if (is_metaconsole()) {
metaconsole_restore_db();
}
}
return reporting_check_structure_content($return);
}

View File

@ -1541,6 +1541,26 @@ function reporting_html_agents_inventory($table, $item, $pdf=0)
$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);
} else if ($data_field_key === 'custom_fields') {
$custom_fields_value = [];
if (is_array($data_field_value)) {
foreach ($data_field_value as $value) {
$custom_fields_value[] = $value['name'].': '.$value['description'];
}
}
$column_value = implode(' / ', $custom_fields_value);
} else if ($data_field_key === 'secondary_groups') {
$custom_fields_value = [];
if (is_array($data_field_value)) {
foreach ($data_field_value as $value) {
$custom_fields_value[] = ui_print_group_icon((int) $value['id_group'], true);
}
}
$column_value = implode(' / ', $custom_fields_value);
}
$row[] = $column_value;
@ -1553,6 +1573,8 @@ function reporting_html_agents_inventory($table, $item, $pdf=0)
}
}
hd('======', true);
hd($pdf, true);
if ($pdf === 0) {
$table->colspan['permissions']['cell'] = 3;
$table->cellstyle['permissions']['cell'] = 'text-align: center;';
@ -5903,6 +5925,8 @@ function reporting_html_permissions($table, $item, $pdf=0)
}
}
// hd("lllllp", true);
// hd($pdf, true);
if ($pdf === 0) {
$table->colspan['permissions']['cell'] = 3;
$table->cellstyle['permissions']['cell'] = 'text-align: center;';