[Secondary groups] Added update cache on server

This commit is contained in:
fermin831 2018-04-03 15:36:33 +02:00
parent 2839388e9e
commit e2d61d5794
3 changed files with 40 additions and 1 deletions

View File

@ -82,6 +82,7 @@ CREATE TABLE IF NOT EXISTS `tagente` (
`fired_count` bigint(20) NOT NULL default '0',
`update_module_count` tinyint(1) NOT NULL default '0',
`update_alert_count` tinyint(1) NOT NULL default '0',
`update_secondary_groups` tinyint(1) NOT NULL default '0',
`alias` varchar(600) BINARY NOT NULL default '',
`transactional_agent` tinyint(1) NOT NULL default '0',
`alias_as_name` tinyint(2) NOT NULL default '0',
@ -2983,6 +2984,7 @@ CREATE TABLE IF NOT EXISTS `tmetaconsole_agent` (
`fired_count` bigint(20) NOT NULL default '0',
`update_module_count` tinyint(1) NOT NULL default '0',
`update_alert_count` tinyint(1) NOT NULL default '0',
`update_secondary_groups` tinyint(1) NOT NULL default '0',
`transactional_agent` tinyint(1) NOT NULL default '0',
`alias` varchar(600) BINARY NOT NULL default '',
`alias_as_name` tinyint(2) NOT NULL default '0',
@ -3157,3 +3159,21 @@ create table IF NOT EXISTS `tagent_secondary_group`(
ON DELETE CASCADE
) engine=InnoDB DEFAULT CHARSET=utf8;
-- ---------------------------------------------------------------------
-- Table `tmetaconsole_agent_secondary_group`
-- ---------------------------------------------------------------------
create table IF NOT EXISTS `tmetaconsole_agent_secondary_group`(
`id` int unsigned not null auto_increment,
`id_agent` int(10) unsigned NOT NULL,
`id_tagente` int(10) unsigned NOT NULL,
`id_tmetaconsole_setup` int(10) NOT NULL,
`id_group` mediumint(4) unsigned NOT NULL,
PRIMARY KEY(`id`),
FOREIGN KEY(`id_agent`) REFERENCES tmetaconsole_agent(`id_agente`)
ON DELETE CASCADE,
FOREIGN KEY(`id_group`) REFERENCES tgrupo(`id_grupo`)
ON DELETE CASCADE,
FOREIGN KEY (`id_tmetaconsole_setup`) REFERENCES tmetaconsole_setup(`id`)
ON DELETE CASCADE
) engine=InnoDB DEFAULT CHARSET=utf8;

View File

@ -293,7 +293,7 @@ sub pandora_server_tasks ($) {
if (($counter % 30) == 0) {
# Update module status and fired alert counts
my @agents = get_db_rows ($dbh, 'SELECT id_agente, nombre, update_module_count, update_alert_count FROM tagente WHERE disabled = 0 AND (update_module_count=1 OR update_alert_count=1)');
my @agents = get_db_rows ($dbh, 'SELECT id_agente, nombre, update_module_count, update_alert_count, update_secondary_groups FROM tagente WHERE disabled = 0 AND (update_module_count=1 OR update_alert_count=1)');
foreach my $agent (@agents) {
logger ($pa_config, "Updating module status and fired alert counts for agent " . $agent->{'nombre'}, 10);
@ -304,6 +304,10 @@ sub pandora_server_tasks ($) {
if ($agent->{'update_alert_count'} == 1) {
pandora_update_agent_alert_count ($pa_config, $dbh, $agent->{'id_agente'});
}
if ($agent->{'update_secondary_groups'} == 1) {
pandora_update_secondary_groups_cache ($pa_config, $dbh, $agent->{'id_agente'});
}
}
# Keepalive module control.(very DB intensive, not run frecuently

View File

@ -92,6 +92,8 @@ Exported Functions:
=item * C<pandora_update_server>
=item * C<pandora_update_secondary_groups_cache>
=item * C<pandora_group_statistics>
=item * C<pandora_server_statistics>
@ -221,6 +223,7 @@ our @EXPORT = qw(
pandora_update_gis_data
pandora_update_module_on_error
pandora_update_module_from_hash
pandora_update_secondary_groups_cache
pandora_update_server
pandora_update_table_from_hash
pandora_update_template_module
@ -5211,6 +5214,18 @@ sub pandora_update_agent_alert_count ($$$) {
enterprise_hook('update_agent_cache', [$pa_config, $dbh, $agent_id]) if ($pa_config->{'node_metaconsole'} == 1);
}
##########################################################################
# Update the secondary group cache.
##########################################################################
sub pandora_update_secondary_groups_cache ($$$) {
my ($pa_config, $dbh, $agent_id) = @_;
db_do ($dbh, 'UPDATE tagente SET update_secondary_groups=0 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->{'node_metaconsole'} == 1);
}
########################################################################
# SUB pandora_get_os (string)
# Detect OS using a string, and return id_os