#10730 Regular expresion inventory reports

This commit is contained in:
Jonathan 2023-04-13 10:42:37 +02:00
parent c8b6be3e92
commit 7d9fb5c77a
5 changed files with 88 additions and 43 deletions

View File

@ -117,6 +117,7 @@ $period = SECONDS_1DAY;
$search = '';
$full_text = 0;
$log_number = 1000;
$inventory_regular_expression = '';
// Added support for projection graphs.
$period_pg = SECONDS_5DAY;
$projection_period = SECONDS_5DAY;
@ -940,6 +941,7 @@ switch ($action) {
$inventory_modules = $es['inventory_modules'];
$id_agents = $es['id_agents'];
$recursion = $item['recursion'];
$inventory_regular_expression = $es['inventory_regular_expression'];
$idAgent = $es['id_agents'];
$idAgentModule = $inventory_modules;
@ -2196,6 +2198,15 @@ $class = 'databox filters';
</td>
</tr>
<tr id="row_regular_expression" class="datos">
<td class="bolder"><?php echo __('Regular expression'); ?></td>
<td>
<?php
html_print_input_text('inventory_regular_expression', $inventory_regular_expression, '', false, 255, false, false, false, '', 'w50p');
?>
</td>
</tr>
<tr id="row_date" class="datos">
<td class="bolder"><?php echo __('Date'); ?></td>
<td class="mx180px">
@ -6445,6 +6456,7 @@ function chooseType() {
$("#row_date").hide();
$("#row_agent_multi").hide();
$("#row_module_multi").hide();
$('#row_regular_expression').hide();
$("#row_event_graphs").hide();
$("#row_event_graph_by_agent").hide();
$("#row_event_graph_by_user").hide();
@ -7154,6 +7166,7 @@ function chooseType() {
$("#row_group").show();
$("#row_agent_multi").show();
$("#row_module_multi").show();
$('#row_regular_expression').show();
$("#row_date").show();
$("#id_agents")

View File

@ -1756,6 +1756,7 @@ switch ($action) {
$es['inventory_modules'] = get_parameter(
'inventory_modules'
);
$es['inventory_regular_expression'] = get_parameter('inventory_regular_expression', '');
$description = get_parameter('description');
$values['external_source'] = json_encode($es);
$good_format = true;
@ -2538,6 +2539,7 @@ switch ($action) {
$es['inventory_modules'] = get_parameter(
'inventory_modules'
);
$es['inventory_regular_expression'] = get_parameter('inventory_regular_expression', '');
$values['external_source'] = json_encode($es);
$good_format = true;
break;

View File

@ -36,7 +36,8 @@ function inventory_get_data(
$return_mode=false,
$order_by_agent=false,
$node='',
$pagination_url_parameters=[]
$pagination_url_parameters=[],
$regular_expression=''
) {
global $config;
@ -268,7 +269,15 @@ function inventory_get_data(
$i++;
}
$data[] = $temp_row;
if ($regular_expression !== '') {
if (is_array(preg_grep('/'.$regular_expression.'/', $temp_row))) {
if (count(preg_grep('/'.$regular_expression.'/', $temp_row)) > 0) {
$data[] = $temp_row;
}
}
} else {
$data[] = $temp_row;
}
}
}

View File

@ -3170,6 +3170,7 @@ function reporting_inventory($report, $content, $type)
$date = $es['date'];
$description = $content['description'];
$inventory_regular_expression = $es['inventory_regular_expression'];
switch ($type) {
case 'data':
@ -3179,7 +3180,11 @@ function reporting_inventory($report, $content, $type)
$date,
'',
false,
'csv'
'csv',
false,
'',
[],
$inventory_regular_expression
);
break;
@ -3190,7 +3195,11 @@ function reporting_inventory($report, $content, $type)
$date,
'',
false,
'hash'
'hash',
false,
'',
[],
$inventory_regular_expression
);
break;
}

View File

@ -1996,6 +1996,13 @@ function reporting_html_inventory($table, $item, $pdf=0)
&& is_array($type_modules) === true
) {
foreach ($type_modules as $key_type_module => $type_module) {
$print_table = true;
foreach ($type_module as $key => $module) {
if (count($module['data']) == 0) {
unset($type_module[$key]);
}
}
$table1 = new stdClass();
$table1->width = '99%';
$table1->class = 'info_table';
@ -2006,57 +2013,62 @@ function reporting_html_inventory($table, $item, $pdf=0)
if (isset($type_module) === true
&& is_array($type_module) === true
) {
foreach ($type_module as $key_type => $module) {
if (isset($module['data']) === true
&& is_array($module['data']) === true
) {
array_pop($module['data']);
foreach ($module['data'] as $k_module => $v_module) {
$str_key = $key_type_module.'-'.$key_type.'-'.$k_module;
$table1->head[0] = __('Agent');
$table1->head[1] = __('Module');
$table1->head[2] = __('Date');
$table1->headstyle[0] = 'text-align: left';
$table1->headstyle[1] = 'text-align: left';
$table1->headstyle[2] = 'text-align: left';
$table1->cellstyle[$str_key][0] = 'text-align: left;';
$table1->cellstyle[$str_key][1] = 'text-align: left;';
$table1->cellstyle[$str_key][2] = 'text-align: left;';
$table1->data[$str_key][0] = $module['agent_name'];
$table1->data[$str_key][1] = $key_type_module;
$dateModule = explode(' ', $module['timestamp']);
$table1->data[$str_key][2] = $dateModule[0];
if (isset($v_module) === true
&& is_array($v_module) === true
) {
foreach ($v_module as $k => $v) {
$table1->head[$k] = $k;
$table1->headstyle[$k] = 'text-align: left';
$table1->cellstyle[$str_key][$k] = 'text-align: left;';
if ($pdf === 0) {
$table1->data[$str_key][$k] = $v;
} else {
// Workaround to prevent table columns from growing indefinitely in PDFs.
$table1->data[$str_key][$k] = preg_replace(
'/([^\s]{30})(?=[^\s])/',
'$1'.'<br>',
$v
);
if (count($type_module) > 0) {
foreach ($type_module as $key_type => $module) {
if (isset($module['data']) === true
&& is_array($module['data']) === true
) {
foreach ($module['data'] as $k_module => $v_module) {
$str_key = $key_type_module.'-'.$key_type.'-'.$k_module;
$table1->head[0] = __('Agent');
$table1->head[1] = __('Module');
$table1->head[2] = __('Date');
$table1->headstyle[0] = 'text-align: left';
$table1->headstyle[1] = 'text-align: left';
$table1->headstyle[2] = 'text-align: left';
$table1->cellstyle[$str_key][0] = 'text-align: left;';
$table1->cellstyle[$str_key][1] = 'text-align: left;';
$table1->cellstyle[$str_key][2] = 'text-align: left;';
$table1->data[$str_key][0] = $module['agent_name'];
$table1->data[$str_key][1] = $key_type_module;
$dateModule = explode(' ', $module['timestamp']);
$table1->data[$str_key][2] = $dateModule[0];
if (isset($v_module) === true
&& is_array($v_module) === true
) {
foreach ($v_module as $k => $v) {
$table1->head[$k] = $k;
$table1->headstyle[$k] = 'text-align: left';
$table1->cellstyle[$str_key][$k] = 'text-align: left;';
if ($pdf === 0) {
$table1->data[$str_key][$k] = $v;
} else {
// Workaround to prevent table columns from growing indefinitely in PDFs.
$table1->data[$str_key][$k] = preg_replace(
'/([^\s]{30})(?=[^\s])/',
'$1'.'<br>',
$v
);
}
}
}
}
}
}
} else {
$print_table = false;
}
} else {
$print_table = false;
}
if ($pdf === 0) {
if ($pdf === 0 && $print_table === true) {
$table->colspan[$key_type_module]['cell'] = 3;
$table->data[$key_type_module]['cell'] = html_print_table(
$table1,
true
);
} else {
} else if ($print_table === true) {
$return_pdf .= html_print_table(
$table1,
true
@ -5988,7 +6000,7 @@ function reporting_get_events($data, $links=false)
$tooltip = ui_print_help_tip(
__(
"Event count corresponds to events within the last hour"
'Event count corresponds to events within the last hour'
),
true
);