#12138 delete agent access graph

This commit is contained in:
miguel angel rasteu 2023-10-02 16:24:23 +02:00
parent b0d12c8a18
commit 3f41e4f32b
13 changed files with 60 additions and 301 deletions

View File

@ -27,7 +27,6 @@ if (! check_acl($config['id_user'], 0, 'DM')) {
// Get some general DB stats (not very heavy) // Get some general DB stats (not very heavy)
// NOTE: this is not realtime monitoring stats, are more focused on DB sanity // 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 = 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_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'); $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 '</b></td></tr>'; echo '</b></td></tr>';
echo '<tr class="rowOdd"><td>';
echo __('Total agent access records');
echo '<td><b>';
if ($stat_access > $max_access) {
echo "<font color='#ff0000'>$stat_access</font>";
} else {
echo $stat_access;
}
echo '</b></td></tr>';
// Sanity // Sanity
echo '<tr><th colspan=2><i>'; echo '<tr><th colspan=2><i>';
echo __('Database sanity'); echo __('Database sanity');

View File

@ -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'])); $performance_variables_control = (array) json_decode(io_safe_output($config['performance_variables_control']));
$total_agents = db_get_value('count(*)', 'tagente'); $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 = new StdClass();
$table_status->width = '100%'; $table_status->width = '100%';
$table_status->class = 'databox filters'; $table_status->class = 'databox filters';
@ -666,8 +665,8 @@ $table_other->data[2][1] = html_print_label_input_block(
true 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'), __('Use agent access graph'),
html_print_checkbox_switch( html_print_checkbox_switch(
'agentaccess', 'agentaccess',
@ -676,9 +675,9 @@ $table_other->data[3][0] = html_print_label_input_block(
true, true,
$disable_agentaccess $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'), __('Max. recommended number of files in attachment directory'),
html_print_input_text( html_print_input_text(
'num_files_attachment', 'num_files_attachment',

View File

@ -270,13 +270,6 @@ class ConsoleSupervisor
$this->checkSyncQueueStatus(); $this->checkSyncQueueStatus();
} }
/*
* Check number of agents is equals and more than 200.
* NOTIF.ACCESSSTASTICS.PERFORMANCE
*/
$this->checkAccessStatisticsPerformance();
/* /*
* Checkc agent missing libraries. * Checkc agent missing libraries.
* NOTIF.AGENT.LIBRARY * NOTIF.AGENT.LIBRARY
@ -570,13 +563,6 @@ class ConsoleSupervisor
$this->checkSyncQueueStatus(); $this->checkSyncQueueStatus();
} }
/*
* Check number of agents is equals and more than 200.
* NOTIF.ACCESSSTASTICS.PERFORMANCE
*/
$this->checkAccessStatisticsPerformance();
/* /*
* Checkc agent missing libraries. * Checkc agent missing libraries.
* NOTIF.AGENT.LIBRARY * 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&section=perf',
]
);
}
} else {
$this->cleanNotifications('NOTIF.ACCESSSTASTICS.PERFORMANCE');
}
}
/** /**
* Update targets for given notification using object targets. * Update targets for given notification using object targets.
* *

View File

@ -580,9 +580,6 @@ class Diagnostics extends Wizard
$countModuleData = db_get_value_sql( $countModuleData = db_get_value_sql(
'SELECT COUNT(*) FROM tagente_datos' 'SELECT COUNT(*) FROM tagente_datos'
); );
$countAgentAccess = db_get_value_sql(
'SELECT COUNT(*) FROM tagent_access'
);
$countEvents = db_get_value_sql('SELECT COUNT(*) FROM tevento'); $countEvents = db_get_value_sql('SELECT COUNT(*) FROM tevento');
if (enterprise_installed() === true) { if (enterprise_installed() === true) {
@ -595,39 +592,35 @@ class Diagnostics extends Wizard
$result = [ $result = [
'error' => false, 'error' => false,
'data' => [ 'data' => [
'countAgents' => [ 'countAgents' => [
'name' => __('Total agents'), 'name' => __('Total agents'),
'value' => $countAgents, 'value' => $countAgents,
], ],
'countModules' => [ 'countModules' => [
'name' => __('Total modules'), 'name' => __('Total modules'),
'value' => $countModules, 'value' => $countModules,
], ],
'countGroups' => [ 'countGroups' => [
'name' => __('Total groups'), 'name' => __('Total groups'),
'value' => $countGroups, 'value' => $countGroups,
], ],
'countModuleData' => [ 'countModuleData' => [
'name' => __('Total module data records'), 'name' => __('Total module data records'),
'value' => $countModuleData, 'value' => $countModuleData,
], ],
'countAgentAccess' => [ 'countEvents' => [
'name' => __('Total agent access record'),
'value' => $countAgentAccess,
],
'countEvents' => [
'name' => __('Total events'), 'name' => __('Total events'),
'value' => $countEvents, 'value' => $countEvents,
], ],
'countTraps' => [ 'countTraps' => [
'name' => __('Total traps'), 'name' => __('Total traps'),
'value' => $countTraps, 'value' => $countTraps,
], ],
'countUsers' => [ 'countUsers' => [
'name' => __('Total users'), 'name' => __('Total users'),
'value' => $countUsers, 'value' => $countUsers,
], ],
'countSessions' => [ 'countSessions' => [
'name' => __('Total sessions'), 'name' => __('Total sessions'),
'value' => $countSessions, 'value' => $countSessions,
], ],

View File

@ -913,10 +913,6 @@ function config_update_config()
$error_update[] = __('Batch statistics period (secs)'); $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) { 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'); $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); config_update_value('show_qr_code_header', false);
} }
if (!isset($config['agentaccess'])) {
config_update_value('agentaccess', true);
}
if (!isset($config['timezone'])) { if (!isset($config['timezone'])) {
config_update_value('timezone', 'Europe/Berlin'); config_update_value('timezone', 'Europe/Berlin');
} }

View File

@ -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 * Print a pie graph with alerts defined/fired data
* *

View File

@ -796,27 +796,6 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false)
'white_table_flex' 'white_table_flex'
); );
if ($config['agentaccess']) {
$access_graph = '<div style="height: 150px;" class="w100p center">';
$access_graph .= graphic_agentaccess(
$id_agente,
SECONDS_1DAY,
false
);
$access_graph .= '</div>';
ui_toggle(
$access_graph,
'<span class="subsection_header_title secondary">'.__('Agent access rate (24h)').'</span>',
'',
'',
true,
false,
'',
'white-box-content mrgn_top_0 mrgn_btn_0px border-bottom-gray',
'white_table_flex'
);
}
// Table network interfaces. // Table network interfaces.
$network_interfaces_by_agents = agents_get_network_interfaces([$agent]); $network_interfaces_by_agents = agents_get_network_interfaces([$agent]);

View File

@ -313,55 +313,6 @@ for ($i = 0; $i < $custom_fields_count; $i++) {
* END: TABLE DATA BUILD * 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' => '<span class="subsection_header_title">'.__('Agent access rate (Last 24h)').'</span>',
],
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 * START: TABLE INTERFACES
*/ */
@ -595,13 +546,6 @@ html_print_div(
] ]
); );
html_print_div(
[
'class' => 'agent_details_line',
'content' => $agentEvents.$agentAccessRate,
]
);
if (empty($agentAdditionalInfo) === false) { if (empty($agentAdditionalInfo) === false) {
html_print_div( html_print_div(
[ [

View File

@ -290,12 +290,12 @@ CREATE TABLE IF NOT EXISTS `tagente_modulo` (
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `tagent_access` -- Table `tagent_access`
-- ----------------------------------------------------- -- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tagent_access` ( -- CREATE TABLE IF NOT EXISTS `tagent_access` (
`id_agent` INT UNSIGNED NOT NULL DEFAULT 0, -- `id_agent` INT UNSIGNED NOT NULL DEFAULT 0,
`utimestamp` BIGINT NOT NULL DEFAULT 0, -- `utimestamp` BIGINT NOT NULL DEFAULT 0,
KEY `agent_index` (`id_agent`), -- KEY `agent_index` (`id_agent`),
KEY `idx_utimestamp` USING BTREE (`utimestamp`) -- KEY `idx_utimestamp` USING BTREE (`utimestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ----------------------------------------------------- -- -----------------------------------------------------
-- Table `talert_snmp` -- Table `talert_snmp`

View File

@ -128,7 +128,7 @@ sub pandora_get_sharedconfig ($$) {
my ($pa_config, $dbh) = @_; my ($pa_config, $dbh) = @_;
# Agentaccess option # 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. # Realtimestats 0 disabled, 1 enabled.
# Master servers will generate all the information (global tactical stats). # Master servers will generate all the information (global tactical stats).
@ -458,7 +458,7 @@ sub pandora_load_config {
# don't get an error later. # don't get an error later.
$pa_config->{"realtimestats"} = 0; $pa_config->{"realtimestats"} = 0;
$pa_config->{"stats_interval"} = 300; $pa_config->{"stats_interval"} = 300;
$pa_config->{"agentaccess"} = 1; #$pa_config->{"agentaccess"} = 1;
$pa_config->{"event_storm_protection"} = 0; $pa_config->{"event_storm_protection"} = 0;
$pa_config->{"use_custom_encoding"} = 0; $pa_config->{"use_custom_encoding"} = 0;
$pa_config->{"node_metaconsole"} = 0; # > 7.0NG $pa_config->{"node_metaconsole"} = 0; # > 7.0NG

View File

@ -2104,11 +2104,11 @@ sub pandora_access_update ($$$) {
my ($pa_config, $agent_id, $dbh) = @_; my ($pa_config, $agent_id, $dbh) = @_;
return if ($agent_id < 0); return if ($agent_id < 0);
return;
if ($pa_config->{"agentaccess"} == 0){ #if ($pa_config->{"agentaccess"} == 0){
return; # return;
} #}
db_do ($dbh, "INSERT INTO tagent_access (id_agent, utimestamp) VALUES (?, ?)", $agent_id, time ()); #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); db_do ($dbh, 'DELETE FROM tagente WHERE id_agente = ?', $agent_id);
# Delete agent access data # 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 # Delete addresses
db_do ($dbh, 'DELETE FROM taddress_agent WHERE id_ag = ?', $agent_id); db_do ($dbh, 'DELETE FROM taddress_agent WHERE id_ag = ?', $agent_id);
@ -6593,11 +6593,11 @@ sub pandora_installation_monitoring($$) {
undef $module; undef $module;
# Total agent access record # Total agent access record
$module->{'name'} = "total_access_data"; #$module->{'name'} = "total_access_data";
$module->{'description'} = 'Total agent access records'; #$module->{'description'} = 'Total agent access records';
$module->{'data'} = get_db_value($dbh, 'SELECT COUNT(id_agent) FROM tagent_access'); #$module->{'data'} = get_db_value($dbh, 'SELECT COUNT(id_agent) FROM tagent_access');
push(@modules, $module); #push(@modules, $module);
undef $module; #undef $module;
# Total users # Total users
$module->{'name'} = "total_users"; $module->{'name'} = "total_users";
@ -6645,8 +6645,7 @@ sub pandora_installation_monitoring($$) {
FROM FROM
information_schema.tables information_schema.tables
WHERE WHERE
table_schema not in ('information_schema', 'mysql') table_schema not in ('information_schema', 'mysql')"
AND table_name NOT IN ('tagent_access, tevento')"
); );
$module->{'unit'} = '%'; $module->{'unit'} = '%';
push(@modules, $module); push(@modules, $module);

View File

@ -276,24 +276,24 @@ sub pandora_purgedb ($$$) {
log_message ('PURGE', "Deleting old access data (More than 24hr)"); 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); #$first_mark = get_db_value_limit ($dbh, 'SELECT utimestamp FROM tagent_access ORDER BY utimestamp ASC', 1);
if (defined ($first_mark)) { #if (defined ($first_mark)) {
$total_time = $ulimit_access_timestamp - $first_mark; # $total_time = $ulimit_access_timestamp - $first_mark;
$purge_steps = int( $total_time / $BIG_OPERATION_STEP); # $purge_steps = int( $total_time / $BIG_OPERATION_STEP);
if ($purge_steps > 0) { # if ($purge_steps > 0) {
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){ # 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); # 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"); # log_message ('PURGE', "Agent access deletion progress %$ax", "\r");
# Do a nanosleep here for 0,01 sec # # Do a nanosleep here for 0,01 sec
usleep (10000); # usleep (10000);
} # }
log_message ('', "\n"); # log_message ('', "\n");
} else { # } else {
log_message ('PURGE', "No agent access data to purge."); # log_message ('PURGE', "No agent access data to purge.");
} # }
} else { #} else {
log_message ('PURGE', "No agent access data."); # log_message ('PURGE', "No agent access data.");
} #}
# Purge the reports # Purge the reports
if (defined($conf->{'_enterprise_installed'}) && $conf->{'_enterprise_installed'} eq '1' && if (defined($conf->{'_enterprise_installed'}) && $conf->{'_enterprise_installed'} eq '1' &&

View File

@ -212,7 +212,7 @@ sub stress_agent {
sub table_stats { sub table_stats {
my ($dbh, $conf) = @_; my ($dbh, $conf) = @_;
my $stats = { my $stats = {
tagent_access => 'N/A', #tagent_access => 'N/A',
tagente => 'N/A', tagente => 'N/A',
tagente_datos => 'N/A', tagente_datos => 'N/A',
tagente_datos_string => 'N/A', tagente_datos_string => 'N/A',
@ -225,8 +225,7 @@ sub table_stats {
FROM information_schema.TABLES FROM information_schema.TABLES
WHERE TABLE_SCHEMA=? WHERE TABLE_SCHEMA=?
AND TABLE_NAME IN (?, ?, ?, ?, ?, ?, ?)", AND TABLE_NAME IN (?, ?, ?, ?, ?, ?, ?)",
$conf->{'dbname'}, $conf->{'dbname'},,
'tagent_access',
'tagente', 'tagente',
'tagente_datos', 'tagente_datos',
'tagente_datos_string', 'tagente_datos_string',
@ -309,7 +308,7 @@ sub generate_optimized_my_cnf {
sub table_comments { sub table_comments {
my ($stats) = @_; my ($stats) = @_;
my $comments = { my $comments = {
tagent_access => 'OK', #tagent_access => 'OK',
tagente => 'OK', tagente => 'OK',
tagente_datos => 'OK', tagente_datos => 'OK',
tagente_datos_string => 'OK', tagente_datos_string => 'OK',
@ -319,11 +318,11 @@ sub table_comments {
tsesion => 'OK', tsesion => 'OK',
}; };
if ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 250) { #if ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 250) {
$comments->{'tagent_access'} = 'CRITICAL: Table too big. Please contact our support team at: support@artica.es'; # $comments->{'tagent_access'} = 'CRITICAL: Table too big. Please contact our support team at: support@artica.es';
} elsif ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 100) { #} elsif ($stats->{'tagent_access'} > $stats->{'tagente'} * 24 * 100) {
$comments->{'tagent_access'} = 'WARNING: Table too big. Please contact our support team at: support@artica.es'; # $comments->{'tagent_access'} = 'WARNING: Table too big. Please contact our support team at: support@artica.es';
} #}
if ($stats->{'tagente_datos'} > 5000000) { if ($stats->{'tagente_datos'} > 5000000) {
$comments->{'tagente_datos'} = 'CRITICAL: Table too big. Please use a history database or decrease the purge period.'; $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'} Data table $table_stats->{'tagente_datos'} $table_comments->{'tagente_datos'}
String data table $table_stats->{'tagente_datos_string'} $table_comments->{'tagente_datos_string'} String data table $table_stats->{'tagente_datos_string'} $table_comments->{'tagente_datos_string'}
Event table $table_stats->{'tevento'} $table_comments->{'tevento'} 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'} Audit information $table_stats->{'tsesion'} $table_comments->{'tsesion'}