From aaae7454fa4f73acb35a575cd00886a061f20e0c Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 6 Feb 2023 10:37:01 +0100 Subject: [PATCH 1/3] #10259 create control for token agentaccess if agents morte than 200 --- pandora_console/godmode/setup/performance.php | 5 ++- .../include/class/ConsoleSupervisor.php | 39 +++++++++++++++++++ .../include/functions_notifications.php | 1 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 969ff868c1..05b0bbdf26 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -151,6 +151,9 @@ if ($update_config == 1 && $config['history_db_enabled'] == 1) { } } +$total_agents = db_get_value('count(*)', 'tagente'); +$disable_agentaccess = ($total_agents >= 200) ? true : false; + $table_status = new StdClass(); $table_status->width = '100%'; $table_status->class = 'databox filters'; @@ -577,7 +580,7 @@ $table_other->data[$i++][1] = html_print_input_text( ); $table_other->data[$i][0] = __('Use agent access graph'); -$table_other->data[$i++][1] = html_print_checkbox_switch('agentaccess', 1, $config['agentaccess'], true); +$table_other->data[$i++][1] = html_print_checkbox_switch('agentaccess', 1, $config['agentaccess'], true, $disable_agentaccess); $table_other->data[$i][0] = __('Max. recommended number of files in attachment directory'); $table_other->data[$i++][1] = html_print_input_text( diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index b6a6d3df43..ce6d2df301 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -258,6 +258,11 @@ class ConsoleSupervisor $this->checkSyncQueueStatus(); } + /* + * Check number of agents is equals and more than 200. + * NOTIF.ACCESSSTASTICS.PERFORMANCE + */ + $this->checkAccessStatisticsPerformance(); } @@ -518,6 +523,12 @@ class ConsoleSupervisor $this->checkSyncQueueLength(); $this->checkSyncQueueStatus(); } + + /* + * Check number of agents is equals and more than 200. + * NOTIF.ACCESSSTASTICS.PERFORMANCE + */ + $this->checkAccessStatisticsPerformance(); } @@ -532,6 +543,34 @@ class ConsoleSupervisor } + /** + * Check number of agents and disable agentaccess token if number + * is equals and more than 200. + * + * @return void + */ + public function checkAccessStatisticsPerformance() + { + $total_agents = db_get_value('count(*)', 'tagente'); + + if ($total_agents >= 200) { + db_process_sql_update('tconfig', ['value' => 0], ['token' => 'agentaccess']); + $this->notify( + [ + 'type' => 'NOTIF.ACCESSSTASTICS.PERFORMANCE', + 'title' => __('Access statistics performance'), + 'message' => __( + 'Usage of agent access statistics IS NOT RECOMMENDED on systems with more than 200 agents due performance penalty' + ), + 'url' => '__url__/index.php?sec=general&sec2=godmode/setup/setup§ion=perf', + ] + ); + } else { + $this->cleanNotifications('NOTIF.ACCESSSTASTICS.PERFORMANCE'); + } + } + + /** * Update targets for given notification using object targets. * diff --git a/pandora_console/include/functions_notifications.php b/pandora_console/include/functions_notifications.php index 705d67ab3b..8ed023ddde 100644 --- a/pandora_console/include/functions_notifications.php +++ b/pandora_console/include/functions_notifications.php @@ -159,6 +159,7 @@ function notifications_get_subtypes(?string $source=null) 'NOTIF.SERVER.STATUS', 'NOTIF.SERVER.QUEUE', 'NOTIF.SERVER.MASTER', + 'NOTIF.ACCESSSTASTICS.PERFORMANCE', ], ]; From fecee4895f234509784eb023bb5c4412bc1685ce Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Mon, 6 Feb 2023 11:04:08 +0100 Subject: [PATCH 2/3] #10259 fixed bug in agentaccess token --- pandora_console/godmode/setup/performance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 05b0bbdf26..1e0fc4df69 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -152,7 +152,7 @@ if ($update_config == 1 && $config['history_db_enabled'] == 1) { } $total_agents = db_get_value('count(*)', 'tagente'); -$disable_agentaccess = ($total_agents >= 200) ? true : false; +$disable_agentaccess = ($total_agents >= 200 && $config['agentaccess'] == 0) ? true : false; $table_status = new StdClass(); $table_status->width = '100%'; From c7e53f5a1a50f704436c0b206981173fdda2167c Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Fri, 24 Feb 2023 12:07:37 +0100 Subject: [PATCH 3/3] #10259 resolve conflics --- .../include/class/ConsoleSupervisor.php | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index ce6d2df301..837be70906 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -262,7 +262,17 @@ class ConsoleSupervisor * Check number of agents is equals and more than 200. * NOTIF.ACCESSSTASTICS.PERFORMANCE */ + $this->checkAccessStatisticsPerformance(); + + /* + * Checkc agent missing libraries. + * NOTIF.AGENT.LIBRARY + */ + + if ((bool) enterprise_installed() === true) { + $this->checkLibaryError(); + } } @@ -528,7 +538,18 @@ class ConsoleSupervisor * Check number of agents is equals and more than 200. * NOTIF.ACCESSSTASTICS.PERFORMANCE */ + $this->checkAccessStatisticsPerformance(); + + /* + * Checkc agent missing libraries. + * NOTIF.AGENT.LIBRARY + */ + + if ((bool) enterprise_installed() === true) { + $this->checkLibaryError(); + } + } @@ -2418,7 +2439,7 @@ class ConsoleSupervisor if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') { $message_conf_cron .= __('Discovery relies on an appropriate cron setup.'); $message_conf_cron .= '. '.__('Please, add the following line to your crontab file:'); - $message_conf_cron .= '
* * * * * <user> wget -q -O - --no-check-certificate ';
+                $message_conf_cron .= '
* * * * * <user> wget -q -O - --no-check-certificate --load-cookies /tmp/cron-session-cookies --save-cookies /tmp/cron-session-cookies --keep-session-cookies ';
                 $message_conf_cron .= str_replace(
                     ENTERPRISE_DIR.'/meta/',
                     '',
@@ -2845,4 +2866,30 @@ class ConsoleSupervisor
     }
 
 
+    /**
+     * Chechs if an agent has a dependency eror on omnishell
+     *
+     * @return void
+     */
+    public function checkLibaryError()
+    {
+        $sql = 'SELECT COUNT(errorlevel) from tremote_command_target WHERE errorlevel = 2';
+
+        $error_dependecies = db_get_sql($sql);
+        if ($error_dependecies > 0) {
+            $this->notify(
+                [
+                    'type'    => 'NOTIF.AGENT.LIBRARY',
+                    'title'   => __('Agent dependency error'),
+                    'message' => __(
+                        'There are omnishell agents with dependency errors',
+                    ),
+
+                    'url'     => '__url__/index.php?sec=gextensions&sec2=enterprise/tools/omnishell',
+                ]
+            );
+        }
+    }
+
+
 }