fixed api function add comment for metaconsole pandora_enterprise#9522

This commit is contained in:
Daniel Barbero 2022-09-20 11:53:56 +02:00
parent 9ae4c7ca67
commit e3579f2b13
1 changed files with 39 additions and 12 deletions

View File

@ -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.'