change regex search in events

This commit is contained in:
alejandro.campos@artica.es 2024-02-16 10:10:38 +01:00
parent cb63c27d2a
commit df7435132a
5 changed files with 47 additions and 38 deletions

View File

@ -0,0 +1,11 @@
START TRANSACTION;
-- Watch out! The following field migration must be done before altering the corresponding table.
UPDATE `tevent_filter`
SET `search` = `regex`
WHERE `regex` IS NOT NULL AND `regex` != '';
-- Watch out! The following alter command must be done after the previous update of this table.
ALTER TABLE `tevent_filter` MODIFY COLUMN `regex` TINYINT unsigned NOT NULL DEFAULT 0;
COMMIT;

View File

@ -646,7 +646,7 @@ function load_form_filter() {
if (i == 'search')
$('#text-search').val(val);
if (i == 'regex')
$('#text-regex').val(val);
$('#checkbox-regex').val(val);
if (i == 'not_search')
$('#checkbox-not_search').val(val);
if (i == 'text_agent')
@ -977,7 +977,7 @@ function save_new_filter() {
"severity" : $("#severity").val(),
"status" : $("#status").val(),
"search" : $("#text-search").val(),
"regex" : $('#text-regex').val(),
"regex" : $('#checkbox-regex').val(),
"not_search" : $("#checkbox-not_search").val(),
"text_agent" : $("#text_id_agent").val(),
"id_agent" : $('input:hidden[name=id_agent]').val(),
@ -1058,7 +1058,7 @@ function save_update_filter() {
"severity" : $("#severity").val(),
"status" : $("#status").val(),
"search" : $("#text-search").val(),
"regex" : $('#text-regex').val(),
"regex" : $('#checkbox-regex').val(),
"not_search" : $("#checkbox-not_search").val(),
"text_agent" : $("#text_id_agent").val(),
"id_agent" : $('input:hidden[name=id_agent]').val(),
@ -2594,6 +2594,7 @@ if ($get_events_fired) {
'severity' => -1,
'status' => -1,
'search' => '',
'regex' => 0,
'not_search' => 0,
'text_agent' => '',
'id_agent' => 0,

View File

@ -1177,14 +1177,22 @@ function events_get_all(
$array_search[] = 'lower(ta.alias)';
}
if ((bool) $filter['regex'] === true) {
$comp_pattern = 'REGEXP "%s"';
} else {
$comp_pattern = 'LIKE lower("%%%s%%")';
}
$comp_string = sprintf($comp_pattern, $filter['search']);
$sql_search = ' AND (';
foreach ($array_search as $key => $field) {
$sql_search .= sprintf(
'%s %s %s like lower("%%%s%%")',
'%s %s %s %s',
($key === 0) ? '' : $nexo,
$field,
$not_search,
$filter['search']
$comp_string
);
$sql_search .= ' ';
}

View File

@ -130,11 +130,11 @@ $severity = get_parameter(
'filter[severity]',
($filter['severity'] ?? '')
);
$regex = get_parameter(
$regex = (bool) get_parameter(
'filter[regex]',
(io_safe_output($filter['regex']) ?? '')
($filter['regex'] ?? false)
);
unset($filter['regex']);
$status = get_parameter(
'filter[status]',
($filter['status'] ?? '')
@ -1229,27 +1229,7 @@ if (is_ajax() === true) {
}
}
$regex_validation = false;
if (empty($tmp) === false && $regex !== '') {
foreach (json_decode(json_encode($tmp), true) as $key => $field) {
if ($key === 'b64') {
continue;
}
$field = strip_tags($field);
if (preg_match('/'.$regex.'/', $field)) {
$regex_validation = true;
}
}
if ($regex_validation === true) {
$carry[] = $tmp;
}
} else {
$carry[] = $tmp;
}
$carry[] = $tmp;
return $carry;
}
);
@ -2083,6 +2063,23 @@ $data .= ui_print_help_tip(
__('Search for elements NOT containing given text.'),
true
);
$data .= '&nbsp&nbsp&nbsp';
$data .= html_print_checkbox_switch(
'regex',
$regex,
$regex,
true,
false,
'checked_slide_events(this);',
true
);
$data .= ui_print_help_tip(
__('Search by regular expression.'),
true
);
$data .= '</div>';
$in = '<div class="filter_input filter_input_not_search"><label>'.__('Free search').'</label>';
@ -2119,12 +2116,6 @@ $in = '<div class="filter_input"><label>'.__('Severity').'</label>';
$in .= $data.'</div>';
$inputs[] = $in;
// REGEX search datatable.
$in = '<div class="filter_input"><label>'.__('Regex search').ui_print_help_tip(__('Filter the results of the current page with regular expressions. It works on Agent name, Event name, Extra ID, Source, Custom data and Comment fields.'), true).'</label>';
$in .= html_print_input_text('regex', $regex, '', '', 255, true);
$in .= '</div>';
$inputs[] = $in;
// User private filter.
$inputs[] = html_print_input_hidden('private_filter_event', $private_filter_event, true);
// Trick view in table.
@ -2805,8 +2796,6 @@ try {
true
);
// Print datatable.
html_print_div(
[

View File

@ -1264,7 +1264,7 @@ CREATE TABLE IF NOT EXISTS `tevent_filter` (
`custom_data_filter_type` TINYINT UNSIGNED DEFAULT 0,
`owner_user` TEXT,
`private_filter_user` TEXT,
`regex` TEXT,
`regex` TINYINT unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id_filter`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;