diff --git a/pandora_console/extras/mr/53.sql b/pandora_console/extras/mr/53.sql index dfb7976a91..0540d5dfe7 100644 --- a/pandora_console/extras/mr/53.sql +++ b/pandora_console/extras/mr/53.sql @@ -2,6 +2,9 @@ START TRANSACTION; ALTER TABLE `tipam_vlan` ADD COLUMN `custom_id` bigint(20) unsigned DEFAULT NULL; +ALTER TABLE `tevent_filter` ADD COLUMN `custom_data` VARCHAR(500) DEFAULT ''; +ALTER TABLE `tevent_filter` ADD COLUMN `custom_data_filter_type` TINYINT UNSIGNED DEFAULT 0; + UPDATE `tuser_task` SET `parameters` = 'a:3:{i:0;a:2:{s:11:"description";s:11:"Description";s:4:"type";s:4:"text";}i:1;a:3:{s:11:"description";s:20:"Save to disk in path";s:4:"type";s:6:"string";s:13:"default_value";s:21:"_%_ATTACHMENT_PATH_%_";}i:2;a:3:{s:11:"description";s:14:"Active backups";s:4:"type";s:6:"number";s:13:"default_value";i:3;}}' WHERE `function_name` = 'cron_task_do_backup'; CREATE TABLE IF NOT EXISTS `tbackup` ( diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql index 535182d147..41bdb0e6e2 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql @@ -1543,6 +1543,8 @@ ALTER TABLE `tevent_filter` MODIFY COLUMN `severity` text NOT NULL; ALTER TABLE tevent_filter ADD COLUMN `server_id` int(10) NOT NULL default 0; ALTER TABLE `tevent_filter` ADD COLUMN `time_from` TIME NULL; ALTER TABLE `tevent_filter` ADD COLUMN `time_to` TIME NULL; +ALTER TABLE `tevent_filter` ADD COLUMN `custom_data` VARCHAR(500) DEFAULT ''; +ALTER TABLE `tevent_filter` ADD COLUMN `custom_data_filter_type` TINYINT UNSIGNED DEFAULT 0; -- --------------------------------------------------------------------- -- Table `tusuario` diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index a53657ffce..fb5dce8830 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -116,6 +116,7 @@ $fields_available['data'] = __('Data'); $fields_available['module_status'] = __('Module Status'); $fields_available['mini_severity'] = __('Severity mini'); $fields_available['module_custom_id'] = __('Module custom ID'); +$fields_available['custom_data'] = __('Custom data'); // Remove fields already selected. diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index b52242f166..eebb4e213c 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -89,6 +89,8 @@ if ($id) { $tag_without_base64 = base64_encode($tag_without_json_clean); $filter_only_alert = $filter['filter_only_alert']; + $custom_data = $filter['custom_data']; + $custom_data_filter_type = $filter['custom_data_filter_type']; if ($id_agent_module != 0) { $text_module = modules_get_agentmodule_name($id_agent_module); @@ -165,30 +167,34 @@ if ($update || $create) { $tag_without_json = io_safe_input(base64_decode($tag_without_base64)); $filter_only_alert = get_parameter('filter_only_alert', ''); + $custom_data = get_parameter('custom_data', ''); + $custom_data_filter_type = get_parameter('custom_data_filter_type', ''); $values = [ - 'id_name' => $id_name, - 'id_group_filter' => $id_group_filter, - 'id_group' => $id_group, - 'event_type' => $event_type, - 'severity' => $severity, - 'status' => $status, - 'search' => $search, - 'text_agent' => $text_agent, - 'id_agent_module' => $id_agent_module, - 'id_agent' => $id_agent, - 'pagination' => $pagination, - 'event_view_hr' => $event_view_hr, - 'id_user_ack' => $id_user_ack, - 'group_rep' => $group_rep, - 'tag_with' => $tag_with_json, - 'tag_without' => $tag_without_json, - 'date_from' => $date_from, - 'date_to' => $date_to, - 'source' => $source, - 'id_extra' => $id_extra, - 'user_comment' => $user_comment, - 'filter_only_alert' => $filter_only_alert, + 'id_name' => $id_name, + 'id_group_filter' => $id_group_filter, + 'id_group' => $id_group, + 'event_type' => $event_type, + 'severity' => $severity, + 'status' => $status, + 'search' => $search, + 'text_agent' => $text_agent, + 'id_agent_module' => $id_agent_module, + 'id_agent' => $id_agent, + 'pagination' => $pagination, + 'event_view_hr' => $event_view_hr, + 'id_user_ack' => $id_user_ack, + 'group_rep' => $group_rep, + 'tag_with' => $tag_with_json, + 'tag_without' => $tag_without_json, + 'date_from' => $date_from, + 'date_to' => $date_to, + 'source' => $source, + 'id_extra' => $id_extra, + 'user_comment' => $user_comment, + 'filter_only_alert' => $filter_only_alert, + 'custom_data' => $custom_data, + 'custom_data_filter_type' => $custom_data_filter_type, ]; $severity = explode(',', $severity); @@ -627,9 +633,26 @@ $table->data[23][1] = html_print_input_text('id_extra', $id_extra, '', 11, 255, $table->data[24][0] = ''.__('Comment').''; $table->data[24][1] = html_print_input_text('user_comment', $user_comment, '', 35, 255, true); +$table->data[25][0] = ''.__('Custom data filter type').''; +$table->data[25][1] = html_print_select( + [ + '0' => __('Filter custom data by name field'), + '1' => __('Filter custom data by value field'), + ], + 'custom_data_filter_type', + $custom_data_filter_type, + '', + false, + '', + true +); + +$table->data[26][0] = ''.__('Custom data').''; +$table->data[26][1] = html_print_input_text('custom_data', $custom_data, '', 35, 255, true); + if (is_metaconsole()) { - $table->data[25][0] = ''.__('Id souce event').''; - $table->data[25][1] = html_print_input_text( + $table->data[27][0] = ''.__('Id souce event').''; + $table->data[27][1] = html_print_input_text( 'id_source_event', $id_source_event, '', diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index e8a0d5831a..71e0783c51 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -290,6 +290,8 @@ if ($save_event_filter) { $values['id_extra'] = get_parameter('id_extra'); $values['user_comment'] = get_parameter('user_comment'); $values['id_source_event'] = get_parameter('id_source_event'); + $values['custom_data'] = get_parameter('custom_data'); + $values['custom_data_filter_type'] = get_parameter('custom_data_filter_type'); if (is_metaconsole()) { $values['server_id'] = get_parameter('server_id'); @@ -344,6 +346,8 @@ if ($update_event_filter) { $values['id_extra'] = get_parameter('id_extra'); $values['user_comment'] = get_parameter('user_comment'); $values['id_source_event'] = get_parameter('id_source_event'); + $values['custom_data'] = get_parameter('custom_data'); + $values['custom_data_filter_type'] = get_parameter('custom_data_filter_type'); if (is_metaconsole() === true) { $values['server_id'] = get_parameter('server_id'); @@ -815,7 +819,9 @@ function save_new_filter() { "id_extra": $("#text-id_extra").val(), "user_comment": $("#text-user_comment").val(), "id_source_event": $("#text-id_source_event").val(), - "server_id": $("#server_id").val() + "server_id": $("#server_id").val(), + "custom_data": $("#text-custom_data").val(), + "custom_data_filter_type": $("#custom_data_filter_type").val() }, function (data) { $("#info_box").hide(); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 1eb5a1e34b..986fdab80c 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -210,6 +210,7 @@ function events_get_all_fields() $columns['data'] = __('Data'); $columns['module_status'] = __('Module status'); $columns['module_custom_id'] = __('Module custom id'); + $columns['custom_data'] = __('Custom data'); return $columns; } @@ -310,6 +311,9 @@ function events_get_column_name($field, $table_alias=false) case 'direccion': return __('Agent IP'); + case 'custom_data': + return __('Custom data'); + default: return __($field); } @@ -1118,6 +1122,23 @@ function events_get_all( ); } + // Custom data. + if (empty($filter['custom_data']) === false) { + if ($filter['custom_data_filter_type'] === '1') { + $sql_filters[] = sprintf( + ' AND JSON_VALID(custom_data) = 1 AND JSON_EXTRACT(custom_data, "$.*") LIKE lower("%%%s%%") ', + $filter['custom_data'], + $filter['custom_data'] + ); + } else { + $sql_filters[] = sprintf( + ' AND JSON_VALID(custom_data) = 1 AND JSON_KEYS(custom_data) REGEXP "%s" ', + $filter['custom_data'], + $filter['custom_data'] + ); + } + } + // Validated or in process by. if (empty($filter['id_user_ack']) === false) { $sql_filters[] = sprintf( @@ -5139,6 +5160,14 @@ function events_page_general($event) $data[1] = ''.__('N/A').''; } + $data = []; + $data[0] = __('Custom data'); + if ($event['custom_data'] != '') { + $data[1] = $event['custom_data']; + } else { + $data[1] = ''.__('N/A').''; + } + $table_general->data[] = $data; $table_data = $table_general->data; diff --git a/pandora_console/operation/events/events.build_table.php b/pandora_console/operation/events/events.build_table.php index b241cbcf16..1653f7ab7a 100644 --- a/pandora_console/operation/events/events.build_table.php +++ b/pandora_console/operation/events/events.build_table.php @@ -134,7 +134,7 @@ if ($group_rep == 2) { echo '