Skip to content

Commit

Permalink
Merge branch 'ent-9500-cli-en-la-metaconsola-no-se-sicnroniza-con-los…
Browse files Browse the repository at this point in the history
…-nodos' into 'develop'

synch cli with nodes pandora_enterprise#9500

pandora_enterprise#9500

See merge request artica/pandorafms!5198
  • Loading branch information
Jimmy Olano committed Oct 28, 2022
2 parents 0da1247 + 82a3fc1 commit 4594fb1
Show file tree
Hide file tree
Showing 2 changed files with 273 additions and 33 deletions.
76 changes: 76 additions & 0 deletions pandora_server/lib/PandoraFMS/DB.pm
Expand Up @@ -113,6 +113,10 @@ our @EXPORT = qw(
get_agentmodule_status_str
get_agentmodule_data
set_ssl_opts
db_synch_insert
db_synch_update
db_synch_delete
db_synch
$RDBMS
$RDBMS_QUOTE
$RDBMS_QUOTE_STRING
Expand Down Expand Up @@ -1672,6 +1676,78 @@ sub set_ssl_opts($) {
}
}

########################################################################
## Synch insert query with nodes.
########################################################################
sub db_synch_insert ($$$$$@) {
my ($dbh, $pa_config, $table, $query, $result, @values) = @_;

my $substr = "\"\%s\"";
$query =~ s/\?/$substr/g;
my $query_string = sprintf($query, @values);

db_synch($dbh, $pa_config, 'INSERT INTO', $table, $query_string, $result);
}

########################################################################
## Synch update query with nodes.
########################################################################
sub db_synch_update ($$$$$@) {
my ($dbh, $pa_config, $table, $query, $result, @values) = @_;

my $substr = "\"\%s\"";
$query =~ s/\?/$substr/g;
my $query_string = sprintf($query, @values);

db_synch($dbh, $pa_config, 'UPDATE', $table, $query_string, $result);
}

########################################################################
## Synch delete query with nodes.
########################################################################
sub db_synch_delete ($$$$@) {
my ($dbh, $pa_config, $table, $result, @parameters) = @_;

#Build query string.
my $query = $dbh->{Statement};

my $substr = "\"\%s\"";
$query =~ s/\?/$substr/g;

my $query_string = sprintf($query, @parameters);

db_synch($dbh, $pa_config, 'DELETE FROM', $table, $query_string, $result);
}

########################################################################
## Synch queries with nodes.
########################################################################
sub db_synch ($$$$$$) {
my ($dbh, $pa_config, $type, $table, $query, $result) = @_;
my @nodes = get_db_rows($dbh, 'SELECT * FROM tmetaconsole_setup');
foreach my $node (@nodes) {
eval {
local $SIG{__DIE__};
my @values_queue = (
safe_input($query),
$node->{'id'},
time(),
$type,
$table,
'',
$result
);

my $query_queue = 'INSERT INTO tsync_queue (`sql`, `target`, `utimestamp`, `operation`, `table`, `error`, `result`) VALUES (?, ?, ?, ?, ?, ?, ?)';
db_insert ($dbh, 'id', $query_queue, @values_queue);
};
if ($@) {
logger($pa_config, "Error add sync_queue: $@", 10);
return;
}
}
}

# End of function declaration
# End of defined Code

Expand Down

0 comments on commit 4594fb1

Please sign in to comment.