diff --git a/packaging/centreon-plugin-Applications-Adobestatus-Restapi/deb.json b/packaging/centreon-plugin-Applications-Adobestatus-Restapi/deb.json new file mode 100644 index 0000000000..9757fe1126 --- /dev/null +++ b/packaging/centreon-plugin-Applications-Adobestatus-Restapi/deb.json @@ -0,0 +1,4 @@ +{ + "dependencies": [ + ] +} diff --git a/packaging/centreon-plugin-Applications-Adobestatus-Restapi/pkg.json b/packaging/centreon-plugin-Applications-Adobestatus-Restapi/pkg.json new file mode 100644 index 0000000000..393b2bfb65 --- /dev/null +++ b/packaging/centreon-plugin-Applications-Adobestatus-Restapi/pkg.json @@ -0,0 +1,9 @@ +{ + "pkg_name": "centreon-plugin-Applications-Adobestatus-Restapi", + "pkg_summary": "Centreon Plugin", + "plugin_name": "centreon_adobestatus_restapi.pl", + "files": [ + "centreon/plugins/script_custom.pm", + "apps/saas/adobestatus/restapi/" + ] +} diff --git a/packaging/centreon-plugin-Applications-Adobestatus-Restapi/rpm.json b/packaging/centreon-plugin-Applications-Adobestatus-Restapi/rpm.json new file mode 100644 index 0000000000..9757fe1126 --- /dev/null +++ b/packaging/centreon-plugin-Applications-Adobestatus-Restapi/rpm.json @@ -0,0 +1,4 @@ +{ + "dependencies": [ + ] +} diff --git a/src/apps/saas/adobestatus/restapi/custom/public.pm b/src/apps/saas/adobestatus/restapi/custom/public.pm new file mode 100644 index 0000000000..7ceff7adf6 --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/custom/public.pm @@ -0,0 +1,192 @@ +# +# 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::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) = @_; + 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', 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 => 'PUBLIC 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) = @_; + + if (is_empty($self->{option_results}->{hostname})) { + $self->{output}->option_exit(short_msg => "Need to specify hostname option."); + } + + 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 request_api { + my ($self, %options) = @_; + + $self->settings(); + my ($content) = $self->{http}->request( + url_path => $options{endpoint}, + 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 = json_decode( + $content, + errstr => MSG_JSON_DECODE_ERROR, + output => $self->{output} + ); + + return $decoded; +} + +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} })); + + 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} + }; + } + } + + return $current_incidents; +} + +sub get_products { + my ($self, %options) = @_; + + my $response = $self->request_api(endpoint => '/adobestatus/SnowServiceRegistry'); + + my $products = {}; + foreach (values %{$response->{products}}) { + $products->{ $_->{id} } = $_->{name}; + } + + return $products; +} + +1; + +__END__ + +=head1 NAME + +Public JSON API + +=head1 PUBLIC API OPTIONS + +Public JSON API + +=over 8 + +=item B<--hostname> + +Define hostname (default: C<'data.status.adobe.com'>). + +=item B<--port> + +Port used (default: 443) + +=item B<--proto> + +Specify https if needed (default: 'https') + +=item B<--timeout> + +Set timeout in seconds (default: 30). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/src/apps/saas/adobestatus/restapi/mode/incidents.pm b/src/apps/saas/adobestatus/restapi/mode/incidents.pm new file mode 100644 index 0000000000..d60281c4b7 --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/mode/incidents.pm @@ -0,0 +1,218 @@ +# +# 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::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); + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Number of products '; +} + +sub prefix_product_output { + my ($self, %options) = @_; + + return "Product '" . $options{instance_value}->{productName} . "' number of current incidents "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { 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}->{global} = [ + { label => 'products-detected', display_ok => 0, nlabel => 'products.detected.count', + unknown_default => '@0', + set => { + 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' } + ] + } + } + ]; +} + +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-product-id:s' => { name => 'filter_product_id', default => '' }, + 'filter-product-name:s' => { name => 'filter_product_name', default => '' }, + 'display-incidents' => { name => 'display_incidents' } + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $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; + +__END__ + +=head1 MODE + +Check current incidents. + +=over 8 + +=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> + +Threshold. + +=item B<--warning-product-incidents-potential> + +Threshold. + +=item B<--critical-product-incidents-potential> + +Threshold. + +=item B<--warning-product-incidents-trivial> + +Threshold. + +=item B<--critical-product-incidents-trivial> + +Threshold. + +=back + +=cut diff --git a/src/apps/saas/adobestatus/restapi/mode/listproducts.pm b/src/apps/saas/adobestatus/restapi/mode/listproducts.pm new file mode 100644 index 0000000000..a9ee1767df --- /dev/null +++ b/src/apps/saas/adobestatus/restapi/mode/listproducts.pm @@ -0,0 +1,102 @@ +# +# 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::mode::listproducts; + +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) = @_; + + return $options{custom}->get_products(); +} + +sub run { + my ($self, %options) = @_; + + my $results = $self->manage_selection(%options); + foreach my $id (keys %$results) { + $self->{output}->output_add( + long_msg => sprintf( + '[id: %s][name: %s]', + $id, + $results->{$id} + ) + ); + } + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'List products:' + ); + $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 my $id (keys %$results) { + $self->{output}->add_disco_entry( + id => $id, + name => $results->{$id} + ); + } +} + +1; + +__END__ + +=head1 MODE + +List products. + +=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..de658cdb47 --- /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}->{public} = 'apps::saas::adobestatus::restapi::custom::public'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Adobe Status using API or public JSON. + +=over 8 + +=back + +=cut