Merge branch 'ent-12075-registro-de-nodos-ha-en-metaconsola' into 'develop'

Update database targets in HA environments using metaconsole

See merge request artica/pandorafms!6956
This commit is contained in:
Rafael Ameijeiras 2024-02-26 16:28:57 +00:00
commit d62407dd4a
3 changed files with 30 additions and 40 deletions

View File

@ -108,4 +108,13 @@ INSERT IGNORE INTO `tcredential_store` (`identifier`, `id_group`, `product`, `ex
;
UPDATE `trecon_task` SET `auth_strings` = IF(`auth_strings` = '',CONCAT(@creds_name,`id_rt`),CONCAT(@creds_name,`id_rt`,',',`auth_strings`)) WHERE `snmp_version` = 3 AND `snmp_enabled` = 1;
ALTER TABLE `tdatabase` ADD COLUMN `disabled` TINYINT NOT NULL DEFAULT 0;
CREATE TABLE IF NOT EXISTS `tmetaconsole_ha_databases` (
`node_id` int NOT NULL,
`host` varchar(255) DEFAULT '',
`master` tinyint unsigned DEFAULT '0',
PRIMARY KEY (`node_id`, `host`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
COMMIT;

View File

@ -2668,6 +2668,7 @@ CREATE TABLE IF NOT EXISTS `tdatabase` (
`utimestamp` BIGINT DEFAULT 0,
`mysql_version` VARCHAR(10) DEFAULT '',
`pandora_version` VARCHAR(10) DEFAULT '',
`disabled` TINYINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
@ -4654,4 +4655,14 @@ CREATE TABLE IF NOT EXISTS `tmerge_queries` (
`utimestamp` int(20) unsigned NOT NULL default 0,
`query` LONGTEXT NOT NULL default "",
PRIMARY KEY (`steps`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
-- ---------------------------------------------------------------------
-- Table `tmetaconsole_ha_databases`
-- ---------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `tmetaconsole_ha_databases` (
`node_id` int NOT NULL,
`host` varchar(255) DEFAULT '',
`master` tinyint unsigned DEFAULT '0',
PRIMARY KEY (`node_id`, `host`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;

View File

@ -442,16 +442,6 @@ sub ha_database_connect_pandora($) {
# Select a new master database.
my ($dbh, $utimestamp, $max_utimestamp) = (undef, undef, -1);
my @disabled_nodes = get_disabled_nodes($conf);
# If there are disabled nodes ignore them from the HA_DB_Hosts.
if(scalar @disabled_nodes ne 0){
@HA_DB_Hosts = grep { my $item = $_; !grep { $_ eq $item } @disabled_nodes } @HA_DB_Hosts;
my $data = join(",", @disabled_nodes);
log_message($conf, 'LOG', "Ignoring disabled hosts: " . $data);
}
foreach my $ha_dbhost (@HA_DB_Hosts) {
# Retry each database ha_connect_retries times.
@ -478,6 +468,13 @@ sub ha_database_connect_pandora($) {
# No luck. Try the next database.
next unless defined($dbh);
# Check if database is disabled.
if (defined(get_db_value($dbh, 'SELECT `id` FROM `tdatabase` WHERE `host` = "' . $ha_dbhost . '" AND disabled = 1')))
{
log_message($conf, 'LOG', "Ignoring disabled host: " . $ha_dbhost);
db_disconnect($dbh);
next;
}
eval {
# Get the most recent utimestamp from the database.
$utimestamp = get_db_value($dbh, 'SELECT UNIX_TIMESTAMP(MAX(keepalive)) FROM tserver');
@ -542,36 +539,6 @@ sub ha_restart_pandora($) {
`$config->{'pandora_service_cmd'} $control_command 2>/dev/null`;
}
###############################################################################
# Get ip of the disabled nodes.
###############################################################################
sub get_disabled_nodes($) {
my ($conf) = @_;
my $dbh = db_connect('mysql',
$conf->{'dbname'},
$conf->{'dbhost'},
$conf->{'dbport'},
$conf->{'ha_dbuser'},
$conf->{'ha_dbpass'});
my $disabled_nodes = get_db_value($dbh, "SELECT value FROM tconfig WHERE token = 'ha_disabled_nodes'");
if(!defined($disabled_nodes) || $disabled_nodes eq ""){
$disabled_nodes = ',';
}
my @disabled_nodes = split(',', $disabled_nodes);
if(scalar @disabled_nodes ne 0){
$disabled_nodes = join(",", @disabled_nodes);
@disabled_nodes = get_db_rows($dbh, "SELECT host FROM tdatabase WHERE id IN ($disabled_nodes)");
@disabled_nodes = map { $_->{host} } @disabled_nodes;
}
return @disabled_nodes;
}
###############################################################################
# Main (Pacemaker)
###############################################################################
@ -743,6 +710,9 @@ sub ha_main_pandora($) {
# Execute resync actions.
enterprise_hook('pandoraha_resync_dbs', [$conf, $dbh, $DB_Host, \@HA_DB_Hosts]);
# Update and push HA databases info to Metaconsole or nodes.
enterprise_hook('pandoraha_update_and_push_databases_info', [$conf, $dbh]);
# Synchronize nodes.
enterprise_hook('pandoraha_sync_node', [$conf, $dbh]);
};