Implemented an agent cache for the metaconsole.
This commit is contained in:
parent
ede2e3794a
commit
71def9a7fb
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
require_once($config['homedir'] . "/include/functions_modules.php");
|
require_once($config['homedir'] . "/include/functions_modules.php");
|
||||||
require_once($config['homedir'] . '/include/functions_users.php');
|
require_once($config['homedir'] . '/include/functions_users.php');
|
||||||
|
enterprise_include_once('/include/functions_agents.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the agent exists in the DB.
|
* Check the agent exists in the DB.
|
||||||
|
@ -1828,6 +1829,8 @@ function agents_delete_agent ($id_agents, $disableACL = false) {
|
||||||
db_pandora_audit( "Agent management",
|
db_pandora_audit( "Agent management",
|
||||||
"Deleted agent '$agent_name'");
|
"Deleted agent '$agent_name'");
|
||||||
|
|
||||||
|
// Delete the agent from the metaconsole cache
|
||||||
|
enterprise_hook('agent_delete_from_cache', array($id_agent));
|
||||||
|
|
||||||
/* Break the loop on error */
|
/* Break the loop on error */
|
||||||
if ($error)
|
if ($error)
|
||||||
|
|
|
@ -204,21 +204,23 @@ function config_update_config () {
|
||||||
if ((int)get_parameter('event_replication') == 1) {
|
if ((int)get_parameter('event_replication') == 1) {
|
||||||
if (!config_update_value ('replication_interval', (int)get_parameter('replication_interval')))
|
if (!config_update_value ('replication_interval', (int)get_parameter('replication_interval')))
|
||||||
$error_update[] = __('Replication interval');
|
$error_update[] = __('Replication interval');
|
||||||
if (!config_update_value ('replication_dbhost', (string)get_parameter('replication_dbhost')))
|
|
||||||
$error_update[] = __('Replication DB host');
|
|
||||||
if (!config_update_value ('replication_dbname', (string)get_parameter('replication_dbname')))
|
|
||||||
$error_update[] = __('Replication DB database');
|
|
||||||
if (!config_update_value ('replication_dbuser', (string)get_parameter('replication_dbuser')))
|
|
||||||
$error_update[] = __('Replication DB user');
|
|
||||||
if (!config_update_value ('replication_dbpass', io_input_password((string)get_parameter('replication_dbpass'))))
|
|
||||||
$error_update[] = __('Replication DB password');
|
|
||||||
if (!config_update_value ('replication_dbport', (string)get_parameter('replication_dbport')))
|
|
||||||
$error_update[] = __('Replication DB port');
|
|
||||||
if (!config_update_value ('replication_mode', (string)get_parameter('replication_mode')))
|
if (!config_update_value ('replication_mode', (string)get_parameter('replication_mode')))
|
||||||
$error_update[] = __('Replication mode');
|
$error_update[] = __('Replication mode');
|
||||||
if (!config_update_value ('show_events_in_local', (string)get_parameter('show_events_in_local')))
|
if (!config_update_value ('show_events_in_local', (string)get_parameter('show_events_in_local')))
|
||||||
$error_update[] = __('Show events list in local console (read only)');
|
$error_update[] = __('Show events list in local console (read only)');
|
||||||
}
|
}
|
||||||
|
if (!config_update_value ('replication_dbhost', (string)get_parameter('replication_dbhost')))
|
||||||
|
$error_update[] = __('Replication DB host');
|
||||||
|
if (!config_update_value ('replication_dbname', (string)get_parameter('replication_dbname')))
|
||||||
|
$error_update[] = __('Replication DB database');
|
||||||
|
if (!config_update_value ('replication_dbuser', (string)get_parameter('replication_dbuser')))
|
||||||
|
$error_update[] = __('Replication DB user');
|
||||||
|
if (!config_update_value ('replication_dbpass', io_input_password((string)get_parameter('replication_dbpass'))))
|
||||||
|
$error_update[] = __('Replication DB password');
|
||||||
|
if (!config_update_value ('replication_dbport', (string)get_parameter('replication_dbport')))
|
||||||
|
$error_update[] = __('Replication DB port');
|
||||||
|
if (!config_update_value ('metaconsole_agent_cache', (int)get_parameter('metaconsole_agent_cache')))
|
||||||
|
$error_update[] = __('Metaconsole agent cache');
|
||||||
if (!config_update_value ('log_collector', (bool)get_parameter('log_collector')))
|
if (!config_update_value ('log_collector', (bool)get_parameter('log_collector')))
|
||||||
$error_update[] = __('Activate Log Collector');
|
$error_update[] = __('Activate Log Collector');
|
||||||
|
|
||||||
|
@ -796,6 +798,10 @@ function config_process_config () {
|
||||||
config_update_value ('replication_mode', "only_validated");
|
config_update_value ('replication_mode', "only_validated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset ($config["metaconsole_agent_cache"])) {
|
||||||
|
config_update_value ('metaconsole_agent_cache', 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset ($config["show_events_in_local"])) {
|
if (!isset ($config["show_events_in_local"])) {
|
||||||
config_update_value ('show_events_in_local', 0);
|
config_update_value ('show_events_in_local', 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,9 @@ sub pandora_startup () {
|
||||||
# Generate the encryption key after reading the passphrase.
|
# Generate the encryption key after reading the passphrase.
|
||||||
$Config{"encryption_key"} = enterprise_hook('pandora_get_encryption_key', [\%Config, $Config{"encryption_passphrase"}]);
|
$Config{"encryption_key"} = enterprise_hook('pandora_get_encryption_key', [\%Config, $Config{"encryption_passphrase"}]);
|
||||||
|
|
||||||
|
# Update the agent cache.
|
||||||
|
enterprise_hook('update_agent_cache', [\%Config, $DBH]) if ($Config{'metaconsole_agent_cache'} == 1);
|
||||||
|
|
||||||
pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH);
|
pandora_audit (\%Config, 'Pandora FMS Server Daemon starting', 'SYSTEM', 'System', $DBH);
|
||||||
|
|
||||||
# Load servers
|
# Load servers
|
||||||
|
@ -291,7 +294,7 @@ sub pandora_server_tasks ($) {
|
||||||
logger ($pa_config, "Updating module status and fired alert counts for agent " . $agent->{'nombre'}, 10);
|
logger ($pa_config, "Updating module status and fired alert counts for agent " . $agent->{'nombre'}, 10);
|
||||||
|
|
||||||
if ($agent->{'update_module_count'} == 1) {
|
if ($agent->{'update_module_count'} == 1) {
|
||||||
pandora_update_agent_module_count ($dbh, $agent->{'id_agente'});
|
pandora_update_agent_module_count ($pa_config, $dbh, $agent->{'id_agente'});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($agent->{'update_alert_count'} == 1) {
|
if ($agent->{'update_alert_count'} == 1) {
|
||||||
|
|
|
@ -159,6 +159,9 @@ sub pandora_get_sharedconfig ($$) {
|
||||||
|
|
||||||
# Pandora FMS Console's attachment directory
|
# Pandora FMS Console's attachment directory
|
||||||
$pa_config->{"attachment_dir"} = pandora_get_tconfig_token ($dbh, 'attachment_store', '/var/www/pandora_console/attachment');
|
$pa_config->{"attachment_dir"} = pandora_get_tconfig_token ($dbh, 'attachment_store', '/var/www/pandora_console/attachment');
|
||||||
|
|
||||||
|
# Metaconsole agent cache.
|
||||||
|
$pa_config->{"metaconsole_agent_cache"} = pandora_get_tconfig_token ($dbh, 'metaconsole_agent_cache', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -2608,7 +2608,7 @@ sub pandora_create_module_from_hash ($$$) {
|
||||||
sub pandora_update_module_from_hash ($$$$$) {
|
sub pandora_update_module_from_hash ($$$$$) {
|
||||||
my ($pa_config, $parameters, $where_column, $where_value, $dbh) = @_;
|
my ($pa_config, $parameters, $where_column, $where_value, $dbh) = @_;
|
||||||
|
|
||||||
my $module_id = db_process_update($dbh, 'tagente_modulo', $parameters, $where_column, $where_value);
|
my $module_id = db_process_update($dbh, 'tagente_modulo', $parameters, {$where_column => $where_value});
|
||||||
return $module_id;
|
return $module_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2618,7 +2618,7 @@ sub pandora_update_module_from_hash ($$$$$) {
|
||||||
sub pandora_update_table_from_hash ($$$$$$) {
|
sub pandora_update_table_from_hash ($$$$$$) {
|
||||||
my ($pa_config, $parameters, $where_column, $where_value, $table, $dbh) = @_;
|
my ($pa_config, $parameters, $where_column, $where_value, $table, $dbh) = @_;
|
||||||
|
|
||||||
my $module_id = db_process_update($dbh, $table, $parameters, $where_column, $where_value);
|
my $module_id = db_process_update($dbh, $table, $parameters, {$where_column => $where_value});
|
||||||
return $module_id;
|
return $module_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4663,24 +4663,8 @@ sub pandora_set_event_storm_protection ($) {
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# Update the module status count of an agent.
|
# Update the module status count of an agent.
|
||||||
##########################################################################
|
##########################################################################
|
||||||
sub pandora_update_agent_count ($$) {
|
sub pandora_update_agent_module_count ($$$) {
|
||||||
my ($dbh, $agent_id) = @_;
|
my ($pa_config, $dbh, $agent_id) = @_;
|
||||||
|
|
||||||
db_do ($dbh, 'UPDATE tagente SET update_module_count=0,
|
|
||||||
normal_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=0),
|
|
||||||
critical_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=1),
|
|
||||||
warning_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=2),
|
|
||||||
unknown_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=3),
|
|
||||||
notinit_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=4),
|
|
||||||
total_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id .
|
|
||||||
') WHERE id_agente = ' . $agent_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
##########################################################################
|
|
||||||
# Update the module status count of an agent.
|
|
||||||
##########################################################################
|
|
||||||
sub pandora_update_agent_module_count ($$) {
|
|
||||||
my ($dbh, $agent_id) = @_;
|
|
||||||
|
|
||||||
db_do ($dbh, 'UPDATE tagente SET update_module_count=0,
|
db_do ($dbh, 'UPDATE tagente SET update_module_count=0,
|
||||||
normal_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=0),
|
normal_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=0),
|
||||||
|
@ -4690,6 +4674,9 @@ sub pandora_update_agent_module_count ($$) {
|
||||||
notinit_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=4),
|
notinit_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id . ' AND estado=4),
|
||||||
total_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id .
|
total_count=(SELECT COUNT(*) FROM tagente_modulo, tagente_estado WHERE tagente_modulo.disabled=0 AND tagente_modulo.id_agente_modulo=tagente_estado.id_agente_modulo AND tagente_modulo.id_agente=' . $agent_id .
|
||||||
') WHERE id_agente = ' . $agent_id);
|
') WHERE id_agente = ' . $agent_id);
|
||||||
|
|
||||||
|
# Sync the agent cache every time the module count is updated.
|
||||||
|
enterprise_hook('update_agent_cache', [$pa_config, $dbh, $agent_id]) if ($pa_config->{'metaconsole_agent_cache'} == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
|
@ -734,17 +734,20 @@ sub db_process_insert($$$$;@) {
|
||||||
########################################################################
|
########################################################################
|
||||||
## SQL update.
|
## SQL update.
|
||||||
########################################################################
|
########################################################################
|
||||||
sub db_process_update($$$$$;@) {
|
sub db_process_update($$$$) {
|
||||||
my ($dbh, $table, $parameters, $where_column, $where_value, @values) = @_;
|
my ($dbh, $table, $parameters, $conditions) = @_;
|
||||||
|
|
||||||
my @columns_array = keys %$parameters;
|
my @columns_array = keys %$parameters;
|
||||||
my @values_array = values %$parameters;
|
my @values_array = values %$parameters;
|
||||||
|
my @where_columns = keys %$conditions;
|
||||||
|
my @where_values = values %$conditions;
|
||||||
|
|
||||||
if (!defined($table) || $#columns_array == -1) {
|
if (!defined($table) || $#columns_array == -1 || $#where_columns == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# VALUES...
|
||||||
my $fields = '';
|
my $fields = '';
|
||||||
for (my $i = 0; $i <= $#values_array; $i++) {
|
for (my $i = 0; $i <= $#values_array; $i++) {
|
||||||
if (!defined($values_array[$i])) {
|
if (!defined($values_array[$i])) {
|
||||||
|
@ -757,11 +760,22 @@ sub db_process_update($$$$$;@) {
|
||||||
" " . $RDBMS_QUOTE . "$columns_array[$i]" . $RDBMS_QUOTE . " = ?";
|
" " . $RDBMS_QUOTE . "$columns_array[$i]" . $RDBMS_QUOTE . " = ?";
|
||||||
}
|
}
|
||||||
|
|
||||||
push(@values_array, $where_value);
|
# WHERE...
|
||||||
|
my $where = '';
|
||||||
|
for (my $i = 0; $i <= $#where_columns; $i++) {
|
||||||
|
if (!defined($where_values[$i])) {
|
||||||
|
$where_values[$i] = '';
|
||||||
|
}
|
||||||
|
if ($i > 0 && $i <= $#where_values) {
|
||||||
|
$where = $where.' AND ';
|
||||||
|
}
|
||||||
|
$where = $where .
|
||||||
|
" " . $RDBMS_QUOTE . "$where_columns[$i]" . $RDBMS_QUOTE . " = ?";
|
||||||
|
}
|
||||||
|
|
||||||
my $res = db_update ($dbh, "UPDATE $table
|
my $res = db_update ($dbh, "UPDATE $table
|
||||||
SET $fields
|
SET $fields
|
||||||
WHERE $where_column = ?", @values_array);
|
WHERE $where", @values_array, @where_values);
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -497,7 +497,7 @@ sub pandora_validate_event_id ($$$) {
|
||||||
sub pandora_update_user_from_hash ($$$$) {
|
sub pandora_update_user_from_hash ($$$$) {
|
||||||
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
||||||
|
|
||||||
my $user_id = db_process_update($dbh, 'tusuario', $parameters, $where_column, $where_value);
|
my $user_id = db_process_update($dbh, 'tusuario', $parameters, {$where_column => $where_value});
|
||||||
return $user_id;
|
return $user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,7 +507,7 @@ sub pandora_update_user_from_hash ($$$$) {
|
||||||
sub pandora_update_alert_template_from_hash ($$$$) {
|
sub pandora_update_alert_template_from_hash ($$$$) {
|
||||||
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
||||||
|
|
||||||
my $template_id = db_process_update($dbh, 'talert_templates', $parameters, $where_column, $where_value);
|
my $template_id = db_process_update($dbh, 'talert_templates', $parameters, {$where_column => $where_value});
|
||||||
return $template_id;
|
return $template_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -621,7 +621,7 @@ sub pandora_create_special_day_from_hash ($$$) {
|
||||||
sub pandora_update_special_day_from_hash ($$$$) {
|
sub pandora_update_special_day_from_hash ($$$$) {
|
||||||
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
||||||
|
|
||||||
my $special_day_id = db_process_update($dbh, 'talert_special_days', $parameters, $where_column, $where_value);
|
my $special_day_id = db_process_update($dbh, 'talert_special_days', $parameters, {$where_column => $where_value});
|
||||||
return $special_day_id;
|
return $special_day_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3480,7 +3480,7 @@ sub cli_stop_downtime () {
|
||||||
|
|
||||||
my $parameters->{'date_to'} = time;
|
my $parameters->{'date_to'} = time;
|
||||||
|
|
||||||
db_process_update($dbh, 'tplanned_downtime', $parameters, 'id', $downtime_id);
|
db_process_update($dbh, 'tplanned_downtime', $parameters, {'id' => $downtime_id});
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -3593,7 +3593,7 @@ sub pandora_get_event_name($$) {
|
||||||
sub pandora_update_event_from_hash ($$$$) {
|
sub pandora_update_event_from_hash ($$$$) {
|
||||||
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
my ($parameters, $where_column, $where_value, $dbh) = @_;
|
||||||
|
|
||||||
my $event_id = db_process_update($dbh, 'tevento', $parameters, $where_column, $where_value);
|
my $event_id = db_process_update($dbh, 'tevento', $parameters, {$where_column => $where_value});
|
||||||
return $event_id;
|
return $event_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue