Merge branch 'ent-8459-Nuevo-informe-de-catalogo-de-modulos-del-sistema' into 'develop'

Ent 8459 nuevo informe de catalogo de modulos del sistema

See merge request artica/pandorafms!5067
This commit is contained in:
Diego Muñoz-Reja 2022-08-30 12:18:45 +00:00
commit 53026e8d98
5 changed files with 376 additions and 2 deletions

View File

@ -78,6 +78,14 @@ $agents_inventory_display_options['estado'] = __('Status');
$agents_inventory_display_options['agent_version'] = __('Version');
$agents_inventory_display_options['remote'] = __('Remote configuration');
// Modules inventory display options.
$modules_inventory_display_options = [];
$modules_inventory_display_options['alias'] = __('Name');
$modules_inventory_display_options['direccion'] = __('Description');
$modules_inventory_display_options['id_os'] = __('Tags');
$modules_inventory_display_options['id_grupo'] = __('Module groups');
$modules_inventory_display_options['secondary_groups'] = __('Group');
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')) {
@ -901,6 +909,14 @@ switch ($action) {
$idAgentModule = $inventory_modules;
break;
case 'modules_inventory':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
$selected_agent_group_filter = $es['agent_group_filter'];
$selected_module_group = $es['module_group'];
break;
case 'inventory':
$description = $item['description'];
$es = json_decode($item['external_source'], true);
@ -3644,7 +3660,22 @@ $class = 'databox filters';
true,
'agent_group_filter',
$selected_agent_group_filter,
''
'',
'',
0,
false,
false,
false,
'',
false,
false,
false,
false,
'id_grupo',
false,
false,
false,
120
);
?>
</td>
@ -3820,6 +3851,47 @@ $class = 'databox filters';
</td>
</tr>
<tr id="row_module_group_filter" class="datos">
<td class="bolder">
<?php
echo __('Module group filter');
?>
</td>
<td>
<?php
$rows_select = [];
$rows_select[0] = __('Not assigned');
if ($is_metaconsole === false) {
$rows = db_get_all_rows_sql(
'SELECT * FROM tmodule_group ORDER BY name'
);
$rows = io_safe_output($rows);
if (empty($rows) === false) {
foreach ($rows as $module_group) {
$rows_select[$module_group['id_mg']] = $module_group['name'];
}
}
} else {
$rows_select = modules_get_modulegroups();
}
html_print_select($rows_select, 'modulegroup', $modulegroup, '', __($is_none), -1, true, false, true, '', false, 'width: 120px;');
html_print_select(
$rows_select,
'module_group',
$selected_module_group,
'',
__('All'),
-1,
false,
false,
true,
'',
false,
'width: 120px;'
);
?>
</td>
</tr>
</tbody>
</table>
@ -6139,6 +6211,8 @@ function chooseType() {
$("#row_agents_inventory_display_options").hide();
$("#row_agent_server_filter").hide();
$("#row_agent_group_filter").hide();
$("#row_module_group_filter").hide();
$("#row_module_group_filter").hide();
$("#row_os").hide();
$("#row_custom_field_filter").hide();
$("#row_custom_field").hide();
@ -6768,6 +6842,14 @@ function chooseType() {
break;
case 'modules_inventory':
$("#row_group").show();
$("#row_agent_server_filter").show();
$("#row_agent_group_filter").show();
$("#row_module_group_filter").show();
break;
case 'inventory':
$("#row_description").show();
$("#row_group").show();

View File

@ -2313,6 +2313,14 @@ switch ($action) {
$values['external_source'] = json_encode($es);
break;
case 'modules_inventory':
$es['agent_server_filter'] = get_parameter('agent_server_filter');
$es['module_group'] = get_parameter('module_group');
$es['agent_group_filter'] = get_parameter('agent_group_filter');
$values['external_source'] = json_encode($es);
break;
case 'IPAM_network':
$es['network_filter'] = get_parameter('network_filter');
$es['alive_ip'] = get_parameter('alive_ip');
@ -3081,6 +3089,14 @@ switch ($action) {
$values['external_source'] = json_encode($es);
break;
case 'modules_inventory':
$es['agent_server_filter'] = get_parameter('agent_server_filter');
$es['module_group'] = get_parameter('module_group');
$es['agent_group_filter'] = get_parameter('agent_group_filter');
$values['external_source'] = json_encode($es);
break;
case 'IPAM_network':
$es['network_filter'] = get_parameter('network_filter');
$es['alive_ip'] = get_parameter('alive_ip');

View File

@ -774,6 +774,13 @@ function reporting_make_reporting_data(
);
break;
case 'modules_inventory':
$report['contents'][] = reporting_modules_inventory(
$report,
$content
);
break;
case 'inventory':
$report['contents'][] = reporting_inventory(
$report,
@ -2438,6 +2445,14 @@ function reporting_event_report_module(
}
/**
* Generate agents inventory report.
*
* @param array $report Report info.
* @param array $content Content info.
*
* @return array
*/
function reporting_agents_inventory($report, $content)
{
global $config;
@ -2470,7 +2485,7 @@ function reporting_agents_inventory($report, $content)
$custom_field_sql = '';
$search_sql = '';
if (!empty($es_agent_custom_fields)) {
if (empty(array_filter($es_agent_custom_fields)) === false) {
$custom_field_sql = 'INNER JOIN tagent_custom_data tacd ON tacd.id_agent = tagente.id_agente';
if ($es_agent_custom_fields[0] != 0) {
$custom_field_sql .= ' AND tacd.id_field IN ('.implode(',', $es_agent_custom_fields).')';
@ -2629,6 +2644,146 @@ function reporting_agents_inventory($report, $content)
}
/**
* Generate modules inventory report.
*
* @param array $report Report info.
* @param array $content Content info.
*
* @return array
*/
function reporting_modules_inventory($report, $content)
{
global $config;
$return['name'] = $content['name'];
$return['type'] = 'modules_inventory';
$return['title'] = $content['name'];
$return['landscape'] = $content['landscape'];
$return['pagebreak'] = $content['pagebreak'];
$return['description'] = $content['description'];
$return['date'] = reporting_get_date_text($report, $content);
$external_source = io_safe_input(json_decode($content['external_source'], true));
$es_agent_group_filter = $external_source['agent_group_filter'];
$module_group = $external_source['module_group'];
$es_agent_server_filter = $external_source['agent_server_filter'];
$search_sql = '';
if (empty($es_agent_group_filter) === false) {
$search_sql .= ' AND (ta.id_grupo = '.$es_agent_group_filter.' OR tasg.id_group = '.$es_agent_group_filter.')';
}
if (empty($module_group) === false && $module_group > -1) {
$search_sql .= ' AND tam.id_module_group = '.$module_group;
}
$user_groups_to_sql = '';
$user_groupsAR = users_get_groups($config['id_user'], 'AR');
$user_groups = $user_groupsAR;
$user_groups_to_sql = implode(',', array_keys($user_groups));
$sql = sprintf(
'SELECT tam.id_agente_modulo,
tam.nombre,
tam.descripcion,
tam.id_module_group,
ttm.id_tag,
ta.id_grupo AS group_id,
tasg.id_group AS sec_group_id
FROM tagente_modulo tam
INNER JOIN tagente ta
ON tam.id_agente = ta.id_agente
LEFT JOIN tagent_secondary_group tasg
ON ta.id_agente = tasg.id_agent
LEFT JOIN ttag_module ttm
ON ttm.id_agente_modulo = tam.id_agente_modulo
WHERE (ta.id_grupo IN (%s) OR tasg.id_group IN (%s)) %s',
$user_groups_to_sql,
$user_groups_to_sql,
$search_sql
);
if (is_metaconsole()) {
$servers_ids = array_column(metaconsole_get_servers(), 'id');
} else {
$servers_ids = [0];
}
$return_data = [];
foreach ($servers_ids as $server_id) {
if (is_metaconsole()) {
$server = metaconsole_get_connection_by_id($server_id);
if ((int) $es_agent_server_filter !== 0
&& (int) $es_agent_server_filter !== (int) $server_id
) {
continue;
}
metaconsole_connect($server);
}
$agents = db_get_all_rows_sql($sql);
$return_data[$server_id] = $agents;
if (is_metaconsole()) {
metaconsole_restore_db();
}
}
$all_data = [];
foreach ($return_data as $server_agents) {
foreach ($server_agents as $agent) {
$all_data[] = $agent;
}
}
$return['data'] = $all_data;
$module_row_data = [];
foreach ($return['data'] as $row) {
if (is_array($module_row_data[$row['id_agente_modulo']]) === false) {
$module_row_data[$row['id_agente_modulo']]['nombre'] = $row['nombre'];
$module_row_data[$row['id_agente_modulo']]['descripcion'] = $row['descripcion'];
$module_row_data[$row['id_agente_modulo']]['id_module_group'] = $row['id_module_group'];
$module_row_data[$row['id_agente_modulo']]['id_tag'] = [];
$module_row_data[$row['id_agente_modulo']]['group_id'] = [];
$module_row_data[$row['id_agente_modulo']]['sec_group_id'] = [];
}
if (in_array($row['id_tag'], $module_row_data[$row['id_agente_modulo']]['id_tag']) === false
&& $row['id_tag'] !== null
) {
$module_row_data[$row['id_agente_modulo']]['id_tag'][] = $row['id_tag'];
}
if (in_array($row['group_id'], $module_row_data[$row['id_agente_modulo']]['group_id']) === false
&& $row['group_id'] !== null
) {
$module_row_data[$row['id_agente_modulo']]['group_id'][] = $row['group_id'];
}
if (in_array($row['sec_group_id'], $module_row_data[$row['id_agente_modulo']]['sec_group_id']) === false
&& $row['sec_group_id'] !== null
) {
$module_row_data[$row['id_agente_modulo']]['sec_group_id'][] = $row['sec_group_id'];
}
}
$return['data'] = $module_row_data;
return reporting_check_structure_content($return);
}
function reporting_inventory_changes($report, $content, $type)
{
global $config;

View File

@ -394,6 +394,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
reporting_html_agents_inventory($table, $item);
break;
case 'modules_inventory':
reporting_html_modules_inventory($table, $item);
break;
case 'inventory':
reporting_html_inventory($table, $item);
break;
@ -1677,6 +1681,116 @@ function reporting_html_agents_inventory($table, $item, $pdf=0)
}
/**
* Print html modules inventory
*
* @param object $table Head table or false if it comes from pdf.
* @param array $item Items data.
* @param boolean $pdf Print pdf true or false.
*
* @return string HTML code.
*/
function reporting_html_modules_inventory($table, $item, $pdf=0)
{
global $config;
$table1 = new stdClass();
$table1->width = '100%';
$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;';
$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->head = [];
$table1->head[] = __('Name');
$table1->head[] = __('Description');
$table1->head[] = __('Module group');
$table1->head[] = __('Tags');
$table1->head[] = __('Agent group');
$table1->head[] = __('Agent secondary groups');
$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->data = [];
foreach ($item['data'] as $module_id => $module_data) {
$row = [];
$first_item = array_pop(array_reverse($module_data));
foreach ($module_data as $data_field_key => $data_field_value) {
if ($data_field_key === 'nombre') {
$column_value = $data_field_value;
} else if ($data_field_key === 'descripcion') {
$column_value = $data_field_value;
} else if ($data_field_key === 'id_module_group') {
$module_group_name = modules_get_modulegroup_name($data_field_value);
if ($module_group_name === '') {
$module_group_name = '-';
}
$column_value = $module_group_name;
} else if ($data_field_key === 'id_tag') {
$tags_names = array_map(
function ($tag_id) {
return db_get_value('name', 'ttag', 'id_tag', $tag_id);
},
$data_field_value
);
$column_value = implode('<br>', $tags_names);
} else if ($data_field_key === 'group_id') {
$column_value = groups_get_name($data_field_value[0]);
} else if ($data_field_key === 'sec_group_id') {
$sec_groups_names = array_map(function ($group_id) {
return groups_get_name($group_id);
},
$data_field_value
);
$column_value = implode('<br>', $sec_groups_names);
}
$row[] = $column_value;
}
$table1->data[] = $row;
if ($pdf !== 0) {
$table1->data[] = '<br />';
}
}
if ($pdf === 0) {
$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(
$table1,
true
);
}
}
/**
* Print in html inventory changes reports
*

View File

@ -880,6 +880,13 @@ function reports_get_report_types($template=false, $not_editor=false)
];
}
if (!$template) {
$types['modules_inventory'] = [
'optgroup' => __('Inventory'),
'name' => __('Modules inventory'),
];
}
if ($config['enterprise_installed']) {
$types['inventory'] = [
'optgroup' => __('Inventory'),