From 3f41e4f32bf747584e64ba2a23cbcfb94a54a7d2 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Mon, 2 Oct 2023 16:24:23 +0200 Subject: [PATCH] #12138 delete agent access graph --- pandora_console/godmode/db/db_main.php | 13 --- pandora_console/godmode/setup/performance.php | 13 ++- .../include/class/ConsoleSupervisor.php | 46 ---------- .../include/class/Diagnostics.class.php | 23 ++--- pandora_console/include/functions_config.php | 8 -- pandora_console/include/functions_graph.php | 86 ------------------- .../include/functions_treeview.php | 21 ----- .../agentes/estado_generalagente.php | 56 ------------ pandora_console/pandoradb.sql | 12 +-- pandora_server/lib/PandoraFMS/Config.pm | 4 +- pandora_server/lib/PandoraFMS/Core.pm | 25 +++--- pandora_server/util/pandora_db.pl | 36 ++++---- pandora_server/util/pandora_perf_report.pl | 18 ++-- 13 files changed, 60 insertions(+), 301 deletions(-) diff --git a/pandora_console/godmode/db/db_main.php b/pandora_console/godmode/db/db_main.php index 9979b2c224..3bd4052ba2 100644 --- a/pandora_console/godmode/db/db_main.php +++ b/pandora_console/godmode/db/db_main.php @@ -27,7 +27,6 @@ if (! check_acl($config['id_user'], 0, 'DM')) { // Get some general DB stats (not very heavy) // NOTE: this is not realtime monitoring stats, are more focused on DB sanity -$stat_access = db_get_sql('SELECT COUNT(*) FROM tagent_access WHERE id_agent != 0'); $stat_data = db_get_sql('SELECT COUNT(*) FROM tagente_datos WHERE id_agente_modulo != 0'); $stat_data_log4x = db_get_sql('SELECT COUNT(*) FROM tagente_datos_log4x WHERE id_agente_modulo != 0'); $stat_data_string = db_get_sql('SELECT COUNT(*) FROM tagente_datos_string WHERE id_agente_modulo != 0'); @@ -149,18 +148,6 @@ echo $stat_modules; echo ''; - -echo ''; -echo __('Total agent access records'); -echo ''; -if ($stat_access > $max_access) { - echo "$stat_access"; -} else { - echo $stat_access; -} - -echo ''; - // Sanity echo ''; echo __('Database sanity'); diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index 51cd554a66..870c4c283a 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -154,8 +154,7 @@ if ($update_config == 1 && $config['history_db_enabled'] == 1) { $performance_variables_control = (array) json_decode(io_safe_output($config['performance_variables_control'])); $total_agents = db_get_value('count(*)', 'tagente'); -$disable_agentaccess = ($total_agents >= 200 && $config['agentaccess'] == 0) ? true : false; - +// $disable_agentaccess = ($total_agents >= 200 && $config['agentaccess'] == 0) ? true : false; $table_status = new StdClass(); $table_status->width = '100%'; $table_status->class = 'databox filters'; @@ -666,8 +665,8 @@ $table_other->data[2][1] = html_print_label_input_block( true ) ); - -$table_other->data[3][0] = html_print_label_input_block( +/* + $table_other->data[3][0] = html_print_label_input_block( __('Use agent access graph'), html_print_checkbox_switch( 'agentaccess', @@ -676,9 +675,9 @@ $table_other->data[3][0] = html_print_label_input_block( true, $disable_agentaccess ) -); - -$table_other->data[3][1] = html_print_label_input_block( + ); +*/ +$table_other->data[3][0] = html_print_label_input_block( __('Max. recommended number of files in attachment directory'), html_print_input_text( 'num_files_attachment', diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index a434a30e7f..6ecd80ec9a 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -270,13 +270,6 @@ class ConsoleSupervisor $this->checkSyncQueueStatus(); } - /* - * Check number of agents is equals and more than 200. - * NOTIF.ACCESSSTASTICS.PERFORMANCE - */ - - $this->checkAccessStatisticsPerformance(); - /* * Checkc agent missing libraries. * NOTIF.AGENT.LIBRARY @@ -570,13 +563,6 @@ class ConsoleSupervisor $this->checkSyncQueueStatus(); } - /* - * Check number of agents is equals and more than 200. - * NOTIF.ACCESSSTASTICS.PERFORMANCE - */ - - $this->checkAccessStatisticsPerformance(); - /* * Checkc agent missing libraries. * NOTIF.AGENT.LIBRARY @@ -704,38 +690,6 @@ class ConsoleSupervisor } - /** - * Check number of agents and disable agentaccess token if number - * is equals and more than 200. - * - * @return void - */ - public function checkAccessStatisticsPerformance() - { - global $config; - - $total_agents = db_get_value('count(*)', 'tagente'); - - if ($total_agents >= 200) { - if ((int) $config['agentaccess'] !== 0) { - 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/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 7d7532189c..aa5d5995af 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -580,9 +580,6 @@ class Diagnostics extends Wizard $countModuleData = db_get_value_sql( 'SELECT COUNT(*) FROM tagente_datos' ); - $countAgentAccess = db_get_value_sql( - 'SELECT COUNT(*) FROM tagent_access' - ); $countEvents = db_get_value_sql('SELECT COUNT(*) FROM tevento'); if (enterprise_installed() === true) { @@ -595,39 +592,35 @@ class Diagnostics extends Wizard $result = [ 'error' => false, 'data' => [ - 'countAgents' => [ + 'countAgents' => [ 'name' => __('Total agents'), 'value' => $countAgents, ], - 'countModules' => [ + 'countModules' => [ 'name' => __('Total modules'), 'value' => $countModules, ], - 'countGroups' => [ + 'countGroups' => [ 'name' => __('Total groups'), 'value' => $countGroups, ], - 'countModuleData' => [ + 'countModuleData' => [ 'name' => __('Total module data records'), 'value' => $countModuleData, ], - 'countAgentAccess' => [ - 'name' => __('Total agent access record'), - 'value' => $countAgentAccess, - ], - 'countEvents' => [ + 'countEvents' => [ 'name' => __('Total events'), 'value' => $countEvents, ], - 'countTraps' => [ + 'countTraps' => [ 'name' => __('Total traps'), 'value' => $countTraps, ], - 'countUsers' => [ + 'countUsers' => [ 'name' => __('Total users'), 'value' => $countUsers, ], - 'countSessions' => [ + 'countSessions' => [ 'name' => __('Total sessions'), 'value' => $countSessions, ], diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 28f5f695cd..19e3160476 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -913,10 +913,6 @@ function config_update_config() $error_update[] = __('Batch statistics period (secs)'); } - if (config_update_value('agentaccess', (int) get_parameter('agentaccess'), true) === false) { - $error_update[] = __('Use agent access graph'); - } - if (config_update_value('num_files_attachment', (int) get_parameter('num_files_attachment'), true) === false) { $error_update[] = __('Max. recommended number of files in attachment directory'); } @@ -2232,10 +2228,6 @@ function config_process_config() config_update_value('show_qr_code_header', false); } - if (!isset($config['agentaccess'])) { - config_update_value('agentaccess', true); - } - if (!isset($config['timezone'])) { config_update_value('timezone', 'Europe/Berlin'); } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index e6605a488b..762f04810e 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2523,92 +2523,6 @@ function combined_graph_summatory_average( } -/** - * Print a graph with access data of agents. - * - * @param integer $id_agent Agent Id. - * @param integer $period Timestamp period graph. - * @param boolean|null $return Type return. - * - * @return string - */ -function graphic_agentaccess( - int $id_agent, - int $period=0, - ?bool $return=false, - ?bool $agent_view=false -) { - global $config; - - // Dates. - $date = get_system_time(); - $datelimit = ($date - $period); - $interval = 3600; - - // Query. - $sql = sprintf( - 'SELECT utimestamp, count(*) as data - FROM tagent_access - WHERE id_agent = %d - AND utimestamp >= %d - AND utimestamp <= %d - GROUP BY TRUNCATE(utimestamp/%d,0)', - $id_agent, - $datelimit, - $date, - $interval - ); - - $data = db_get_all_rows_sql($sql); - - // Array data. - $data_array = []; - $colors = []; - if (isset($data) === true && is_array($data) === true) { - foreach ($data as $value) { - $time = io_safe_output(date('H:m', $value['utimestamp'])); - $labels[] = $time; - $data_array[] = [ - 'y' => (int) $value['data'], - 'x' => $time, - ]; - - $colors[] = '#82b92f'; - } - } - - $options = []; - $options['grid']['hoverable'] = true; - - if ($agent_view === true) { - $options['agent_view'] = true; - } - - $options = [ - 'height' => 125, - 'colors' => $colors, - 'legend' => ['display' => false], - 'scales' => [ - 'x' => [ - 'grid' => ['display' => false], - 'ticks' => [ - 'fonts' => ['size' => 8], - ], - ], - 'y' => [ - 'grid' => ['display' => false], - 'ticks' => [ - 'fonts' => ['size' => 8], - ], - ], - ], - 'labels' => $labels, - ]; - - return vbar_graph($data_array, $options); -} - - /** * Print a pie graph with alerts defined/fired data * diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index 47f861314a..bc2271606e 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -796,27 +796,6 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) 'white_table_flex' ); - if ($config['agentaccess']) { - $access_graph = '
'; - $access_graph .= graphic_agentaccess( - $id_agente, - SECONDS_1DAY, - false - ); - $access_graph .= '
'; - ui_toggle( - $access_graph, - ''.__('Agent access rate (24h)').'', - '', - '', - true, - false, - '', - 'white-box-content mrgn_top_0 mrgn_btn_0px border-bottom-gray', - 'white_table_flex' - ); - } - // Table network interfaces. $network_interfaces_by_agents = agents_get_network_interfaces([$agent]); diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 62963f6b29..4a57231242 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -313,55 +313,6 @@ for ($i = 0; $i < $custom_fields_count; $i++) { * END: TABLE DATA BUILD */ -/* - * START: ACCESS RATE GRAPH - */ - -$access_agent = db_get_value_sql( - 'SELECT COUNT(id_agent) - FROM tagent_access - WHERE id_agent = '.$id_agente -); - -if ((bool) $config['agentaccess'] === true && $access_agent > 0) { - $agentAccessRateHeader = html_print_div( - [ - 'class' => 'agent_details_header', - 'content' => ''.__('Agent access rate (Last 24h)').'', - ], - true - ); - - $agentAccessRateContent = html_print_div( - [ - 'class' => 'white-table-graph-content', - 'content' => graphic_agentaccess( - $id_agente, - SECONDS_1DAY, - true, - true - ), - ], - true - ); - - $agentAccessRate = html_print_div( - [ - 'class' => 'box-flat agent_details_col mrgn_lft_20px w50p', - 'id' => 'table_access_rate', - 'content' => $agentAccessRateHeader.$agentAccessRateContent, - ], - true - ); -} else { - $agentAccessRate = ''; -} - -/* - * END: ACCESS RATE GRAPH - */ - - /* * START: TABLE INTERFACES */ @@ -595,13 +546,6 @@ html_print_div( ] ); -html_print_div( - [ - 'class' => 'agent_details_line', - 'content' => $agentEvents.$agentAccessRate, - ] -); - if (empty($agentAdditionalInfo) === false) { html_print_div( [ diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index b44fb54e92..2435813cd1 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -290,12 +290,12 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` ( -- ----------------------------------------------------- -- Table `tagent_access` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `tagent_access` ( - `id_agent` INT UNSIGNED NOT NULL DEFAULT 0, - `utimestamp` BIGINT NOT NULL DEFAULT 0, - KEY `agent_index` (`id_agent`), - KEY `idx_utimestamp` USING BTREE (`utimestamp`) -) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +-- CREATE TABLE IF NOT EXISTS `tagent_access` ( +-- `id_agent` INT UNSIGNED NOT NULL DEFAULT 0, +-- `utimestamp` BIGINT NOT NULL DEFAULT 0, +-- KEY `agent_index` (`id_agent`), +-- KEY `idx_utimestamp` USING BTREE (`utimestamp`) +-- ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ----------------------------------------------------- -- Table `talert_snmp` diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index 8feacb839e..8527d47e27 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -128,7 +128,7 @@ sub pandora_get_sharedconfig ($$) { my ($pa_config, $dbh) = @_; # Agentaccess option - $pa_config->{"agentaccess"} = pandora_get_tconfig_token ($dbh, 'agentaccess', 1); + #$pa_config->{"agentaccess"} = pandora_get_tconfig_token ($dbh, 'agentaccess', 1); # Realtimestats 0 disabled, 1 enabled. # Master servers will generate all the information (global tactical stats). @@ -458,7 +458,7 @@ sub pandora_load_config { # don't get an error later. $pa_config->{"realtimestats"} = 0; $pa_config->{"stats_interval"} = 300; - $pa_config->{"agentaccess"} = 1; + #$pa_config->{"agentaccess"} = 1; $pa_config->{"event_storm_protection"} = 0; $pa_config->{"use_custom_encoding"} = 0; $pa_config->{"node_metaconsole"} = 0; # > 7.0NG diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index ed4e127ade..d079461e01 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -2104,11 +2104,11 @@ sub pandora_access_update ($$$) { my ($pa_config, $agent_id, $dbh) = @_; return if ($agent_id < 0); - - if ($pa_config->{"agentaccess"} == 0){ - return; - } - db_do ($dbh, "INSERT INTO tagent_access (id_agent, utimestamp) VALUES (?, ?)", $agent_id, time ()); + return; + #if ($pa_config->{"agentaccess"} == 0){ + # return; + #} + #db_do ($dbh, "INSERT INTO tagent_access (id_agent, utimestamp) VALUES (?, ?)", $agent_id, time ()); } ########################################################################## @@ -4170,7 +4170,7 @@ sub pandora_delete_agent ($$;$) { db_do ($dbh, 'DELETE FROM tagente WHERE id_agente = ?', $agent_id); # Delete agent access data - db_do ($dbh, 'DELETE FROM tagent_access WHERE id_agent = ?', $agent_id); + #db_do ($dbh, 'DELETE FROM tagent_access WHERE id_agent = ?', $agent_id); # Delete addresses db_do ($dbh, 'DELETE FROM taddress_agent WHERE id_ag = ?', $agent_id); @@ -6593,11 +6593,11 @@ sub pandora_installation_monitoring($$) { undef $module; # Total agent access record - $module->{'name'} = "total_access_data"; - $module->{'description'} = 'Total agent access records'; - $module->{'data'} = get_db_value($dbh, 'SELECT COUNT(id_agent) FROM tagent_access'); - push(@modules, $module); - undef $module; + #$module->{'name'} = "total_access_data"; + #$module->{'description'} = 'Total agent access records'; + #$module->{'data'} = get_db_value($dbh, 'SELECT COUNT(id_agent) FROM tagent_access'); + #push(@modules, $module); + #undef $module; # Total users $module->{'name'} = "total_users"; @@ -6645,8 +6645,7 @@ sub pandora_installation_monitoring($$) { FROM information_schema.tables WHERE - table_schema not in ('information_schema', 'mysql') - AND table_name NOT IN ('tagent_access, tevento')" + table_schema not in ('information_schema', 'mysql')" ); $module->{'unit'} = '%'; push(@modules, $module); diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 048c365ca1..4ef684e5ae 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -276,24 +276,24 @@ sub pandora_purgedb ($$$) { log_message ('PURGE', "Deleting old access data (More than 24hr)"); - $first_mark = get_db_value_limit ($dbh, 'SELECT utimestamp FROM tagent_access ORDER BY utimestamp ASC', 1); - if (defined ($first_mark)) { - $total_time = $ulimit_access_timestamp - $first_mark; - $purge_steps = int( $total_time / $BIG_OPERATION_STEP); - if ($purge_steps > 0) { - for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){ - db_do ($dbh, "DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark); - log_message ('PURGE', "Agent access deletion progress %$ax", "\r"); - # Do a nanosleep here for 0,01 sec - usleep (10000); - } - log_message ('', "\n"); - } else { - log_message ('PURGE', "No agent access data to purge."); - } - } else { - log_message ('PURGE', "No agent access data."); - } + #$first_mark = get_db_value_limit ($dbh, 'SELECT utimestamp FROM tagent_access ORDER BY utimestamp ASC', 1); + #if (defined ($first_mark)) { + # $total_time = $ulimit_access_timestamp - $first_mark; + # $purge_steps = int( $total_time / $BIG_OPERATION_STEP); + # if ($purge_steps > 0) { + # for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){ + # db_do ($dbh, "DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark); + # log_message ('PURGE', "Agent access deletion progress %$ax", "\r"); + # # Do a nanosleep here for 0,01 sec + # usleep (10000); + # } + # log_message ('', "\n"); + # } else { + # log_message ('PURGE', "No agent access data to purge."); + # } + #} else { + # log_message ('PURGE', "No agent access data."); + #} # Purge the reports if (defined($conf->{'_enterprise_installed'}) && $conf->{'_enterprise_installed'} eq '1' && diff --git a/pandora_server/util/pandora_perf_report.pl b/pandora_server/util/pandora_perf_report.pl index cbc11219c7..2bc9fdf91b 100644 --- a/pandora_server/util/pandora_perf_report.pl +++ b/pandora_server/util/pandora_perf_report.pl @@ -212,7 +212,7 @@ sub stress_agent { sub table_stats { my ($dbh, $conf) = @_; my $stats = { - tagent_access => 'N/A', + #tagent_access => 'N/A', tagente => 'N/A', tagente_datos => 'N/A', tagente_datos_string => 'N/A', @@ -225,8 +225,7 @@ sub table_stats { FROM information_schema.TABLES WHERE TABLE_SCHEMA=? AND TABLE_NAME IN (?, ?, ?, ?, ?, ?, ?)", - $conf->{'dbname'}, - 'tagent_access', + $conf->{'dbname'},, 'tagente', 'tagente_datos', 'tagente_datos_string', @@ -309,7 +308,7 @@ sub generate_optimized_my_cnf { sub table_comments { my ($stats) = @_; my $comments = { - tagent_access => 'OK', + #tagent_access => 'OK', tagente => 'OK', tagente_datos => 'OK', tagente_datos_string => 'OK', @@ -319,11 +318,11 @@ sub table_comments { tsesion => 'OK', }; - if ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 250) { - $comments->{'tagent_access'} = 'CRITICAL: Table too big. Please contact our support team at: support@artica.es'; - } elsif ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 100) { - $comments->{'tagent_access'} = 'WARNING: Table too big. Please contact our support team at: support@artica.es'; - } + #if ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 250) { + # $comments->{'tagent_access'} = 'CRITICAL: Table too big. Please contact our support team at: support@artica.es'; + #} elsif ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 100) { + # $comments->{'tagent_access'} = 'WARNING: Table too big. Please contact our support team at: support@artica.es'; + #} if ($stats->{'tagente_datos'} > 5000000) { $comments->{'tagente_datos'} = 'CRITICAL: Table too big. Please use a history database or decrease the purge period.'; @@ -474,7 +473,6 @@ Module table $table_stats->{'tagente_modulo'} $tab Data table $table_stats->{'tagente_datos'} $table_comments->{'tagente_datos'} String data table $table_stats->{'tagente_datos_string'} $table_comments->{'tagente_datos_string'} Event table $table_stats->{'tevento'} $table_comments->{'tevento'} -Access stats $table_stats->{'tagent_access'} $table_comments->{'tagent_access'} Audit information $table_stats->{'tsesion'} $table_comments->{'tsesion'}