From af23275f5d3f5fc6a2df61952a4a5ad73567c2a7 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 26 Feb 2024 14:41:09 +0100 Subject: [PATCH] fix api call --- pandora_console/include/functions_api.php | 48 +++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 29feaa253f..b70827b856 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13270,7 +13270,7 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3) } else if ($other['type'] == 'array') { $comment = $other['data'][0]; - $node_int = 0; + $node_int = 0; if (is_metaconsole() === true) { if (isset($other['data'][1]) === true && empty($other['data'][1]) === false @@ -17806,8 +17806,8 @@ function api_token_check(string $token) * @param mixed $custom_field Custom field to set. * @return void */ -function api_set_event_custom_id($id, $value) -{ +function api_set_event_custom_id($id, $value, $other) +{ // Get the event $event = events_get_event($id, false, is_metaconsole()); // If event not exists, end the execution. @@ -17824,10 +17824,44 @@ function api_set_event_custom_id($id, $value) $result = false; } - $result = events_event_custom_id( - $id, - $value - ); + $node_id = 0; + + if (is_metaconsole() === true) { + if (isset($other['data'][0]) === true + && empty($other['data'][0]) === false + ) { + $node_id = $other['data'][0]; + } + } + + try { + if (is_metaconsole() === true + && (int) $node_id > 0 + ) { + $node = new Node($node_id); + $node->connect(); + } + + $result = events_event_custom_id( + $id, + $value + ); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $node_id > 0 + ) { + $node->disconnect(); + } + + $status = false; + } finally { + if (is_metaconsole() === true + && $node_id > 0 + ) { + $node->disconnect(); + } + } // If update results failed if (empty($result) === true || $result === false) {