mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
1923 Added required methods for migrationserver
This commit is contained in:
parent
a3dceac0a0
commit
ed282c6a9b
@ -3092,8 +3092,9 @@ create table IF NOT EXISTS `tmigration_queue`(
|
|||||||
`id_source_node` int unsigned not null,
|
`id_source_node` int unsigned not null,
|
||||||
`id_target_node` int unsigned not null,
|
`id_target_node` int unsigned not null,
|
||||||
`priority` int unsigned default 0,
|
`priority` int unsigned default 0,
|
||||||
`step` int unsigned default 0,
|
`step` int default 0,
|
||||||
`running` tinyint(2) unsigned not null default 0,
|
`running` tinyint(2) default 0,
|
||||||
|
`active_db_only` tinyint(2) default 0,
|
||||||
PRIMARY KEY(`id`)
|
PRIMARY KEY(`id`)
|
||||||
) engine=InnoDB DEFAULT CHARSET=utf8;
|
) engine=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
@ -3104,8 +3105,6 @@ create table IF NOT EXISTS `tmigration_queue`(
|
|||||||
create table IF NOT EXISTS `tmigration_module_queue`(
|
create table IF NOT EXISTS `tmigration_module_queue`(
|
||||||
`id` int unsigned not null auto_increment,
|
`id` int unsigned not null auto_increment,
|
||||||
`id_migration` int unsigned not null,
|
`id_migration` int unsigned not null,
|
||||||
`id_source_node` int unsigned not null,
|
|
||||||
`id_target_node` int unsigned not null,
|
|
||||||
`id_source_agentmodule` int unsigned not null,
|
`id_source_agentmodule` int unsigned not null,
|
||||||
`id_target_agentmodule` int unsigned not null,
|
`id_target_agentmodule` int unsigned not null,
|
||||||
`last_replication_timestamp` bigint(20) NOT NULL default 0,
|
`last_replication_timestamp` bigint(20) NOT NULL default 0,
|
||||||
|
@ -37,6 +37,7 @@ use PandoraFMS::ReconServer;
|
|||||||
use PandoraFMS::WMIServer;
|
use PandoraFMS::WMIServer;
|
||||||
use PandoraFMS::PluginServer;
|
use PandoraFMS::PluginServer;
|
||||||
use PandoraFMS::PredictionServer;
|
use PandoraFMS::PredictionServer;
|
||||||
|
use PandoraFMS::MigrationServer;
|
||||||
|
|
||||||
# Constants for Win32 services.
|
# Constants for Win32 services.
|
||||||
use constant WIN32_SERVICE_STOPPED => 0x01;
|
use constant WIN32_SERVICE_STOPPED => 0x01;
|
||||||
@ -118,6 +119,7 @@ sub pandora_startup () {
|
|||||||
} else {
|
} else {
|
||||||
# Metaconsole service modules are run by the prediction server
|
# Metaconsole service modules are run by the prediction server
|
||||||
push (@Servers, new PandoraFMS::PredictionServer (\%Config, $DBH));
|
push (@Servers, new PandoraFMS::PredictionServer (\%Config, $DBH));
|
||||||
|
push (@Servers, new PandoraFMS::MigrationServer (\%Config, $DBH));
|
||||||
}
|
}
|
||||||
|
|
||||||
# There are enterprise metaconsole servers!
|
# There are enterprise metaconsole servers!
|
||||||
|
@ -34,12 +34,14 @@ our @EXPORT = qw(
|
|||||||
add_new_address_agent
|
add_new_address_agent
|
||||||
db_concat
|
db_concat
|
||||||
db_connect
|
db_connect
|
||||||
|
db_history_connect
|
||||||
db_delete_limit
|
db_delete_limit
|
||||||
db_disconnect
|
db_disconnect
|
||||||
db_do
|
db_do
|
||||||
db_get_lock
|
db_get_lock
|
||||||
db_insert
|
db_insert
|
||||||
db_insert_get_values
|
db_insert_get_values
|
||||||
|
db_insert_from_array_hash
|
||||||
db_insert_from_hash
|
db_insert_from_hash
|
||||||
db_process_insert
|
db_process_insert
|
||||||
db_process_update
|
db_process_update
|
||||||
@ -168,6 +170,28 @@ sub db_connect ($$$$$$) {
|
|||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
## Connect to a history DB associated to given dbh.
|
||||||
|
##########################################################################
|
||||||
|
sub db_history_connect {
|
||||||
|
my ($dbh, $pa_config) = @_;
|
||||||
|
|
||||||
|
my %conf;
|
||||||
|
|
||||||
|
$conf{'history_db_enabled'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", "history_db_enabled");
|
||||||
|
$conf{'history_db_host'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", "history_db_host");
|
||||||
|
$conf{'history_db_port'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", "history_db_port");
|
||||||
|
$conf{'history_db_name'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", "history_db_name");
|
||||||
|
$conf{'history_db_user'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", "history_db_user");
|
||||||
|
$conf{'history_db_pass'} = get_db_value ($dbh, "SELECT value FROM tconfig WHERE token = ?", "history_db_pass");
|
||||||
|
|
||||||
|
my $history_dbh = ($conf{'history_db_enabled'} eq '1') ? db_connect ($pa_config->{'dbengine'}, $conf{'history_db_name'},
|
||||||
|
$conf{'history_db_host'}, $conf{'history_db_port'}, $conf{'history_db_user'}, $conf{'history_db_pass'}) : undef;
|
||||||
|
|
||||||
|
|
||||||
|
return $history_dbh;
|
||||||
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
## Disconnect from the DB.
|
## Disconnect from the DB.
|
||||||
########################################################################
|
########################################################################
|
||||||
@ -904,14 +928,15 @@ sub db_process_insert($$$$;@) {
|
|||||||
########################################################################
|
########################################################################
|
||||||
## SQL insert from hash
|
## SQL insert from hash
|
||||||
## 1st: dbh
|
## 1st: dbh
|
||||||
## 2nd: table name,
|
## 2nd: index
|
||||||
## 2nd: {field => value} ref
|
## 3rd: table name,
|
||||||
|
## 4th: {field => value} ref
|
||||||
########################################################################
|
########################################################################
|
||||||
sub db_insert_from_hash {
|
sub db_insert_from_hash {
|
||||||
my ($dbh, $index, $table, $data) = @_;
|
my ($dbh, $index, $table, $data) = @_;
|
||||||
|
|
||||||
my @fields = keys %{$data};
|
|
||||||
my $values_prep = "";
|
my $values_prep = "";
|
||||||
|
my @fields = keys %{$data};
|
||||||
my @values = values %{$data};
|
my @values = values %{$data};
|
||||||
my $nfields = scalar @fields;
|
my $nfields = scalar @fields;
|
||||||
|
|
||||||
@ -921,7 +946,37 @@ sub db_insert_from_hash {
|
|||||||
$values_prep =~ s/,$//;
|
$values_prep =~ s/,$//;
|
||||||
|
|
||||||
return db_insert($dbh, $index, "INSERT INTO " . $table . " (" . join (",", @fields) . ") VALUES ($values_prep)", @values);
|
return db_insert($dbh, $index, "INSERT INTO " . $table . " (" . join (",", @fields) . ") VALUES ($values_prep)", @values);
|
||||||
|
}
|
||||||
|
|
||||||
|
########################################################################
|
||||||
|
## SQL insert from hash
|
||||||
|
## 1st: dbh
|
||||||
|
## 2nd: index
|
||||||
|
## 3rd: table name,
|
||||||
|
## 4th: array({field => value},{field => value}) array ref
|
||||||
|
##
|
||||||
|
## Returns: An array with the inserted indexes
|
||||||
|
########################################################################
|
||||||
|
sub db_insert_from_array_hash {
|
||||||
|
my ($dbh, $index, $table, $data) = @_;
|
||||||
|
|
||||||
|
if ((!defined($data) || ref ($data) ne "ARRAY")) {
|
||||||
|
return ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
my @inserted_keys;
|
||||||
|
|
||||||
|
eval {
|
||||||
|
foreach my $row (@{$data}) {
|
||||||
|
push @inserted_keys, db_insert_from_hash($dbh, $index, $table, $row);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if ($@) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
return @inserted_keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user