created new report item
This commit is contained in:
parent
1c1e25e712
commit
7abe6d5446
|
@ -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';
|
|||
<td><?php html_print_checkbox_switch('pagebreak', 1, $pagebreak); ?></td>
|
||||
</tr>
|
||||
|
||||
<tr id="row_agents_inventory_display_options" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('Display options');
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
html_print_select(
|
||||
$agents_inventory_display_options,
|
||||
'agents_inventory_display_options[]',
|
||||
$selected_agents_inventory_display_options,
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
true,
|
||||
true,
|
||||
'',
|
||||
false,
|
||||
'width:200px'
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="row_agent_group_filter" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('Agent group filter');
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
html_print_select_groups(
|
||||
$config['id_user'],
|
||||
'RW',
|
||||
true,
|
||||
'agent_group_filter',
|
||||
$selected_agent_group_filter,
|
||||
''
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr id="row_os" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('OS');
|
||||
echo __('Agent OS filter');
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
html_print_select_from_sql(
|
||||
'SELECT id_os, name FROM tconfig_os',
|
||||
'id_os',
|
||||
$id_os,
|
||||
'agent_os_filter',
|
||||
$selected_agent_os_filter,
|
||||
'',
|
||||
'',
|
||||
'0'
|
||||
|
@ -3043,14 +3123,14 @@ $class = 'databox filters';
|
|||
<tr id="row_custom_field" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('Custom field');
|
||||
echo __('Agent custom field filter');
|
||||
?>
|
||||
</td>
|
||||
<td >
|
||||
<?php
|
||||
echo html_print_input_text(
|
||||
'label',
|
||||
$label,
|
||||
'agent_custom_field_filter',
|
||||
$selected_agent_custom_field_filter,
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
|
@ -3067,7 +3147,7 @@ $class = 'databox filters';
|
|||
<tr id="row_agent_status" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('Agent status');
|
||||
echo __('Agent status filter');
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
|
@ -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';
|
|||
<tr id="row_agent_version" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('Agent version');
|
||||
echo __('Agent version filter');
|
||||
?>
|
||||
</td>
|
||||
<td >
|
||||
<?php
|
||||
echo html_print_input_text(
|
||||
'agent_version',
|
||||
'',
|
||||
'agent_version_filter',
|
||||
$selected_agent_version_filter,
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
|
@ -3137,14 +3217,14 @@ $class = 'databox filters';
|
|||
<tr id="row_module_free_search" class="datos">
|
||||
<td class="bolder">
|
||||
<?php
|
||||
echo __('Module search');
|
||||
echo __('Agent module filter');
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
echo html_print_input_text(
|
||||
'module_search',
|
||||
'',
|
||||
'agent_module_search_filter',
|
||||
$selected_agent_module_search_filter,
|
||||
'',
|
||||
50,
|
||||
255,
|
||||
|
@ -5361,6 +5441,8 @@ function chooseType() {
|
|||
$("#row_users").hide();
|
||||
$("#row_profiles_group").hide();
|
||||
$("#row_select_by_group").hide();
|
||||
$("#row_agents_inventory_display_options").hide();
|
||||
$("#row_agent_group_filter").hide();
|
||||
$("#row_os").hide();
|
||||
$("#row_custom_field").hide();
|
||||
$("#row_agent_status").hide();
|
||||
|
@ -5909,10 +5991,12 @@ function chooseType() {
|
|||
break;
|
||||
|
||||
case 'agents_inventory':
|
||||
$("#row_agents_inventory_display_options").show();
|
||||
$("#row_agent_group_filter").show();
|
||||
$("#row_group").show();
|
||||
$("#row_os").show();
|
||||
$("#row_custom_field").show();
|
||||
$("#row_status").show();
|
||||
$("#row_agent_status").show();
|
||||
$("#row_agent_version").show();
|
||||
$("#row_agent_remote_conf").show();
|
||||
$("#row_module_free_search").show();
|
||||
|
|
|
@ -2100,6 +2100,18 @@ switch ($action) {
|
|||
$values['external_source'] = json_encode($es);
|
||||
break;
|
||||
|
||||
case 'agents_inventory':
|
||||
$es['agents_inventory_display_options'] = get_parameter('agents_inventory_display_options');
|
||||
$es['agent_custom_field_filter'] = get_parameter('agent_custom_field_filter');
|
||||
$es['agent_os_filter'] = get_parameter('agent_os_filter');
|
||||
$es['agent_status_filter'] = get_parameter('agent_status_filter');
|
||||
$es['agent_version_filter'] = get_parameter('agent_version_filter');
|
||||
$es['agent_module_search_filter'] = get_parameter('agent_module_search_filter');
|
||||
$es['agent_group_filter'] = get_parameter('agent_group_filter');
|
||||
|
||||
$values['external_source'] = json_encode($es);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
|
@ -2725,6 +2737,18 @@ switch ($action) {
|
|||
$values['external_source'] = json_encode($es);
|
||||
break;
|
||||
|
||||
case 'agents_inventory':
|
||||
$es['agents_inventory_display_options'] = get_parameter('agents_inventory_display_options');
|
||||
$es['agent_custom_field_filter'] = get_parameter('agent_custom_field_filter');
|
||||
$es['agent_os_filter'] = get_parameter('agent_os_filter');
|
||||
$es['agent_status_filter'] = get_parameter('agent_status_filter');
|
||||
$es['agent_version_filter'] = get_parameter('agent_version_filter');
|
||||
$es['agent_module_search_filter'] = get_parameter('agent_module_search_filter');
|
||||
$es['agent_group_filter'] = get_parameter('agent_group_filter');
|
||||
|
||||
$values['external_source'] = json_encode($es);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default.
|
||||
break;
|
||||
|
|
|
@ -1166,7 +1166,7 @@ if (check_login()) {
|
|||
|
||||
$last_status_change_text = 'Time elapsed since last status change: ';
|
||||
$last_status_change_text .= !empty($module['last_status_change']) ? human_time_comparation($module['last_status_change']) : __('N/A');
|
||||
|
||||
hd($title);
|
||||
$data[5] = ui_print_status_image($status, htmlspecialchars($title), true, false, false, false, $last_status_change_text);
|
||||
if (!$show_context_help_first_time) {
|
||||
$show_context_help_first_time = true;
|
||||
|
|
|
@ -2265,7 +2265,127 @@ function reporting_event_report_module(
|
|||
|
||||
function reporting_agents_inventory($report, $content)
|
||||
{
|
||||
hd($content);
|
||||
global $config;
|
||||
|
||||
$return['name'] = $content['name'];
|
||||
$return['type'] = 'agents_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_agents_inventory_display_options = $external_source['agents_inventory_display_options'];
|
||||
$es_custom_fields = $external_source['agent_custom_field_filter'];
|
||||
$es_os_filter = $external_source['agent_os_filter'];
|
||||
$es_agent_status_filter = $external_source['agent_status_filter'];
|
||||
$es_agent_version_filter = $external_source['agent_version_filter'];
|
||||
$es_agent_module_search_filter = $external_source['agent_module_search_filter'];
|
||||
$es_agent_group_filter = $external_source['agent_group_filter'];
|
||||
$es_users_groups = $external_source['users_groups'];
|
||||
|
||||
$search_sql = '';
|
||||
|
||||
if ($es_custom_fields != 0) {
|
||||
$search_sql .= ' AND id_os = '.$es_custom_fields;
|
||||
}
|
||||
|
||||
if ($es_os_filter != 0) {
|
||||
$search_sql .= ' AND id_os = '.$es_os_filter;
|
||||
}
|
||||
|
||||
if ($es_agent_status_filter != 0) {
|
||||
$search_sql .= ' AND tae.estado = '.$es_agent_status_filter;
|
||||
}
|
||||
|
||||
if ($es_agent_version_filter != 0) {
|
||||
$search_sql .= ' AND tagente.agent_version = '.$es_agent_version_filter;
|
||||
}
|
||||
|
||||
if ($es_agent_module_search_filter != 0) {
|
||||
$search_sql .= ' AND tam.nombre = '.$es_agent_module_search_filter;
|
||||
}
|
||||
|
||||
if ($es_agent_group_filter != 0) {
|
||||
$search_sql .= ' AND tagente.id_grupo = '.$es_agent_group_filter;
|
||||
}
|
||||
|
||||
$user_groups_to_sql = implode(',', array_keys(users_get_groups()));
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT DISTINCT(tagente.id_agente) AS id_agente,
|
||||
tagente.id_os,
|
||||
tagente.direccion,
|
||||
tae.estado,
|
||||
tagente.agent_version,
|
||||
tagente.alias,
|
||||
tagente.id_grupo,
|
||||
tagente.comentarios,
|
||||
tagente.url_address,
|
||||
tagente.remote
|
||||
FROM tagente LEFT JOIN tagent_secondary_group tasg
|
||||
ON tagente.id_agente = tasg.id_agent
|
||||
INNER JOIN tagente_modulo tam
|
||||
ON tam.id_agente = tagente.id_agente
|
||||
INNER JOIN (
|
||||
SELECT *
|
||||
FROM (SELECT id_agente, estado FROM tagente_estado ORDER BY `utimestamp` DESC) tagente_estado
|
||||
GROUP BY `id_agente`
|
||||
) tae
|
||||
ON tae.id_agente = tagente.id_agente
|
||||
WHERE (tagente.id_grupo IN (%s) OR tasg.id_group IN (%s))
|
||||
%s',
|
||||
$user_groups_to_sql,
|
||||
$user_groups_to_sql,
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
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'];
|
||||
|
|
|
@ -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[] = '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue