From 7676852bd0ea3ca27b434dde9d3ed67f14a34c52 Mon Sep 17 00:00:00 2001 From: marcos Date: Tue, 2 Jun 2020 17:26:43 +0200 Subject: [PATCH 1/5] set event in progress on api --- pandora_console/include/functions_api.php | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 76e10533aa..82538fa1ee 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -16021,3 +16021,49 @@ function api_get_event_mcid($server_id, $console_event_id, $trash2, $returnType) return; } } + + +/** + * Function to set events in progress status. + * + * @param [int] $event_id Id event (Node or Meta). + * @param [int] $server_id Id node event in tmetaconsole_event. + * @param [string] $trash2 don't use. + * @param [string] $returnType + * + * Example + * http://172.17.0.1/pandora_console/include/api.php?op=set&op2=event_in_progress&return_type=json&id=0&id2=0&apipass=1234&user=admin&pass=pandora + * + * @return void + */ +function api_set_event_in_progress($event_id, $server_id, $trash2, $returnType) +{ + global $config; + + if (is_metaconsole()) { + $event = db_process_sql_update( + 'tmetaconsole_event', + ['estado' => 2], + [ + 'id_source_event' => $event_id, + 'server_id' => $server_id, + ] + ); + if ($event !== false) { + returnData($returnType, ['type' => 'string', 'data' => $event]); + } else { + returnError('id_not_found', 'string'); + } + } else { + $event = db_process_sql_update( + 'tevento', + ['estado' => 2], + ['id_evento' => $event_id] + ); + if ($event !== false) { + returnData($returnType, ['type' => 'string', 'data' => $event]); + } else { + returnError('id_not_found', 'string'); + } + } +} From e270776a01011015ccdca34de347a6a9e95ce27d Mon Sep 17 00:00:00 2001 From: marcos Date: Wed, 3 Jun 2020 15:56:19 +0200 Subject: [PATCH 2/5] create new api/cli function to set event on progress --- pandora_console/include/functions_api.php | 8 ++++---- pandora_server/util/pandora_manage.pl | 24 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 82538fa1ee..f5fb12ee1d 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -16027,12 +16027,12 @@ function api_get_event_mcid($server_id, $console_event_id, $trash2, $returnType) * Function to set events in progress status. * * @param [int] $event_id Id event (Node or Meta). - * @param [int] $server_id Id node event in tmetaconsole_event. + * @param [int] $server_id Id node event in tmetaconsole_event (optional). * @param [string] $trash2 don't use. * @param [string] $returnType * * Example - * http://172.17.0.1/pandora_console/include/api.php?op=set&op2=event_in_progress&return_type=json&id=0&id2=0&apipass=1234&user=admin&pass=pandora + * http://127.0.0.1/pandora_console/include/api.php?op=set&op2=event_in_progress&return_type=json&id=0&id2=0&apipass=1234&user=admin&pass=pandora * * @return void */ @@ -16045,8 +16045,8 @@ function api_set_event_in_progress($event_id, $server_id, $trash2, $returnType) 'tmetaconsole_event', ['estado' => 2], [ - 'id_source_event' => $event_id, - 'server_id' => $server_id, + 'server_id' => $server_id, + 'id_evento' => $event_id, ] ); if ($event !== false) { diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 839d937db3..ee7ea1586b 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -243,6 +243,8 @@ sub help_screen{ help_screen_line('--duplicate_visual_console', ' []', 'Duplicate a visual console'); help_screen_line('--export_json_visual_console', ' [] []', 'Creates a json with the visual console elements information'); + print "\nEVENTS\n\n" unless $param ne ''; + help_screen_line('--event_in_progress', ' ', 'Set event in progress'); print "\n"; exit; @@ -254,7 +256,7 @@ sub help_screen{ sub api_call($$$;$$$$) { my ($pa_config, $op, $op2, $id, $id2, $other, $return_type) = @_; my $content = undef; - + eval { # Set the parameters for the POST request. my $params = {}; @@ -7676,6 +7678,9 @@ sub pandora_manage_main ($$$) { elsif ($param eq '--reset_agent_counts') { param_check($ltotal, 1, 0); cli_reset_agent_counts(); + }elsif ($param eq '--event_in_progress') { + param_check($ltotal, 2, 0); + cli_event_in_progress(); } else { print_log "[ERROR] Invalid option '$param'.\n\n"; @@ -8325,3 +8330,20 @@ sub cli_reset_agent_counts() { print "$result \n\n "; } + + +############################################################################## +# Set an event in progress. +# Related option: --event_in_progress +############################################################################## + +sub cli_event_in_progress() { + my ($event_id, $server_id) = @ARGV[2..3]; + + # Call the API. + my $result = api_call( + $conf, 'set', 'event_in_progress', $event_id, $server_id + ); + + print "\n$result\n"; +} \ No newline at end of file From 9632b36551697f983ea08376079c803edc7adce2 Mon Sep 17 00:00:00 2001 From: marcos Date: Wed, 15 Jul 2020 23:36:21 +0200 Subject: [PATCH 3/5] changed event in progress method --- pandora_console/include/functions_api.php | 10 +++------- pandora_server/util/pandora_manage.pl | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 0bd21d7562..28150d82aa 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -16157,16 +16157,15 @@ function api_get_event_mcid($server_id, $console_event_id, $trash2, $returnType) * Function to set events in progress status. * * @param [int] $event_id Id event (Node or Meta). - * @param [int] $server_id Id node event in tmetaconsole_event (optional). * @param [string] $trash2 don't use. * @param [string] $returnType * * Example - * http://127.0.0.1/pandora_console/include/api.php?op=set&op2=event_in_progress&return_type=json&id=0&id2=0&apipass=1234&user=admin&pass=pandora + * http://127.0.0.1/pandora_console/include/api.php?op=set&op2=event_in_progress&return_type=json&id=0&apipass=1234&user=admin&pass=pandora * * @return void */ -function api_set_event_in_progress($event_id, $server_id, $trash2, $returnType) +function api_set_event_in_progress($event_id, $trash2, $returnType) { global $config; @@ -16174,10 +16173,7 @@ function api_set_event_in_progress($event_id, $server_id, $trash2, $returnType) $event = db_process_sql_update( 'tmetaconsole_event', ['estado' => 2], - [ - 'server_id' => $server_id, - 'id_evento' => $event_id, - ] + ['id_evento' => $event_id] ); if ($event !== false) { returnData($returnType, ['type' => 'string', 'data' => $event]); diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 5f428706f2..d4aefe4cdf 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -245,7 +245,7 @@ sub help_screen{ help_screen_line('--export_json_visual_console', ' [] []', 'Creates a json with the visual console elements information'); print "\nEVENTS\n\n" unless $param ne ''; - help_screen_line('--event_in_progress', ' ', 'Set event in progress'); + help_screen_line('--event_in_progress', ' ', 'Set event in progress'); print "\n"; exit; @@ -7714,7 +7714,7 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 1, 0); cli_reset_agent_counts(); }elsif ($param eq '--event_in_progress') { - param_check($ltotal, 2, 0); + param_check($ltotal, 1, 0); cli_event_in_progress(); } else { @@ -8373,11 +8373,11 @@ sub cli_reset_agent_counts() { ############################################################################## sub cli_event_in_progress() { - my ($event_id, $server_id) = @ARGV[2..3]; + my $event_id = @ARGV[2]; # Call the API. my $result = api_call( - $conf, 'set', 'event_in_progress', $event_id, $server_id + $conf, 'set', 'event_in_progress', $event_id ); print "\n$result\n"; From a6a97d264eccbfde0a350616c970878bbcb12669 Mon Sep 17 00:00:00 2001 From: marcos Date: Wed, 15 Jul 2020 23:41:25 +0200 Subject: [PATCH 4/5] changed event in progress method api refactored --- pandora_console/include/functions_api.php | 35 +++++++++-------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 28150d82aa..3013c186f1 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -16168,28 +16168,21 @@ function api_get_event_mcid($server_id, $console_event_id, $trash2, $returnType) function api_set_event_in_progress($event_id, $trash2, $returnType) { global $config; - if (is_metaconsole()) { - $event = db_process_sql_update( - 'tmetaconsole_event', - ['estado' => 2], - ['id_evento' => $event_id] - ); - if ($event !== false) { - returnData($returnType, ['type' => 'string', 'data' => $event]); - } else { - returnError('id_not_found', 'string'); - } + $table = 'tmetaconsole_event'; } else { - $event = db_process_sql_update( - 'tevento', - ['estado' => 2], - ['id_evento' => $event_id] - ); - if ($event !== false) { - returnData($returnType, ['type' => 'string', 'data' => $event]); - } else { - returnError('id_not_found', 'string'); - } + $table = 'tevento'; + } + + $event = db_process_sql_update( + $table, + ['estado' => 2], + ['id_evento' => $event_id] + ); + + if ($event !== false) { + returnData($returnType, ['type' => 'string', 'data' => $event]); + } else { + returnError('id_not_found', 'string'); } } From 10b2fe25ba4ed39f1242aeb8180338c8bb0c7cd4 Mon Sep 17 00:00:00 2001 From: marcos Date: Thu, 16 Jul 2020 10:57:27 +0200 Subject: [PATCH 5/5] fixed error --- pandora_console/include/functions_api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 3013c186f1..2dcffa5ced 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -16181,7 +16181,7 @@ function api_set_event_in_progress($event_id, $trash2, $returnType) ); if ($event !== false) { - returnData($returnType, ['type' => 'string', 'data' => $event]); + returnData('string', ['data' => $event]); } else { returnError('id_not_found', 'string'); }