From ced22583b77ddd29b663ff07383932723cb79685 Mon Sep 17 00:00:00 2001 From: Laurent Pinsivy Date: Fri, 2 Oct 2020 10:31:46 +0200 Subject: [PATCH] enh(legacy): use full gorgone to export/import conf of Remote Server (#58) * enh(legacy): use full gorgone to export/import conf of Remote Server --- .../modules/centreon/legacycmd/class.pm | 102 +++++++++++------- .../modules/centreon/legacycmd/hooks.pm | 3 +- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/gorgone/gorgone/modules/centreon/legacycmd/class.pm b/gorgone/gorgone/modules/centreon/legacycmd/class.pm index 1a283b6153d..951672efa9a 100644 --- a/gorgone/gorgone/modules/centreon/legacycmd/class.pm +++ b/gorgone/gorgone/modules/centreon/legacycmd/class.pm @@ -255,25 +255,18 @@ sub execute_cmd { }, ); - my $centreon_dir = (defined($connector->{config}->{centreon_dir})) ? - $connector->{config}->{centreon_dir} : '/usr/share/centreon'; - my $task_id = $options{param}; - my $cmd = $centreon_dir . '/bin/centreon -u ' . $self->{clapi_user} . ' -p ' . - $self->{clapi_password} . ' -w -o CentreonWorker -a createRemoteTask -v ' . $task_id; + # Forward data use to be done by createRemoteTask as well as task_id in a gorgone command + # Command name: AddImportTaskWithParent + # Data: ['parent_id' => $task->getId()] $self->send_internal_action( - action => 'COMMAND', - target => undef, - token => $token, + action => 'ADDIMPORTTASKWITHPARENT', + token => $options{token}, + target => $options{target}, data => { - content => [ - { - command => $cmd, - metadata => { - centcore_cmd => 'SENDEXPORTFILE', - } - } - ] - }, + content => { + parent_id => $options{param}, + } + } ); } elsif ($options{cmd} eq 'SYNCTRAP') { my $cache_dir = (defined($connector->{config}->{cache_dir}) && $connector->{config}->{cache_dir} ne '') ? @@ -448,32 +441,63 @@ sub execute_cmd { ] }, ); - } elsif ($options{cmd} eq 'CREATEREMOTETASK') { - if (!defined($self->{clapi_password})) { - return (-1, 'need centreon clapi password to execute CREATEREMOTETASK command'); - } - my $centreon_dir = (defined($connector->{config}->{centreon_dir})) ? - $connector->{config}->{centreon_dir} : '/usr/share/centreon'; - my $task_id = $options{target}; - my $cmd = $centreon_dir . '/bin/centreon -u ' . $self->{clapi_user} . ' -p ' . - $self->{clapi_password} . ' -w -o CentreonWorker -a createRemoteTask -v ' . $task_id; - $self->send_internal_action( - action => 'COMMAND', - target => undef, - token => $token, + } + + return 0; +} + +sub action_addimporttaskwithparent { + my ($self, %options) = @_; + + if (!defined($options{data}->{content}->{parent_id})) { + $self->send_log( + code => GORGONE_ACTION_FINISH_KO, + token => $options{token}, data => { - content => [ - { - command => $cmd, - metadata => { - centcore_cmd => 'CREATEREMOTETASK', - } - } - ] - }, + message => "expected parent_id task ID, found '" . $options{data}->{content}->{parent_id} . "'", + } + ); + return -1; + } + + my ($status, $datas) = $self->{class_object_centreon}->custom_execute( + request => "INSERT INTO task (`type`, `status`, `parent_id`) VALUES ('import', 'pending', '" . $options{data}->{content}->{parent_id} . "')" + ); + if ($status == -1) { + $self->send_log( + code => GORGONE_ACTION_FINISH_KO, + token => $options{token}, + data => { + message => "Cannot add import task on Remote Server.", + } ); + return -1; } + my $centreon_dir = (defined($connector->{config}->{centreon_dir})) ? + $connector->{config}->{centreon_dir} : '/usr/share/centreon'; + my $cmd = $centreon_dir . '/bin/centreon -u ' . $self->{clapi_user} . ' -p ' . + $self->{clapi_password} . ' -w -o CentreonWorker -a processQueue'; + $self->send_internal_action( + action => 'COMMAND', + token => $options{token}, + data => { + content => [ + { + command => $cmd, + } + ] + }, + ); + + $self->send_log( + code => GORGONE_ACTION_FINISH_OK, + token => $options{token}, + data => { + message => 'Task inserted on Remote Server', + } + ); + return 0; } diff --git a/gorgone/gorgone/modules/centreon/legacycmd/hooks.pm b/gorgone/gorgone/modules/centreon/legacycmd/hooks.pm index e8d0eff20f7..34c5ee280bb 100644 --- a/gorgone/gorgone/modules/centreon/legacycmd/hooks.pm +++ b/gorgone/gorgone/modules/centreon/legacycmd/hooks.pm @@ -31,7 +31,8 @@ use constant NAMESPACE => 'centreon'; use constant NAME => 'legacycmd'; use constant EVENTS => [ { event => 'CENTREONCOMMAND', uri => '/command', method => 'POST' }, - { event => 'LEGACYCMDREADY' } + { event => 'LEGACYCMDREADY' }, + { event => 'ADDIMPORTTASKWITHPARENT' } ]; my $config_core;