From d49f1320f53474739a82e711fa07c04fe36a0385 Mon Sep 17 00:00:00 2001
From: Daniel Cebrian <daniel.cebrian@pandorafms.com>
Date: Tue, 31 Jan 2023 12:37:55 +0100
Subject: [PATCH] #10127 added param 'id_node' in set_validate_events for
 update from metaconsole

---
 pandora_console/include/functions_api.php | 47 ++++++++++++++++++++---
 1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php
index 89e764aaaa..11149e86f8 100644
--- a/pandora_console/include/functions_api.php
+++ b/pandora_console/include/functions_api.php
@@ -11061,20 +11061,55 @@ function api_set_event_validate_filter($trash1, $trash2, $other, $trash3)
 
 function api_set_validate_events($id_event, $trash1, $other, $return_type, $user_in_db)
 {
-    $text = $other['data'];
+    $node_int = 0;
+    if ($other['type'] == 'string') {
+        returnError('Parameter error.');
+        return;
+    } else if ($other['type'] == 'array') {
+        $text = $other['data'][0];
+        if (is_metaconsole() === true) {
+            if (isset($other['data'][1]) === true
+                && empty($other['data'][1]) === false
+            ) {
+                $node_int = $other['data'][1];
+            }
+        }
+    }
 
-    // Set off the standby mode when close an event
-    $event = events_get_event($id_event);
-    alerts_agent_module_standby($event['id_alert_am'], 0);
+    try {
+        if (is_metaconsole() === true
+            && (int) $node_int > 0
+        ) {
+            $node = new Node($node_int);
+            $node->connect();
+        }
 
-    $result = events_change_status($id_event, EVENT_VALIDATE);
+        // Set off the standby mode when close an event
+        $event = events_get_event($id_event);
+        alerts_agent_module_standby($event['id_alert_am'], 0);
+        $result = events_change_status($id_event, EVENT_VALIDATE);
 
-    if ($result) {
         if (!empty($text)) {
             // Set the comment for the validation
             events_comment($id_event, $text);
         }
+    } catch (\Exception $e) {
+        if (is_metaconsole() === true
+            && $node_int > 0
+        ) {
+            $node->disconnect();
+        }
 
+        $result = false;
+    } finally {
+        if (is_metaconsole() === true
+            && $node_int > 0
+        ) {
+            $node->disconnect();
+        }
+    }
+
+    if ($result) {
         returnData(
             'string',
             [