From 490945440b668dd9700b3ea25d5571c682ce6307 Mon Sep 17 00:00:00 2001 From: omercier Date: Thu, 20 Mar 2025 11:29:56 +0100 Subject: [PATCH 1/4] fix(ci): add missing image + fix path for tests on noble --- .github/actions/test-plugins/action.yml | 4 +++- .github/docker/testing/Dockerfile.testing-plugins-alma8 | 2 +- .github/docker/testing/Dockerfile.testing-plugins-alma9 | 2 +- .github/docker/testing/Dockerfile.testing-plugins-bookworm | 2 +- .github/docker/testing/Dockerfile.testing-plugins-bullseye | 2 +- .github/docker/testing/Dockerfile.testing-plugins-jammy | 2 +- .github/docker/testing/Dockerfile.testing-plugins-noble | 4 ++-- .github/workflows/plugins.yml | 4 ++-- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/actions/test-plugins/action.yml b/.github/actions/test-plugins/action.yml index bbcf5bfd76..ac24b7d1c6 100644 --- a/.github/actions/test-plugins/action.yml +++ b/.github/actions/test-plugins/action.yml @@ -24,4 +24,6 @@ runs: - name: Install, test and remove plugin shell: bash - run: python3 .github/scripts/test-all-plugins.py ${{ inputs.package-extension }} ${{ inputs.plugin-list }} + run: | + [[ -f /.venv/bin/activate ]] && source /.venv/bin/activate + python3 .github/scripts/test-all-plugins.py ${{ inputs.package-extension }} ${{ inputs.plugin-list }} diff --git a/.github/docker/testing/Dockerfile.testing-plugins-alma8 b/.github/docker/testing/Dockerfile.testing-plugins-alma8 index 22d2d9c07a..71abc16087 100644 --- a/.github/docker/testing/Dockerfile.testing-plugins-alma8 +++ b/.github/docker/testing/Dockerfile.testing-plugins-alma8 @@ -12,7 +12,7 @@ dnf clean all dnf install -y python3.11 python3.11-pip pip3.11 install robotframework robotframework-examples # Install snmpsim -pip3.11 install snmpsim-lextudio +pip3.11 install snmpsim # Install node curl -fsSL https://rpm.nodesource.com/setup_21.x | bash - diff --git a/.github/docker/testing/Dockerfile.testing-plugins-alma9 b/.github/docker/testing/Dockerfile.testing-plugins-alma9 index d5cead3a20..95edbe7640 100644 --- a/.github/docker/testing/Dockerfile.testing-plugins-alma9 +++ b/.github/docker/testing/Dockerfile.testing-plugins-alma9 @@ -12,7 +12,7 @@ dnf clean all dnf install -y python3.11 python3.11-pip pip3.11 install robotframework robotframework-examples # Install snmpsim -pip3.11 install snmpsim-lextudio +pip3.11 install snmpsim # Install node curl -fsSL https://rpm.nodesource.com/setup_21.x | bash - diff --git a/.github/docker/testing/Dockerfile.testing-plugins-bookworm b/.github/docker/testing/Dockerfile.testing-plugins-bookworm index f5e70048ea..48d6e00221 100644 --- a/.github/docker/testing/Dockerfile.testing-plugins-bookworm +++ b/.github/docker/testing/Dockerfile.testing-plugins-bookworm @@ -28,7 +28,7 @@ apt-get install -y python3-dev python3-pip rm -rf /usr/lib/python3.11/EXTERNALLY-MANAGED pip3 install robotframework robotframework-examples # Install snmpsim -pip3 install snmpsim-lextudio +pip3 install snmpsim # Install nodejs curl -fsSL https://deb.nodesource.com/setup_21.x | bash - &&\ diff --git a/.github/docker/testing/Dockerfile.testing-plugins-bullseye b/.github/docker/testing/Dockerfile.testing-plugins-bullseye index 171240fb7f..87700be3ac 100644 --- a/.github/docker/testing/Dockerfile.testing-plugins-bullseye +++ b/.github/docker/testing/Dockerfile.testing-plugins-bullseye @@ -27,7 +27,7 @@ apt-get update apt-get install -y python3 python3-dev python3-pip pip3 install robotframework robotframework-examples # Install snmpsim -pip3 install snmpsim-lextudio +pip3 install snmpsim # Install nodejs curl -fsSL https://deb.nodesource.com/setup_21.x | bash - &&\ diff --git a/.github/docker/testing/Dockerfile.testing-plugins-jammy b/.github/docker/testing/Dockerfile.testing-plugins-jammy index 0678ac512b..7519cd7103 100644 --- a/.github/docker/testing/Dockerfile.testing-plugins-jammy +++ b/.github/docker/testing/Dockerfile.testing-plugins-jammy @@ -27,7 +27,7 @@ apt-get update apt-get install -y python3 python3-dev python3-pip pip3 install robotframework robotframework-examples # Install snmpsim -pip3 install snmpsim-lextudio +pip3 install snmpsim # Install nodejs curl -fsSL https://deb.nodesource.com/setup_21.x | bash - &&\ diff --git a/.github/docker/testing/Dockerfile.testing-plugins-noble b/.github/docker/testing/Dockerfile.testing-plugins-noble index 77260b47ff..4b89178e3d 100644 --- a/.github/docker/testing/Dockerfile.testing-plugins-noble +++ b/.github/docker/testing/Dockerfile.testing-plugins-noble @@ -29,9 +29,9 @@ python3 -m venv .venv source .venv/bin/activate # Install Robotframework apt-get install -y python3 python3-dev python3-pip -.venv/bin/pip3 install robotframework robotframework-examples +pip3 install robotframework robotframework-examples # Install snmpsim -.venv/bin/pip3 install snmpsim-lextudio +pip3 install snmpsim # Install nodejs curl -fsSL https://deb.nodesource.com/setup_21.x | bash - &&\ diff --git a/.github/workflows/plugins.yml b/.github/workflows/plugins.yml index e4d67fe5b8..2052a609d2 100644 --- a/.github/workflows/plugins.yml +++ b/.github/workflows/plugins.yml @@ -98,7 +98,7 @@ jobs: strategy: fail-fast: false matrix: - image: [unit-tests-alma8, unit-tests-alma9, unit-tests-bullseye, unit-tests-bullseye-arm64, unit-tests-bookworm, unit-tests-jammy] + image: [unit-tests-alma8, unit-tests-alma9, unit-tests-bullseye, unit-tests-bullseye-arm64, unit-tests-bookworm, unit-tests-jammy, unit-tests-noble] include: - runner_name: ubuntu-24.04 - package_extension: rpm @@ -317,7 +317,7 @@ jobs: strategy: fail-fast: false matrix: - image: [testing-plugins-alma8, testing-plugins-alma9, testing-plugins-jammy, testing-plugins-bullseye, testing-plugins-bookworm] + image: [testing-plugins-alma8, testing-plugins-alma9, testing-plugins-jammy, testing-plugins-bullseye, testing-plugins-bookworm, testing-plugins-noble, testing-plugins-bullseye-arm64] include: - runner_name: ubuntu-24.04 - package_extension: rpm From fab96be847eacd8cfec354c59e336462eae7bb2f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 15 Apr 2026 08:48:02 -0400 Subject: [PATCH 2/4] wip --- .../saas/adobestatus/restapi/custom/api.pm | 179 ++++++++++++++++++ .../adobestatus/restapi/mode/components.pm | 137 ++++++++++++++ .../restapi/mode/listcomponents.pm | 108 +++++++++++ src/apps/saas/adobestatus/restapi/plugin.pm | 54 ++++++ 4 files changed, 478 insertions(+) create mode 100644 src/apps/saas/adobestatus/restapi/custom/api.pm create mode 100644 src/apps/saas/adobestatus/restapi/mode/components.pm create mode 100644 src/apps/saas/adobestatus/restapi/mode/listcomponents.pm create mode 100644 src/apps/saas/adobestatus/restapi/plugin.pm diff --git a/src/apps/saas/adobestatus/restapi/custom/api.pm b/src/apps/saas/adobestatus/restapi/custom/api.pm new file mode 100644 index 0000000000..64672c6dbc --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/custom/api.pm @@ -0,0 +1,179 @@ +# +# Copyright 2026-Present Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package apps::atlassian::statuspage::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; +use Digest::MD5 qw(md5_hex); + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + 'api-endpoint:s' => { name => 'api_endpoint' }, + 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'warning-http-status:s' => { name => 'warning_http_status' }, + 'critical-http-status:s' => { name => 'critical_http_status' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl'); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults {} + +sub check_options { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{option_results}->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{option_results}->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{option_results}->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; + $self->{option_results}->{api_endpoint} = (defined($self->{option_results}->{api_endpoint})) ? $self->{option_results}->{api_endpoint} : '/api/v2/'; + $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300'; + $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; + $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; + + if ($self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); + $self->{output}->option_exit(); + } + + return 0; +} + +sub settings { + my ($self, %options) = @_; + + return if (defined($self->{settings_done})); + $self->{http}->set_options(%{$self->{option_results}}); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{settings_done} = 1; +} + +sub get_connection_info { + my ($self, %options) = @_; + + return $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + my ($content) = $self->{http}->request( + url_path => $self->{option_results}->{api_endpoint} . $options{request}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status} + ); + + if (!defined($content) || $content eq '') { + $self->{output}->add_option_msg(short_msg => "API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); + $self->{output}->option_exit(); + } + + my $decoded; + eval { + $decoded = JSON::XS->new->allow_nonref(1)->utf8->decode($content); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); + $self->{output}->option_exit(); + } + + return $decoded; +} + +sub get_components { + my ($self, %options) = @_; + + return $self->request_api(request => 'components.json'); +} + +1; + +__END__ + +=head1 NAME + +Public JSON API + +=head1 API OPTIONS + +Public JSON API + +=over 8 + +=item B<--hostname> + +Set hostname. + +=item B<--port> + +Port used (default: 443) + +=item B<--proto> + +Specify https if needed (default: 'https') + +=item B<--api-endpoint> + +Argos API requests endpoint (default: '/api/v2/') + +=item B<--timeout> + +Set timeout in seconds (default: 30). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/src/apps/saas/adobestatus/restapi/mode/components.pm b/src/apps/saas/adobestatus/restapi/mode/components.pm new file mode 100644 index 0000000000..7022510e73 --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/mode/components.pm @@ -0,0 +1,137 @@ +# +# Copyright 2026-Present Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::atlassian::statuspage::mode::components; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::constants qw(:counters :values); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_component_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub prefix_component_output { + my ($self, %options) = @_; + + return "Component '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'components', type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_component_output', message_multiple => 'All components are ok' } + ]; + + $self->{maps_counters}->{components} = [ + { + label => 'status', + type => COUNTER_KIND_TEXT, + warningd_default => '%{status} =~ /degraded_performance|partial_outage/', + critical_default => '%{status} =~ /major_outage/', + set => { + key_values => [ + { name => 'status' }, { name => 'name' } + ], + closure_custom_output => $self->can('custom_component_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'filter-component-id:s' => { name => 'filter_component_id' }, + 'filter-component-name:s' => { name => 'filter_component_name' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->get_components(); + + $self->{components} = {}; + foreach (@{$results->{components}}) { + next if (defined($self->{option_results}->{filter_component_id}) && $self->{option_results}->{filter_component_id} ne '' && + $_->{id} !~ /$self->{option_results}->{filter_component_id}/); + next if (defined($self->{option_results}->{filter_component_name}) && $self->{option_results}->{filter_component_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_component_name}/); + + $self->{components}->{ $_->{id} } = { + name => $_->{name}, + status => $_->{status} + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check components. + +=over 8 + +=item B<--filter-component-id> + +Filter components by ID (can be a regexp). + +=item B<--filter-component-name> + +Filter components by name (can be a regexp). + +=item B<--unknown-status> + +Define the conditions to match for the status to be UNKNOWN. +You can use the following variables: %{status}, %{name} + +=item B<--warning-status> + +Define the conditions to match for the status to be WARNING (default: '%{status} =~ /degraded_performance|partial_outage/'). +You can use the following variables: %{status}, %{name} + +=item B<--critical-status> + +Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /major_outage/'). +You can use the following variables: %{status}, %{name} + +=back + +=cut diff --git a/src/apps/saas/adobestatus/restapi/mode/listcomponents.pm b/src/apps/saas/adobestatus/restapi/mode/listcomponents.pm new file mode 100644 index 0000000000..fc95c3a8f0 --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/mode/listcomponents.pm @@ -0,0 +1,108 @@ +# +# Copyright 2026-Present Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::atlassian::statuspage::mode::listcomponents; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $components = $options{custom}->get_components(); + + my $results = []; + foreach (@{$components->{components}}) { + push @$results, $_; + } + return $results; +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach (@$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[id: %s][name: %s]', + $_->{id}, + $_->{name} + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List components:' + ); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['id', 'name']); +} + +sub disco_show { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach (@$results) { + $self->{output}->add_disco_entry( + id => $_->{id}, + name => $_->{name} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List components. + +=over 8 + +=back + +=cut diff --git a/src/apps/saas/adobestatus/restapi/plugin.pm b/src/apps/saas/adobestatus/restapi/plugin.pm new file mode 100644 index 0000000000..567ba762c6 --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2026-Present Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::saas::adobestatus::restapi::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{modes} = { + 'incidents' => 'apps::saas::adobestatus::restapi::mode::incidents', + 'list-products' => 'apps::saas::adobestatus::restapi::mode::listproducts' + }; + + $self->{custom_modes}->{json} = 'apps::atlassian::statuspage::custom::json'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Adobe Status using API or public JSON. + +=over 8 + +=back + +=cut From d2a36fd0de1cfafb999177b7a2145e39a74ebfe1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 15 Apr 2026 09:59:49 -0400 Subject: [PATCH 3/4] wip --- .../restapi/custom/{api.pm => public.pm} | 99 +++++++++++-------- .../mode/{components.pm => incidents.pm} | 0 .../{listcomponents.pm => listproducts.pm} | 26 ++--- src/apps/saas/adobestatus/restapi/plugin.pm | 2 +- 4 files changed, 67 insertions(+), 60 deletions(-) rename src/apps/saas/adobestatus/restapi/custom/{api.pm => public.pm} (57%) rename src/apps/saas/adobestatus/restapi/mode/{components.pm => incidents.pm} (100%) rename src/apps/saas/adobestatus/restapi/mode/{listcomponents.pm => listproducts.pm} (81%) diff --git a/src/apps/saas/adobestatus/restapi/custom/api.pm b/src/apps/saas/adobestatus/restapi/custom/public.pm similarity index 57% rename from src/apps/saas/adobestatus/restapi/custom/api.pm rename to src/apps/saas/adobestatus/restapi/custom/public.pm index 64672c6dbc..d2724b7260 100644 --- a/src/apps/saas/adobestatus/restapi/custom/api.pm +++ b/src/apps/saas/adobestatus/restapi/custom/public.pm @@ -17,13 +17,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -package apps::atlassian::statuspage::custom::api; +package apps::saas::adobestatus::restapi::custom::public; use strict; use warnings; use centreon::plugins::http; use JSON::XS; use Digest::MD5 qw(md5_hex); +use centreon::plugins::misc qw/is_empty json_decode/; +use centreon::plugins::constants qw(:messages); sub new { my ($class, %options) = @_; @@ -41,17 +43,16 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'port:s' => { name => 'port' }, - 'proto:s' => { name => 'proto' }, - 'timeout:s' => { name => 'timeout' }, - 'api-endpoint:s' => { name => 'api_endpoint' }, - 'unknown-http-status:s' => { name => 'unknown_http_status' }, + 'hostname:s' => { name => 'hostname', default => 'data.status.adobe.com' }, + 'port:s' => { name => 'port', default => 443 }, + 'proto:s' => { name => 'proto', default => 'https' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'unknown-http-status:s' => { name => 'unknown_http_status', default => '%{http_code} < 200 or %{http_code} >= 300' }, 'warning-http-status:s' => { name => 'warning_http_status' }, 'critical-http-status:s' => { name => 'critical_http_status' } }); } - $options{options}->add_help(package => __PACKAGE__, sections => 'API OPTIONS', once => 1); + $options{options}->add_help(package => __PACKAGE__, sections => 'PUBLIC API OPTIONS', once => 1); $self->{output} = $options{output}; $self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl'); @@ -70,18 +71,8 @@ sub set_defaults {} sub check_options { my ($self, %options) = @_; - $self->{option_results}->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; - $self->{option_results}->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; - $self->{option_results}->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; - $self->{option_results}->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; - $self->{option_results}->{api_endpoint} = (defined($self->{option_results}->{api_endpoint})) ? $self->{option_results}->{api_endpoint} : '/api/v2/'; - $self->{unknown_http_status} = (defined($self->{option_results}->{unknown_http_status})) ? $self->{option_results}->{unknown_http_status} : '%{http_code} < 200 or %{http_code} >= 300'; - $self->{warning_http_status} = (defined($self->{option_results}->{warning_http_status})) ? $self->{option_results}->{warning_http_status} : ''; - $self->{critical_http_status} = (defined($self->{option_results}->{critical_http_status})) ? $self->{option_results}->{critical_http_status} : ''; - - if ($self->{option_results}->{hostname} eq '') { - $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); - $self->{output}->option_exit(); + if (is_empty($self->{option_results}->{hostname})) { + $self->{output}->option_exit(short_msg => "Need to specify hostname option."); } return 0; @@ -96,18 +87,12 @@ sub settings { $self->{settings_done} = 1; } -sub get_connection_info { - my ($self, %options) = @_; - - return $self->{option_results}->{hostname} . ':' . $self->{option_results}->{port}; -} - sub request_api { my ($self, %options) = @_; $self->settings(); my ($content) = $self->{http}->request( - url_path => $self->{option_results}->{api_endpoint} . $options{request}, + url_path => $options{endpoint}, unknown_status => $self->{unknown_http_status}, warning_status => $self->{warning_http_status}, critical_status => $self->{critical_http_status} @@ -118,22 +103,54 @@ sub request_api { $self->{output}->option_exit(); } - my $decoded; - eval { - $decoded = JSON::XS->new->allow_nonref(1)->utf8->decode($content); - }; - if ($@) { - $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); - $self->{output}->option_exit(); - } + my $decoded = json_decode( + $content, + errstr => MSG_JSON_DECODE_ERROR, + output => $self->{output} + ); return $decoded; } -sub get_components { +sub get_incidents { + my ($self, %options) = @_; + + my $response = $self->request_api(endpoint => '/adobestatus/StatusEvents'); + + my $current_incidents = {}; + foreach my $incident (values %{ $response->{incidentEvent}->{incidents}}) { + foreach my $productinc (values %{$incident->{products}}) { + next if (!defined($productinc->{endedOn}) || $productinc->{endedOn} == 0); + + $current_incidents->{ $productinc->{id} } = [] if (!defined($current_incidents->{ $productinc->{id} })); + + foreach ( sort { $b <=> $a } keys(%{$productinc->{history}}) ) { + push @{$current_incidents->{ $productinc->{id} }}, { + status => $_->{status}, + statusTime => $_->{statusTime}, + severity => $_->{severity}, + customerImpact => $_->{customerImpact}, + messageEn => $response->{incidentEvent}->{messages}->{en}->{ $_->{messageToken} }, + }; + last; + } + } + } + + return $current_incidents; +} + +sub get_products { my ($self, %options) = @_; - return $self->request_api(request => 'components.json'); + my $response = $self->request_api(endpoint => '/adobestatus/SnowServiceRegistry'); + + my $products = {}; + foreach (values %{$response->{products}}) { + $products->{ $_->{id} } = $_->{name}; + } + + return $products; } 1; @@ -144,7 +161,7 @@ __END__ Public JSON API -=head1 API OPTIONS +=head1 PUBLIC API OPTIONS Public JSON API @@ -152,7 +169,7 @@ Public JSON API =item B<--hostname> -Set hostname. +Define hostname (default: C<'data.status.adobe.com'>). =item B<--port> @@ -162,10 +179,6 @@ Port used (default: 443) Specify https if needed (default: 'https') -=item B<--api-endpoint> - -Argos API requests endpoint (default: '/api/v2/') - =item B<--timeout> Set timeout in seconds (default: 30). diff --git a/src/apps/saas/adobestatus/restapi/mode/components.pm b/src/apps/saas/adobestatus/restapi/mode/incidents.pm similarity index 100% rename from src/apps/saas/adobestatus/restapi/mode/components.pm rename to src/apps/saas/adobestatus/restapi/mode/incidents.pm diff --git a/src/apps/saas/adobestatus/restapi/mode/listcomponents.pm b/src/apps/saas/adobestatus/restapi/mode/listproducts.pm similarity index 81% rename from src/apps/saas/adobestatus/restapi/mode/listcomponents.pm rename to src/apps/saas/adobestatus/restapi/mode/listproducts.pm index fc95c3a8f0..a9ee1767df 100644 --- a/src/apps/saas/adobestatus/restapi/mode/listcomponents.pm +++ b/src/apps/saas/adobestatus/restapi/mode/listproducts.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package apps::atlassian::statuspage::mode::listcomponents; +package apps::saas::adobestatus::restapi::mode::listproducts; use base qw(centreon::plugins::mode); @@ -44,32 +44,26 @@ sub check_options { sub manage_selection { my ($self, %options) = @_; - my $components = $options{custom}->get_components(); - - my $results = []; - foreach (@{$components->{components}}) { - push @$results, $_; - } - return $results; + return $options{custom}->get_products(); } sub run { my ($self, %options) = @_; my $results = $self->manage_selection(%options); - foreach (@$results) { + foreach my $id (keys %$results) { $self->{output}->output_add( long_msg => sprintf( '[id: %s][name: %s]', - $_->{id}, - $_->{name} + $id, + $results->{$id} ) ); } $self->{output}->output_add( severity => 'OK', - short_msg => 'List components:' + short_msg => 'List products:' ); $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); @@ -85,10 +79,10 @@ sub disco_show { my ($self, %options) = @_; my $results = $self->manage_selection(%options); - foreach (@$results) { + foreach my $id (keys %$results) { $self->{output}->add_disco_entry( - id => $_->{id}, - name => $_->{name} + id => $id, + name => $results->{$id} ); } } @@ -99,7 +93,7 @@ __END__ =head1 MODE -List components. +List products. =over 8 diff --git a/src/apps/saas/adobestatus/restapi/plugin.pm b/src/apps/saas/adobestatus/restapi/plugin.pm index 567ba762c6..de658cdb47 100644 --- a/src/apps/saas/adobestatus/restapi/plugin.pm +++ b/src/apps/saas/adobestatus/restapi/plugin.pm @@ -35,7 +35,7 @@ sub new { 'list-products' => 'apps::saas::adobestatus::restapi::mode::listproducts' }; - $self->{custom_modes}->{json} = 'apps::atlassian::statuspage::custom::json'; + $self->{custom_modes}->{public} = 'apps::saas::adobestatus::restapi::custom::public'; return $self; } From 9b415e16ef7c8960a9bbd4a8773d18af15455997 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 15 Apr 2026 10:51:59 -0400 Subject: [PATCH 4/4] wip --- .../saas/adobestatus/restapi/custom/public.pm | 22 +-- .../adobestatus/restapi/mode/incidents.pm | 181 +++++++++++++----- 2 files changed, 142 insertions(+), 61 deletions(-) diff --git a/src/apps/saas/adobestatus/restapi/custom/public.pm b/src/apps/saas/adobestatus/restapi/custom/public.pm index d2724b7260..7ceff7adf6 100644 --- a/src/apps/saas/adobestatus/restapi/custom/public.pm +++ b/src/apps/saas/adobestatus/restapi/custom/public.pm @@ -120,20 +120,20 @@ sub get_incidents { my $current_incidents = {}; foreach my $incident (values %{ $response->{incidentEvent}->{incidents}}) { foreach my $productinc (values %{$incident->{products}}) { - next if (!defined($productinc->{endedOn}) || $productinc->{endedOn} == 0); + next if (!defined($productinc->{endedOn}) || $productinc->{endedOn} > 0); $current_incidents->{ $productinc->{id} } = [] if (!defined($current_incidents->{ $productinc->{id} })); - foreach ( sort { $b <=> $a } keys(%{$productinc->{history}}) ) { - push @{$current_incidents->{ $productinc->{id} }}, { - status => $_->{status}, - statusTime => $_->{statusTime}, - severity => $_->{severity}, - customerImpact => $_->{customerImpact}, - messageEn => $response->{incidentEvent}->{messages}->{en}->{ $_->{messageToken} }, - }; - last; - } + my @times = sort { $b <=> $a } keys(%{$productinc->{history}}); + next if ($productinc->{history}->{$times[0]}->{status} =~ /Closed/i); + + push @{$current_incidents->{ $productinc->{id} }}, { + status => $productinc->{history}->{$times[0]}->{status}, + statusTime => $productinc->{history}->{$times[0]}->{statusTime}, + severity => $productinc->{history}->{$times[0]}->{severity}, + customerImpact => $productinc->{history}->{$times[0]}->{customerImpact}, + messageEn => $response->{incidentEvent}->{messages}->{en}->{ $productinc->{history}->{$times[0]}->{messageToken} }->{textMessage} + }; } } diff --git a/src/apps/saas/adobestatus/restapi/mode/incidents.pm b/src/apps/saas/adobestatus/restapi/mode/incidents.pm index 7022510e73..d60281c4b7 100644 --- a/src/apps/saas/adobestatus/restapi/mode/incidents.pm +++ b/src/apps/saas/adobestatus/restapi/mode/incidents.pm @@ -18,50 +18,79 @@ # limitations under the License. # -package apps::atlassian::statuspage::mode::components; +package apps::saas::adobestatus::restapi::mode::incidents; use base qw(centreon::plugins::templates::counter); use strict; use warnings; +use centreon::plugins::misc qw/is_excluded/; use centreon::plugins::constants qw(:counters :values); -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); -sub custom_component_status_output { +sub prefix_global_output { my ($self, %options) = @_; - return sprintf( - 'status: %s', - $self->{result_values}->{status} - ); + return 'Number of products '; } -sub prefix_component_output { +sub prefix_product_output { my ($self, %options) = @_; - return "Component '" . $options{instance_value}->{name} . "' "; + return "Product '" . $options{instance_value}->{productName} . "' number of current incidents "; } sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'components', type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_component_output', message_multiple => 'All components are ok' } + { name => 'global', type => COUNTER_TYPE_GLOBAL, cb_prefix_output => 'prefix_global_output' }, + { name => 'products', type => COUNTER_TYPE_INSTANCE, cb_prefix_output => 'prefix_product_output', message_multiple => 'All products are ok' } ]; - $self->{maps_counters}->{components} = [ - { - label => 'status', - type => COUNTER_KIND_TEXT, - warningd_default => '%{status} =~ /degraded_performance|partial_outage/', - critical_default => '%{status} =~ /major_outage/', + $self->{maps_counters}->{global} = [ + { label => 'products-detected', display_ok => 0, nlabel => 'products.detected.count', + unknown_default => '@0', set => { - key_values => [ - { name => 'status' }, { name => 'name' } - ], - closure_custom_output => $self->can('custom_component_status_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold_ng + key_values => [ { name => 'detected' } ], + output_template => 'detected: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; + + $self->{maps_counters}->{products} = [ + { label => 'product-incidents-major', nlabel => 'product.incidents.major.count', set => { + key_values => [ { name => 'major' }, { name => 'productName' } ], + output_template => 'major: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'productName' } + ] + } + }, + { label => 'product-incidents-minor', nlabel => 'product.incidents.minor.count', set => { + key_values => [ { name => 'minor' }, { name => 'productName' } ], + output_template => 'minor: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'productName' } + ] + } + }, + { label => 'product-incidents-potential', nlabel => 'product.incidents.potential.count', set => { + key_values => [ { name => 'potential' }, { name => 'productName' } ], + output_template => 'potential: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'productName' } + ] + } + }, + { label => 'product-incidents-trivial', nlabel => 'product.incidents.trivial.count', set => { + key_values => [ { name => 'trivial' }, { name => 'productName' } ], + output_template => 'trivial: %s', + perfdatas => [ + { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'productName' } + ] } } ]; @@ -73,8 +102,9 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'filter-component-id:s' => { name => 'filter_component_id' }, - 'filter-component-name:s' => { name => 'filter_component_name' } + 'filter-product-id:s' => { name => 'filter_product_id', default => '' }, + 'filter-product-name:s' => { name => 'filter_product_name', default => '' }, + 'display-incidents' => { name => 'display_incidents' } }); return $self; @@ -83,20 +113,42 @@ sub new { sub manage_selection { my ($self, %options) = @_; - my $results = $options{custom}->get_components(); - - $self->{components} = {}; - foreach (@{$results->{components}}) { - next if (defined($self->{option_results}->{filter_component_id}) && $self->{option_results}->{filter_component_id} ne '' && - $_->{id} !~ /$self->{option_results}->{filter_component_id}/); - next if (defined($self->{option_results}->{filter_component_name}) && $self->{option_results}->{filter_component_name} ne '' && - $_->{name} !~ /$self->{option_results}->{filter_component_name}/); - - $self->{components}->{ $_->{id} } = { - name => $_->{name}, - status => $_->{status} + $self->{global} = { detected => 0 }; + $self->{products} = {}; + my $products = $options{custom}->get_products(); + foreach my $id (keys %$products) { + next if is_excluded($id, $self->{option_results}->{filter_product_id}); + next if is_excluded($products->{$id}, $self->{option_results}->{filter_product_name}); + + $self->{global}->{detected}++; + $self->{products}->{$id} = { + productName => $products->{$id}, + minor => 0, + major => 0, + trivial => 0, + potential => 0 }; } + + my $incidents = $options{custom}->get_incidents(); + foreach my $id (keys %$incidents) { + next if (!defined($self->{products}->{$id})); + + foreach my $incident (@{$incidents->{$id}}) { + $self->{products}->{$id}->{ lc($incident->{severity}) }++; + if (defined($self->{option_results}->{display_incidents})) { + $self->{output}->output_add( + long_msg => sprintf( + "incident '%s' [severity: %s] [customerImpact: %s]: %s", + $self->{products}->{$id}->{productName}, + $incident->{severity}, + $incident->{customerImpact}, + scalar(localtime($incident->{statusTime})) + ) + ); + } + } + } } 1; @@ -105,32 +157,61 @@ __END__ =head1 MODE -Check components. +Check current incidents. =over 8 -=item B<--filter-component-id> +=item B<--filter-product-id> + +Filter products by ID (can be a regexp). + +=item B<--filter-product-name> + +Filter product by name (can be a regexp). + +=item B<--display-incidents> + +Display incidents in verbose output. + +=item B<--warning-products-detected> + +Threshold. + +=item B<--critical-products-detected> + +Threshold. + +=item B<--warning-product-incidents-major> + +Threshold. + +=item B<--critical-product-incidents-major> + +Threshold. + +=item B<--warning-product-incidents-minor> + +Threshold. + +=item B<--critical-product-incidents-minor> -Filter components by ID (can be a regexp). +Threshold. -=item B<--filter-component-name> +=item B<--warning-product-incidents-potential> -Filter components by name (can be a regexp). +Threshold. -=item B<--unknown-status> +=item B<--critical-product-incidents-potential> -Define the conditions to match for the status to be UNKNOWN. -You can use the following variables: %{status}, %{name} +Threshold. -=item B<--warning-status> +=item B<--warning-product-incidents-trivial> -Define the conditions to match for the status to be WARNING (default: '%{status} =~ /degraded_performance|partial_outage/'). -You can use the following variables: %{status}, %{name} +Threshold. -=item B<--critical-status> +=item B<--critical-product-incidents-trivial> -Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /major_outage/'). -You can use the following variables: %{status}, %{name} +Threshold. =back