diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql new file mode 100644 index 0000000000..92db1c919c --- /dev/null +++ b/pandora_console/extras/mr/67.sql @@ -0,0 +1,6 @@ +START TRANSACTION; + +ALTER TABLE `tevento` +ADD COLUMN `custom_field` TEXT NULL AFTER `module_status`; + +COMMIT; diff --git a/pandora_console/godmode/events/custom_events.php b/pandora_console/godmode/events/custom_events.php index c91a2df8fe..bfa6dce937 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -115,6 +115,7 @@ $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'); +$fields_available['custom_field'] = __('Custom field'); // Remove fields already selected. diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index f9bf50b7ae..517777aacc 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,6 +92,7 @@ $get_id_source_event = get_parameter('get_id_source_event'); $node_id = (int) get_parameter('node_id', 0); $settings_modal = get_parameter('settings', 0); $parameters_modal = get_parameter('parameters', 0); +$update_custom_field = get_parameter('update_custom_field', 0); // User private filter. $current_filter = get_parameter('current_filter', 0); $private_filter_event = get_parameter('private_filter_event', 0); @@ -2759,3 +2760,50 @@ if ($draw_row_response_info === true) { echo $output; return; } + +if ($update_custom_field) { + $custom_field = get_parameter('custom_field_value'); + $event_id = get_parameter('event_id'); + $server_id = 0; + if (is_metaconsole() === true) { + $server_id = (int) get_parameter('server_id'); + } + + // Safe custom fields for hacks. + if (preg_match('/script/i', io_safe_output($custom_field))) { + $return = false; + } else { + try { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node = new Node($server_id); + $node->connect(); + } + + $return = events_custom_field( + $event_id, + $custom_field + ); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + + $return = false; + } finally { + if (is_metaconsole() === true + && $server_id > 0 + ) { + $node->disconnect(); + } + } + } + + echo ($return === true) ? 'update_ok' : 'update_error'; + + return; +} \ No newline at end of file diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 7e22befbee..dc6bdeb30f 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -17783,3 +17783,45 @@ function api_token_check(string $token) return db_get_value('id_user', 'tusuario', 'api_token', $token); } } + + +/** + * Set custom field value in tevento + * + * @param mixed $id_event Event id. + * @param mixed $custom_field Custom field to set. + * @return void + */ +function api_set_event_custom_field($id, $value) +{ + // Get the event + $event = events_get_event($id, false, is_metaconsole()); + // If event not exists, end the execution. + if ($event === false) { + returnError( + 'event_not_exists', + 'Event not exists' + ); + $result = false; + } + + // Safe custom fields for hacks. + if (preg_match('/script/i', io_safe_output($value))) { + $result = false; + } + + $result = events_custom_field( + $id, + $value + ); + + // If update results failed + if (empty($result) === true || $result === false) { + returnError( + 'The event could not be updated' + ); + return false; + } else { + returnData('string', ['data' => 'Event updated.']); + } +} diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 7068d554e6..c40a1eb9c7 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -219,6 +219,7 @@ function events_get_all_fields() $columns['module_status'] = __('Module status'); $columns['module_custom_id'] = __('Module custom id'); $columns['custom_data'] = __('Custom data'); + $columns['custom_field'] = __('Custom field'); return $columns; } @@ -322,6 +323,9 @@ function events_get_column_name($field, $table_alias=false) case 'custom_data': return __('Custom data'); + case 'custom_field': + return __('Custom field'); + default: return __($field); } @@ -4632,6 +4636,22 @@ function events_page_details($event, $server_id=0) $table_details->data[] = $data; + $data = []; + $data[0] = __('Custom Field'); + $data[1] = '