From e3579f2b13733afe42d180ed2208df2f1af85863 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Tue, 20 Sep 2022 11:53:56 +0200 Subject: [PATCH] fixed api function add comment for metaconsole pandora_enterprise#9522 --- pandora_console/include/functions_api.php | 51 +++++++++++++++++------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index d711432ef9..6290d95a34 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -13362,12 +13362,6 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3) { global $config; - if (defined('METACONSOLE')) { - $meta = true; - } else { - $meta = $other['data'][1]; - } - if (!check_acl($config['id_user'], 0, 'EW')) { returnError('forbidden', 'string'); return; @@ -13378,13 +13372,46 @@ function api_set_add_event_comment($id, $thrash2, $other, $thrash3) return; } else if ($other['type'] == 'array') { $comment = $other['data'][0]; - $history = $other['data'][2]; - $status = events_comment( - $id, - $comment, - 'Added comment' - ); + $node_int = 0; + if (is_metaconsole() === true) { + if (isset($other['data'][1]) === true + && empty($other['data'][1]) === false + ) { + $node_int = $other['data'][1]; + } + } + + try { + if (is_metaconsole() === true + && (int) $node_int > 0 + ) { + $node = new Node($node_int); + $node->connect(); + } + + $status = events_comment( + $id, + $comment, + 'Added comment' + ); + } catch (\Exception $e) { + // Unexistent agent. + if (is_metaconsole() === true + && $node_int > 0 + ) { + $node->disconnect(); + } + + $status = false; + } finally { + if (is_metaconsole() === true + && $node_int > 0 + ) { + $node->disconnect(); + } + } + if (is_error($status)) { returnError( 'The event comment could not be added.'