From 79fe89c3c54059094f1b5c1d069f09ca4cdd9648 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 22 Sep 2023 12:24:15 +0200 Subject: [PATCH 1/6] #11705 new custom_field tevento --- pandora_console/extras/mr/67.sql | 6 ++ .../godmode/events/custom_events.php | 1 + pandora_console/include/ajax/events.php | 48 ++++++++++++ pandora_console/include/functions_api.php | 42 +++++++++++ pandora_console/include/functions_events.php | 74 +++++++++++++++++++ .../include/javascript/pandora_events.js | 31 ++++++++ .../lib/Dashboard/Widgets/events_list.php | 1 + pandora_console/operation/events/events.php | 1 + pandora_console/pandoradb.sql | 1 + 9 files changed, 205 insertions(+) create mode 100644 pandora_console/extras/mr/67.sql 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] = '
'.html_print_input_text('custom_field', $event['custom_field'], '', false, 255, true, false, false, '', 'w60p'); + $data[1] .= html_print_button( + __('Update'), + 'update_custom_field', + false, + 'update_custom_field('.$event['id_evento'].', '.$event['server_id'].');', + [ + 'icon' => 'next', + 'mode' => 'link', + ], + true + ).'
'; + $table_details->data[] = $data; + $details = '
'.html_print_table($table_details, true).'
'; if (is_metaconsole() === true && empty($server_id) === false) { @@ -6203,3 +6223,57 @@ function event_get_counter_extraId(array $event, ?array $filters) return $counters; } + + +/** + * Update event detail custom field + * + * @param mixed $id_event Event ID or array of events. + * @param string $custom_field Custom_field to be update. + * + * @return boolean Whether or not it was successful + */ +function events_custom_field( + $id_event, + $custom_field, +) { + global $config; + // Cleans up the selection for all unwanted values also casts any single + // values as an array. + $id_event = (array) safe_int($id_event, 1); + // Check ACL. + foreach ($id_event as $k => $id) { + $event_group = events_get_group($id); + if (check_acl($config['id_user'], $event_group, 'EW') == 0) { + db_pandora_audit( + AUDIT_LOG_ACL_VIOLATION, + 'Attempted updating event #'.$id + ); + + unset($id_event[$k]); + } + } + + if (empty($id_event) === true) { + return false; + } + + // Get the current event comments. + $first_event = $id_event; + if (is_array($id_event) === true) { + $first_event = reset($id_event); + } + + // Update comment. + $ret = db_process_sql_update( + 'tevento', + ['custom_field' => $custom_field], + ['id_evento' => $first_event] + ); + + if (($ret === false) || ($ret === 0)) { + return false; + } + + return true; +} diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 940fd3ce5d..ce782769cb 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -492,6 +492,37 @@ function event_comment(current_event) { return false; } +// Save custom_field into an event. +function update_custom_field(event_id, server_id) { + var custom_field_value = $("#text-custom_field").val(); + + var params = { + page: "include/ajax/events", + update_custom_field: 1, + custom_field_value: custom_field_value, + event_id: event_id, + server_id: server_id + }; + + $("#button-update_custom_field").attr("disabled", "disabled"); + $("#response_loading").show(); + + jQuery.ajax({ + data: params, + type: "POST", + url: getUrlAjax(), + dataType: "html", + success: function(data) { + if (data === "update_error") { + alert("Custom field not valid"); + } + $("#button-update_custom_field").removeAttr("disabled"); + $("#response_loading").hide(); + $("#button-events_form_search_bt").trigger("click"); + } + }); +} + var processed = 0; function update_event(table, id_evento, type, event_rep, row, server_id) { var inputs = $("#events_form :input"); diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index b7ad581dc0..b84f11aa4a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -837,6 +837,7 @@ class EventsListWidget extends Widget 'mini_severity' => __('Severity mini'), 'module_custom_id' => __('Module custom ID'), 'custom_data' => __('Custom data'), + 'custom_field' => __('Custom field'), ]; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index 059c8f90ec..bde20209a4 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -377,6 +377,7 @@ if (is_ajax() === true) { 'te.owner_user', 'if(te.ack_utimestamp > 0, te.ack_utimestamp,"") as ack_utimestamp', 'te.custom_data', + 'te.custom_field', 'te.data', 'te.module_status', 'ta.alias as agent_name', diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 662beb93af..030ef3a76f 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -723,6 +723,7 @@ CREATE TABLE IF NOT EXISTS `tevento` ( `custom_data` TEXT, `data` TINYTEXT, `module_status` INT NOT NULL DEFAULT 0, + `custom_field` TEXT, PRIMARY KEY (`id_evento`), KEY `idx_agente` (`id_agente`), KEY `idx_agentmodule` (`id_agentmodule`), From e5c5f91576801803f0c743e3f3233b71b8708375 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 25 Sep 2023 10:32:23 +0200 Subject: [PATCH 2/6] #11705 change name event_custom_id --- pandora_console/extras/mr/67.sql | 2 +- .../godmode/events/custom_events.php | 2 +- pandora_console/include/ajax/events.php | 12 +++++----- pandora_console/include/functions_api.php | 4 ++-- pandora_console/include/functions_events.php | 24 +++++++++---------- .../include/javascript/pandora_events.js | 10 ++++---- .../lib/Dashboard/Widgets/events_list.php | 2 +- pandora_console/operation/events/events.php | 2 +- pandora_console/pandoradb.sql | 2 +- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 92db1c919c..7e598f9bd9 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,6 +1,6 @@ START TRANSACTION; ALTER TABLE `tevento` -ADD COLUMN `custom_field` TEXT NULL AFTER `module_status`; +ADD COLUMN `event_custom_id` 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 bfa6dce937..4ab84fa76b 100644 --- a/pandora_console/godmode/events/custom_events.php +++ b/pandora_console/godmode/events/custom_events.php @@ -115,7 +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'); +$fields_available['event_custom_id'] = __('Event Custom ID'); // Remove fields already selected. diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 517777aacc..0a1d32825f 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -92,7 +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); +$update_event_custom_id = get_parameter('update_event_custom_id', 0); // User private filter. $current_filter = get_parameter('current_filter', 0); $private_filter_event = get_parameter('private_filter_event', 0); @@ -2761,8 +2761,8 @@ if ($draw_row_response_info === true) { return; } -if ($update_custom_field) { - $custom_field = get_parameter('custom_field_value'); +if ($update_event_custom_id) { + $event_custom_id = get_parameter('event_custom_id'); $event_id = get_parameter('event_id'); $server_id = 0; if (is_metaconsole() === true) { @@ -2770,7 +2770,7 @@ if ($update_custom_field) { } // Safe custom fields for hacks. - if (preg_match('/script/i', io_safe_output($custom_field))) { + if (preg_match('/script/i', io_safe_output($event_custom_id))) { $return = false; } else { try { @@ -2781,9 +2781,9 @@ if ($update_custom_field) { $node->connect(); } - $return = events_custom_field( + $return = events_event_custom_id( $event_id, - $custom_field + $event_custom_id ); } catch (\Exception $e) { // Unexistent agent. diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index dc6bdeb30f..6271864b5d 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -17792,7 +17792,7 @@ function api_token_check(string $token) * @param mixed $custom_field Custom field to set. * @return void */ -function api_set_event_custom_field($id, $value) +function api_set_event_custom_id($id, $value) { // Get the event $event = events_get_event($id, false, is_metaconsole()); @@ -17810,7 +17810,7 @@ function api_set_event_custom_field($id, $value) $result = false; } - $result = events_custom_field( + $result = events_event_custom_id( $id, $value ); diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c40a1eb9c7..95f81b90bd 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -219,7 +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'); + $columns['event_custom_id'] = __('Event Custom ID'); return $columns; } @@ -323,8 +323,8 @@ function events_get_column_name($field, $table_alias=false) case 'custom_data': return __('Custom data'); - case 'custom_field': - return __('Custom field'); + case 'event_custom_id': + return __('Event Custom ID'); default: return __($field); @@ -4637,13 +4637,13 @@ function events_page_details($event, $server_id=0) $table_details->data[] = $data; $data = []; - $data[0] = __('Custom Field'); - $data[1] = '
'.html_print_input_text('custom_field', $event['custom_field'], '', false, 255, true, false, false, '', 'w60p'); + $data[0] = __('Event Custom ID'); + $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, false, false, '', 'w60p'); $data[1] .= html_print_button( __('Update'), - 'update_custom_field', + 'update_event_custom_id', false, - 'update_custom_field('.$event['id_evento'].', '.$event['server_id'].');', + 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', [ 'icon' => 'next', 'mode' => 'link', @@ -6228,14 +6228,14 @@ function event_get_counter_extraId(array $event, ?array $filters) /** * Update event detail custom field * - * @param mixed $id_event Event ID or array of events. - * @param string $custom_field Custom_field to be update. + * @param mixed $id_event Event ID or array of events. + * @param string $event_custom_id Event custom ID to be update. * * @return boolean Whether or not it was successful */ -function events_custom_field( +function events_event_custom_id( $id_event, - $custom_field, + $event_custom_id, ) { global $config; // Cleans up the selection for all unwanted values also casts any single @@ -6267,7 +6267,7 @@ function events_custom_field( // Update comment. $ret = db_process_sql_update( 'tevento', - ['custom_field' => $custom_field], + ['event_custom_id' => $event_custom_id], ['id_evento' => $first_event] ); diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index ce782769cb..96f01c2c0d 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -493,13 +493,13 @@ function event_comment(current_event) { } // Save custom_field into an event. -function update_custom_field(event_id, server_id) { - var custom_field_value = $("#text-custom_field").val(); +function update_event_custom_id(event_id, server_id) { + var event_custom_id = $("#text-event_custom_id").val(); var params = { page: "include/ajax/events", - update_custom_field: 1, - custom_field_value: custom_field_value, + update_event_custom_id: 1, + event_custom_id: event_custom_id, event_id: event_id, server_id: server_id }; @@ -514,7 +514,7 @@ function update_custom_field(event_id, server_id) { dataType: "html", success: function(data) { if (data === "update_error") { - alert("Custom field not valid"); + alert("Event Custom ID not valid"); } $("#button-update_custom_field").removeAttr("disabled"); $("#response_loading").hide(); diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index b84f11aa4a..47250e83ac 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -837,7 +837,7 @@ class EventsListWidget extends Widget 'mini_severity' => __('Severity mini'), 'module_custom_id' => __('Module custom ID'), 'custom_data' => __('Custom data'), - 'custom_field' => __('Custom field'), + 'event_custom_id' => __('Event Custom ID'), ]; } diff --git a/pandora_console/operation/events/events.php b/pandora_console/operation/events/events.php index bde20209a4..28d9d9eae3 100644 --- a/pandora_console/operation/events/events.php +++ b/pandora_console/operation/events/events.php @@ -377,7 +377,7 @@ if (is_ajax() === true) { 'te.owner_user', 'if(te.ack_utimestamp > 0, te.ack_utimestamp,"") as ack_utimestamp', 'te.custom_data', - 'te.custom_field', + 'te.event_custom_id', 'te.data', 'te.module_status', 'ta.alias as agent_name', diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 030ef3a76f..36fbc4716b 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -723,7 +723,7 @@ CREATE TABLE IF NOT EXISTS `tevento` ( `custom_data` TEXT, `data` TINYTEXT, `module_status` INT NOT NULL DEFAULT 0, - `custom_field` TEXT, + `event_custom_id` TEXT, PRIMARY KEY (`id_evento`), KEY `idx_agente` (`id_agente`), KEY `idx_agentmodule` (`id_agentmodule`), From 70e3707b64805144d4288a4695b53faac9942220 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 25 Sep 2023 12:22:10 +0200 Subject: [PATCH 3/6] #11705 group extra id heredity event custom id --- pandora_console/godmode/setup/setup_general.php | 2 +- pandora_console/include/functions_api.php | 6 ++++-- pandora_console/include/functions_events.php | 4 +++- pandora_server/lib/PandoraFMS/Core.pm | 6 ++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index aa55893d11..3f4c24fbbf 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -733,7 +733,7 @@ $table->data[$i++][] = html_print_label_input_block( ); $help_tip = ui_print_help_tip( - __('If there are any "In process" events with a specific Extra ID and a New event with that Extra ID is received, it will be created as "In process" instead.'), + __('If there are any "In process" events with a specific Extra ID and a New event with that Extra ID is received, it will be created as "In process" instead. The new events also inherit Event Custom ID'), true ); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 6271864b5d..ee17d7df6d 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13130,7 +13130,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) if ($other['data'][18] != '') { $values['id_extra'] = $other['data'][18]; - $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario + $sql_validation = 'SELECT id_evento,estado,ack_utimestamp,id_usuario,event_custom_id FROM tevento WHERE estado IN (0,2) AND id_extra ="'.$other['data'][18].'";'; @@ -13145,6 +13145,7 @@ function api_set_create_event($id, $trash1, $other, $returnType) $values['status'] = 2; $ack_utimestamp = $val['ack_utimestamp']; $values['id_usuario'] = $val['id_usuario']; + $values['event_custom_id'] = $val['event_custom_id']; } api_set_validate_event_by_id($val['id_evento']); @@ -13175,7 +13176,8 @@ function api_set_create_event($id, $trash1, $other, $returnType) $custom_data, $values['server_id'], $values['id_extra'], - $ack_utimestamp + $ack_utimestamp, + $values['event_custom_id'] ?? null ); if ($other['data'][12] != '') { diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 95f81b90bd..4f016f4f82 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -2339,7 +2339,8 @@ function events_create_event( $custom_data='', $server_id=0, $id_extra='', - $ack_utimestamp=0 + $ack_utimestamp=0, + $event_custom_id=null ) { if ($source === false) { $source = get_product_name(); @@ -2371,6 +2372,7 @@ function events_create_event( 'custom_data' => $custom_data, 'data' => '', 'module_status' => 0, + 'event_custom_id' => $event_custom_id, ]; return (int) db_process_sql_insert('tevento', $values); diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index e7ac485a1d..b2faac90df 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -4160,6 +4160,7 @@ sub pandora_event { my $utimestamp = time (); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); + my $event_custom_id = undef; $id_agentmodule = 0 unless defined ($id_agentmodule); # Validate events with the same event id @@ -4177,6 +4178,7 @@ sub pandora_event { logger($pa_config, "Keeping In process status from last event with extended id '$id_extra'.", 10); $ack_utimestamp = get_db_value ($dbh, 'SELECT ack_utimestamp FROM tevento WHERE id_extra=? AND estado=2', $id_extra); $event_status = 2; + $event_custom_id = get_db_value ($dbh, 'SELECT event_custom_id FROM tevento WHERE id_extra=? AND estado=2', $id_extra); } } @@ -4188,8 +4190,8 @@ sub pandora_event { # Create the event logger($pa_config, "Generating event '$evento' for agent ID $id_agente module ID $id_agentmodule.", 10); - $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status); + $event_id = db_insert ($dbh, 'id_evento','INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, estado, utimestamp, event_type, id_agentmodule, id_alert_am, criticity, tags, source, id_extra, id_usuario, critical_instructions, warning_instructions, unknown_instructions, ack_utimestamp, custom_data, data, module_status, event_custom_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $id_agente, $id_grupo, safe_input ($evento), $timestamp, $event_status, $utimestamp, $event_type, $id_agentmodule, $id_alert_am, $severity, $module_tags, $source, $id_extra, $user_name, $critical_instructions, $warning_instructions, $unknown_instructions, $ack_utimestamp, $custom_data, safe_input($module_data), $module_status, $event_custom_id); if(defined($event_id) && $comment ne '') { my $comment_id = db_insert ($dbh, 'id','INSERT INTO tevent_comment (id_event, utimestamp, comment, id_user, action) From 538cb4f04dc7b259b8f9f0e321e2d8a55b5c2266 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 25 Sep 2023 13:12:07 +0200 Subject: [PATCH 4/6] #11705 cli function update_event_custom_id --- pandora_server/util/pandora_manage.pl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index c63d923402..c35a426e12 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -201,6 +201,7 @@ sub help_screen{ help_screen_line('--disable_double_auth', '', 'Disable the double authentication for the specified user'); print "\nEVENTS:\n\n" unless $param ne ''; help_screen_line('--create_event', " [ \n\t \n\t \n\t ]", 'Add event'); + help_screen_line('--update_event_custom_id', " ", 'Update Event Custom ID'); help_screen_line('--validate_event', " \n\t []", 'Validate events'); help_screen_line('--validate_event_id', '', 'Validate event given a event id'); help_screen_line('--get_event_info', '[]', 'Show info about a event given a event id'); @@ -4549,6 +4550,17 @@ sub cli_create_event() { } } +############################################################################## +# Update event custom id +# Related option: --update_event_custom_id +############################################################################## + +sub cli_update_event_custom_id() { + my ($id_event, $event_custom_id) = @ARGV[2..3]; + my $result = api_call(\%conf, 'set', 'event_custom_id', $id_event, $event_custom_id); + print "\n$result\n"; +} + ############################################################################## # Validate event. # Related option: --validate_event @@ -8318,6 +8330,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 4, 0); cli_insert_gis_data(); } + elsif ($param eq '--update_event_custom_id'){ + param_check($ltotal, 2); + cli_update_event_custom_id(); + } else { print_log "[ERROR] Invalid option '$param'.\n\n"; $param = ''; From 63b069d739e7aa85f4e36108624aec7a71964e91 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 22 Nov 2023 11:20:46 +0100 Subject: [PATCH 5/6] #11705 fix for id as array --- pandora_console/include/functions_events.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index c680460ec2..07953c1994 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -6245,7 +6245,10 @@ function events_event_custom_id( global $config; // Cleans up the selection for all unwanted values also casts any single // values as an array. - $id_event = (array) safe_int($id_event, 1); + if (![$id_event]) { + $id_event = (array) safe_int($id_event, 1); + } + // Check ACL. foreach ($id_event as $k => $id) { $event_group = events_get_group($id); From 11cc31c0adb7cf48362a031cdfa703b7aed7d751 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 Nov 2023 10:23:57 +0100 Subject: [PATCH 6/6] #11705 Event custom id edit by EW only --- pandora_console/include/functions_events.php | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index a7bd74096e..dada577ac8 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -4636,21 +4636,29 @@ function events_page_details($event, $server_id=0) } $table_details->data[] = $data; + $readonly = true; + if (check_acl($config['id_user'], 0, 'EW')) { + $readonly = false; + } $data = []; $data[0] = __('Event Custom ID'); - $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, false, false, '', 'w60p'); - $data[1] .= html_print_button( - __('Update'), - 'update_event_custom_id', - false, - 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', - [ - 'icon' => 'next', - 'mode' => 'link', - ], - true - ).'
'; + $data[1] = '
'.html_print_input_text('event_custom_id', $event['event_custom_id'], '', false, 255, true, $readonly, false, '', 'w60p'); + if ($readonly === false) { + $data[1] .= html_print_button( + __('Update'), + 'update_event_custom_id', + false, + 'update_event_custom_id('.$event['id_evento'].', '.$event['server_id'].');', + [ + 'icon' => 'next', + 'mode' => 'link', + ], + true + ); + } + + $data[1] .= '
'; $table_details->data[] = $data; $details = '
'.html_print_table($table_details, true).'
';