Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh servicedisco api migrate #1529

Open
wants to merge 96 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
8187e19
enh(core): move directories for packaging
garnier-quentin Sep 25, 2019
9d5e0f6
feat(docs): prepare doc for modules
cgagnaire Sep 26, 2019
859dd49
feat(docs): add modules doc
cgagnaire Sep 27, 2019
1d91341
enh(core): use module internal send message method
garnier-quentin Dec 3, 2019
9032f83
enh(action): launch multiple actions in one call
cgagnaire Dec 26, 2019
af02d99
fix(autodiscovery): fix job cron add
cgagnaire Dec 26, 2019
cc5f2b4
enh(core): enhance logging
cgagnaire Dec 27, 2019
9751631
enh(docs): enhance endpoints declaration and other things
cgagnaire Dec 31, 2019
d72e2bd
enh(autodiscovery): refacto module
cgagnaire Mar 3, 2020
b625403
enh(autodiscovery): adapt code to new database schema
cgagnaire Mar 5, 2020
61972ca
enh(autodiscovery): add uuid creation
cgagnaire Apr 4, 2020
6e4da76
enh(core): constants class added
garnier-quentin Apr 8, 2020
e3574bb
enh(autodiscovery): handle more cases
cgagnaire Apr 8, 2020
11d0473
enh(autodiscovery): add module installation check
cgagnaire Apr 8, 2020
647b5eb
Merge branch 'master' into module-pipeline
garnier-quentin Apr 9, 2020
5f04213
fix(autodiscovery): check if result have values
cgagnaire Apr 9, 2020
42277e6
enh(autodiscovery): enh exit code handling
cgagnaire Apr 9, 2020
3475adf
enh(autodiscovery): better parse results, add global timeout
cgagnaire Apr 9, 2020
f1e8b57
fix(autodiscovery): fix returns in results process
cgagnaire Apr 30, 2020
b6aefa0
enh(autodiscovery): better management of utf8
garnier-quentin May 2, 2020
39af289
merge master
garnier-quentin May 13, 2020
a467c91
enh(autodiscovery): use listener system - simplify code
garnier-quentin May 15, 2020
9ceb2cd
enh(statistics): use listener system
garnier-quentin May 15, 2020
8bad56e
fix(discovery): escape simple quotes in raw result (#31)
cgagnaire Jun 4, 2020
215cfce
fix(autodiscovery): merge master fix quote
garnier-quentin Jun 4, 2020
5524735
Merge pull request #33 from centreon/module-pipeline
garnier-quentin Jun 4, 2020
23b0a3f
wip service discovery
garnier-quentin Aug 3, 2020
e08879e
wip service discovery
garnier-quentin Aug 3, 2020
42adafb
wip service discovery
garnier-quentin Aug 3, 2020
728b28a
wip service discovery
garnier-quentin Aug 4, 2020
5b37981
wip service discovery
garnier-quentin Aug 4, 2020
55581f4
wip service discovery
garnier-quentin Aug 4, 2020
33c643d
wip service discovery
garnier-quentin Aug 4, 2020
bf3a2c3
wip service discovery
garnier-quentin Aug 5, 2020
cd1d872
wip service discovery
garnier-quentin Aug 5, 2020
bcd3f9f
wip service discovery
garnier-quentin Aug 5, 2020
387d019
wip service discovery
garnier-quentin Aug 5, 2020
51d217e
wip service discovery
garnier-quentin Aug 5, 2020
4469a39
wip service discovery
garnier-quentin Aug 6, 2020
eeb321f
wip service discovery
garnier-quentin Aug 6, 2020
848705a
wip service discovery
garnier-quentin Aug 6, 2020
dcf3e90
fix(disco): fix service discovery - filter rules
garnier-quentin Sep 1, 2020
3e47e2b
Merge pull request #45 from centreon/fix-svcdisco-fitler-rules
garnier-quentin Sep 1, 2020
cd1a023
Mon 5777 - Cron host discovery (#46)
garnier-quentin Sep 25, 2020
d63d233
enh(tapi): centreonv2 - manage redirect login default (#53)
garnier-quentin Sep 30, 2020
3961213
enh(discovery): check module installed + paused not an error (#54)
garnier-quentin Sep 30, 2020
1953d10
fix(autodiscovery): use uuid_parameters instead of uuid_attributes (#55)
cgagnaire Oct 1, 2020
d499f19
MON-6109: failed command because of timeout does not store message (#59)
garnier-quentin Oct 7, 2020
6a979bb
MON-6110: timeout is not retrieved for forced execution (#60)
garnier-quentin Oct 7, 2020
fedddae
Mon 6111 (#61)
garnier-quentin Oct 7, 2020
3406fe1
MON-6114: catch API returned message instead of request message (#62)
garnier-quentin Oct 7, 2020
17f8d14
MON-6121: request errors filling up logs on standard install (#63)
garnier-quentin Oct 7, 2020
defb968
MON-6116: decode JSON fails when not utf8 (#64)
garnier-quentin Oct 8, 2020
c5f2ac2
MON-6217: some errors not catched when timeout (#69)
garnier-quentin Oct 27, 2020
01104c4
Mon 6281: Service discovery email not working properly (#73)
garnier-quentin Nov 5, 2020
754e050
MON-6317: services discovered flaps (#76)
garnier-quentin Nov 13, 2020
3618e63
MON-6356: Versions endpoint returns empty array instead of hash (#78)
garnier-quentin Nov 19, 2020
c24c9f9
fix(core): DB transaction issue (#84)
garnier-quentin Dec 4, 2020
9396f2d
fix(servicediscovery): contact group is not working (#86)
garnier-quentin Dec 9, 2020
4e0d2d1
enh(proxy): better management of utf8 for ssh nodes
garnier-quentin Dec 9, 2020
0fa9f0b
enh(core): more harden ZMQ communication (#95)
garnier-quentin Jan 4, 2021
93732ac
Fix documentation (#102)
bmareau Jan 19, 2021
51eb4e9
enh(core): optimize zmq communication (MON-6761) (#110)
garnier-quentin Feb 25, 2021
390bad1
enh(doc): update autodiscovery doc (#111)
cgagnaire Mar 3, 2021
341d3db
MON-7137: add logging options (#120)
garnier-quentin Apr 16, 2021
0ebceae
fix(autodiscovery): filter_pollers option (#122) (MON-7157)
garnier-quentin Apr 19, 2021
4ab7648
enh(action): add whitelist commands (MON-7412)
garnier-quentin Jun 4, 2021
96e33b6
fix(centreon): centreonv2 class missing module load (#153)
garnier-quentin Sep 23, 2021
79922f4
enh(hostdisco): add token to post command (#169)
garnier-quentin Nov 26, 2021
ed0d47a
fix(autodisco): handle advanced option for service discovery - use Sa…
garnier-quentin Nov 30, 2021
f4ab530
add(module): new httpserver (#173)
garnier-quentin Dec 14, 2021
3d8a974
add capability to crypt internal communication (#205)
garnier-quentin Feb 18, 2022
0314a57
MON-14818: encoding fixed (MON-14894) (#263)
garnier-quentin Sep 1, 2022
31d6e0b
merge centreon-gorgone
kduret Nov 25, 2022
2b31358
enh(gorgone): use zmq ffi binding (#1057)
garnier-quentin Mar 10, 2023
e97574c
enh(gorgone-hostdisco): install missing plugins (#1092)
garnier-quentin Mar 24, 2023
8e7e72a
enh(gorgone-svc-disco): can change macro before the service name crea…
garnier-quentin Mar 31, 2023
0eebb8b
enh(gorgone-servicediscovery): use credentials from centreon vault fo…
sdepassio May 10, 2023
cae6b6f
Centreon 23.10 (Jira release #19426#)
paloth Oct 30, 2023
4113a99
MON-22657 Sync Centreon OSS next 23.10 (#2482)
pkippes Oct 31, 2023
44c9634
Sync dev-23.10.x vers develop oss (#2487)
pkippes Oct 31, 2023
c4d3bc2
Centreon 24.04 (Jira release #19608#)
paloth Jan 25, 2024
fc0cb51
Empty-Commit
tuntoja Jan 26, 2024
21bc0d3
MON-34022 Sync Centreon OSS next 24.04 (Jira release #34022#) (#3181)
pkippes Jan 26, 2024
6bbc97c
Mon-32851 [gorgone] service auto-discovery only the services associat…
Evan-Adam Feb 29, 2024
3606bc5
Revert "Mon-32851 [gorgone] service auto-discovery only the services …
bouda1 Mar 19, 2024
64f5851
fix(gorgone/servicediscovery): lost discoveries are recovered!
cgagnaire Mar 1, 2024
c83e955
fix(gorgone/servicediscovery): pollers are reload multiple times
cgagnaire Mar 5, 2024
618316b
Centreon 24.04 (Jira release #19735#)
paloth Apr 9, 2024
1b792fe
Merge branch 'master' into MON-37060-sync-release-oss
tuntoja Apr 9, 2024
a0e0c8c
MON-37060 Sync Centreon OSS next 24.04 (Jira release #37060#) (#3826)
pkippes Apr 10, 2024
572e373
MON-37899-community-pr-change-level-of-some-gorgone-logs (#3648)
Evan-Adam Apr 15, 2024
d796a77
enh(gorgone/servicediscovery): use rest api instead of clapi
cgagnaire Apr 16, 2024
5bd5e31
enh(gorgone/servicediscovery): map options to be used in config files
cgagnaire Apr 16, 2024
fb3789a
Merge remote-tracking branch 'centreon-gorgone/enh-servicedisco-api' …
kduret Jul 11, 2024
6a0d344
restore unexpected changes
kduret Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions gorgone/docs/modules/centreon/autodiscovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ This module aims to extend Centreon Autodiscovery server functionalities.

## Configuration

| Directive | Description | Default value |
|:----------------|:-----------------------------------------------------------------------|:--------------|
| global\_timeout | Time in seconds before a discovery command is considered timed out | `300` |
| check\_interval | Time in seconds defining frequency at which results will be search for | `15` |
| Directive | Description | Default value |
| :----------------------------------- | :------------------------------------------------------------------------------------------------ | :------------ |
| global\_timeout | Time in seconds before a discovery command is considered timed out | `300` |
| check\_interval | Time in seconds defining frequency at which results will be search for | `15` |
| service\_parrallel\_commands\_poller | Number of commands run simultaneously on each Poller | `8` |
| service\_check\_interval | Time in seconds defining frequency at which results will be search for (for services discoveries) | `15` |
| service\_timeout | Time in seconds before a service discovery command is considered timed out | `90` |

#### Example

Expand All @@ -19,6 +22,9 @@ package: "gorgone::modules::centreon::autodiscovery::hooks"
enable: true
global_timeout: 60
check_interval: 10
service_parrallel_commands_poller: 15
service_check_interval: 5
service_timeout: 60
```

## Events
Expand Down Expand Up @@ -192,9 +198,9 @@ curl --request POST "https://hostname:8443/api/centreon/autodiscovery/hosts" \

#### Headers

| Header | Value |
|:-------|:-----------------|
| Accept | application/json |
| Header | Value |
|:-------------|:-----------------|
| Accept | application/json |

#### Path variables

Expand Down
36 changes: 31 additions & 5 deletions gorgone/gorgone/class/tpapi/centreonv2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ sub error {
return $self->{error};
}

sub get_username {
my ($self, %options) = @_;

if ($self->{is_error} == 1) {
return undef;
}

return $self->{username};
}

sub set_configuration {
my ($self, %options) = @_;

Expand Down Expand Up @@ -197,7 +207,8 @@ sub request {
critical_status => ''
);

my $decoded = $self->json_decode(content => $content);
my $decoded = undef;
$decoded = $self->json_decode(content => $content) if (defined($content) && $content ne "");

# code 403 means forbidden (token not good maybe)
if ($self->{http}->get_code() == 403) {
Expand All @@ -217,8 +228,6 @@ sub request {
return 1;
}

return 1 if (!defined($decoded));

return (0, $decoded);
}

Expand All @@ -238,7 +247,7 @@ sub get_monitoring_hosts {
if (defined($options{search})) {
$get_param = ['search=' . $options{search}];
}

return $self->request(
method => 'GET',
endpoint => $endpoint,
Expand All @@ -253,7 +262,7 @@ sub get_platform_versions {
return $self->request(
method => 'GET',
endpoint => '/platform/versions'
);
);
}

sub get_scheduling_jobs {
Expand All @@ -272,6 +281,23 @@ sub get_scheduling_jobs {
);
}

sub monitoring_server_generate_reload {
my ($self, %options) = @_;

if (!defined($options{monitoring_server_id})) {
$self->{is_error} = 1;
$self->{error} = 'monitoring_server_id option missing';
return 1;
}

# {protocol}://{server}:{port}/centreon/api/{version}/configuration/monitoring-servers/{monitoring_server_id}/generate-and-reload
my $endpoint = '/configuration/monitoring-servers/' . $options{monitoring_server_id} . '/generate-and-reload';
return $self->request(
method => 'GET',
endpoint => $endpoint
);
}

sub DESTROY {
my ($self) = @_;

Expand Down
8 changes: 1 addition & 7 deletions gorgone/gorgone/modules/centreon/autodiscovery/class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use warnings;
use gorgone::standard::library;
use gorgone::standard::constants qw(:all);
use gorgone::modules::centreon::autodiscovery::services::discovery;
use gorgone::class::tpapi::clapi;
use gorgone::class::tpapi::centreonv2;
use gorgone::class::sqlquery;
use gorgone::class::frame;
Expand Down Expand Up @@ -69,7 +68,6 @@ sub new {
$options{config}->{global_timeout} =~ /(\d+)/) ? $1 : 300;
$connector->{check_interval} = (defined($options{config}->{check_interval}) &&
$options{config}->{check_interval} =~ /(\d+)/) ? $1 : 15;
$connector->{tpapi_clapi_name} = defined($options{config}->{tpapi_clapi}) && $options{config}->{tpapi_clapi} ne '' ? $options{config}->{tpapi_clapi} : 'clapi';
$connector->{tpapi_centreonv2_name} = defined($options{config}->{tpapi_centreonv2}) && $options{config}->{tpapi_centreonv2} ne '' ?
$options{config}->{tpapi_centreonv2} : 'centreonv2';

Expand Down Expand Up @@ -1056,7 +1054,7 @@ sub action_launchservicediscovery {
my $svc_discovery = gorgone::modules::centreon::autodiscovery::services::discovery->new(
module_id => $self->{module_id},
logger => $self->{logger},
tpapi_clapi => $self->{tpapi_clapi},
tpapi_centreonv2 => $self->{tpapi_centreonv2},
internal_socket => $self->{internal_socket},
config => $self->{config},
config_core => $self->{config_core},
Expand Down Expand Up @@ -1144,10 +1142,6 @@ sub periodic_exec {
sub run {
my ($self, %options) = @_;

$self->{tpapi_clapi} = gorgone::class::tpapi::clapi->new();
$self->{tpapi_clapi}->set_configuration(
config => $self->{tpapi}->get_configuration(name => $self->{tpapi_clapi_name})
);
$self->{tpapi_centreonv2} = gorgone::class::tpapi::centreonv2->new();
my ($status) = $self->{tpapi_centreonv2}->set_configuration(
config => $self->{tpapi}->get_configuration(name => $self->{tpapi_centreonv2_name}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ sub new {
$connector->{class_object_centreon} = $options{class_object_centreon};
$connector->{class_object_centstorage} = $options{class_object_centstorage};
$connector->{class_autodiscovery} = $options{class_autodiscovery};
$connector->{tpapi_clapi} = $options{tpapi_clapi};
$connector->{tpapi_centreonv2} = $options{tpapi_centreonv2};
$connector->{mail_subject} = defined($connector->{config}->{mail_subject}) ? $connector->{config}->{mail_subject} : 'Centreon Auto Discovery';
$connector->{mail_from} = defined($connector->{config}->{mail_from}) ? $connector->{config}->{mail_from} : 'centreon-autodisco';
$connector->{service_parrallel_commands_poller} = (defined($options{config}->{service_parrallel_commands_poller}) &&
$options{config}->{service_parrallel_commands_poller} =~ /(\d+)/) ? $1 : 8;
$connector->{service_check_interval} = (defined($options{config}->{service_check_interval}) &&
$options{config}->{service_check_interval} =~ /(\d+)/) ? $1 : 15;
$connector->{service_timeout} = (defined($options{config}->{service_timeout}) &&
$options{config}->{service_timeout} =~ /(\d+)/) ? $1 : 90;

$connector->{service_pollers} = {};
$connector->{audit_user_id} = undef;
$connector->{service_parrallel_commands_poller} = 8;
$connector->{service_current_commands_poller} = {};
$connector->{finished} = 0;
$connector->{post_execution} = 0;
Expand Down Expand Up @@ -188,17 +193,11 @@ sub restart_pollers {
my $poller_ids = {};
foreach my $poller_id (keys %{$self->{discovery}->{pollers_reload}}) {
$self->{logger}->writeLogInfo("[autodiscovery] -servicediscovery- $self->{uuid} generate poller config '" . $poller_id . "'");
$self->send_internal_action({
action => 'COMMAND',
token => $self->{discovery}->{token} . ':config',
data => {
content => [
{
command => $self->{tpapi_clapi}->get_applycfg_command(poller_id => $poller_id)
}
]
}
});

my ($status, $results) = $self->{tpapi_centreonv2}->monitoring_server_generate_reload(monitoring_server_id => $poller_id);
if ($status != 0) {
$self->{logger}->writeLogError("[autodiscovery] -servicediscovery- $self->{uuid} cannot generate poller config - " . $self->{tpapi_centreonv2}->error());
}
}
}

Expand Down Expand Up @@ -785,8 +784,8 @@ sub service_execute_commands {
event => 'SERVICEDISCOVERYLISTENER',
target => $poller_id,
token => 'svc-disco-' . $self->{uuid} . '-' . $rule_id . '-' . $host_id,
timeout => 120,
log_pace => 15
timeout => $self->{service_timeout} + $self->{service_check_interval} + 15,
log_pace => $self->{service_check_interval}
}
]
});
Expand All @@ -800,7 +799,7 @@ sub service_execute_commands {
content => [
{
command => $command,
timeout => 90
timeout => $self->{service_timeout}
}
]
}
Expand Down Expand Up @@ -850,13 +849,18 @@ sub launchdiscovery {
return -1;
}

if (!defined($self->{tpapi_clapi}->get_username())) {
$self->send_log_msg_error(token => $options{token}, subname => 'servicediscovery', number => $self->{uuid}, message => 'clapi ' . $self->{tpapi_clapi}->error());
if (!defined($self->{tpapi_centreonv2}->get_username())) {
$self->send_log_msg_error(
token => $options{token},
subname => 'servicediscovery',
number => $self->{uuid},
message => 'cannot get api user: ' . $self->{tpapi_centreonv2}->error()
);
return -1;
}
($status, $message, my $user_id) = gorgone::modules::centreon::autodiscovery::services::resources::get_audit_user_id(
class_object_centreon => $self->{class_object_centreon},
clapi_user => $self->{tpapi_clapi}->get_username()
user => $self->{tpapi_centreonv2}->get_username()
);
if ($status < 0) {
$self->send_log_msg_error(token => $options{token}, subname => 'servicediscovery', number => $self->{uuid}, message => $message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ sub get_audit_user_id {

my ($status, $contacts) = $options{class_object_centreon}->custom_execute(
request => 'SELECT contact_id FROM contact WHERE contact_alias = ?',
bind_values => [$options{clapi_user}],
bind_values => [$options{user}],
mode => 2
);
if ($status == -1) {
Expand Down Expand Up @@ -458,7 +458,7 @@ sub get_macros_host {
my $macro_value = $_->[1];
my $is_password = $_->[2];
# Replace macro value if a vault is used
if (defined($options{vault_count}) && $options{vault_count} > 0 && defined($is_password) && $is_password == 1) {
if (defined($options{vault_count}) && defined($is_password) && $is_password == 1) {
set_macro(\%macros, $macro_name, "{" . $macro_name . "::secret::" . $macro_value . "}");
} else {
set_macro(\%macros, $macro_name, $macro_value);
Expand Down