diff --git a/packaging/centreon-plugin-Applications-Atlassian-Statuspage/deb.json b/packaging/centreon-plugin-Applications-Atlassian-Statuspage/deb.json new file mode 100644 index 0000000000..9757fe1126 --- /dev/null +++ b/packaging/centreon-plugin-Applications-Atlassian-Statuspage/deb.json @@ -0,0 +1,4 @@ +{ + "dependencies": [ + ] +} diff --git a/packaging/centreon-plugin-Applications-Atlassian-Statuspage/pkg.json b/packaging/centreon-plugin-Applications-Atlassian-Statuspage/pkg.json new file mode 100644 index 0000000000..c8fe6feecc --- /dev/null +++ b/packaging/centreon-plugin-Applications-Atlassian-Statuspage/pkg.json @@ -0,0 +1,9 @@ +{ + "pkg_name": "centreon-plugin-Applications-Atlassian-Statuspage", + "pkg_summary": "Centreon Plugin", + "plugin_name": "centreon_atlassian_statuspage.pl", + "files": [ + "centreon/plugins/script_custom.pm", + "apps/atlassian/statuspage/" + ] +} diff --git a/packaging/centreon-plugin-Applications-Atlassian-Statuspage/rpm.json b/packaging/centreon-plugin-Applications-Atlassian-Statuspage/rpm.json new file mode 100644 index 0000000000..9757fe1126 --- /dev/null +++ b/packaging/centreon-plugin-Applications-Atlassian-Statuspage/rpm.json @@ -0,0 +1,4 @@ +{ + "dependencies": [ + ] +} diff --git a/src/apps/atlassian/statuspage/custom/json.pm b/src/apps/atlassian/statuspage/custom/json.pm new file mode 100644 index 0000000000..a6ef915c54 --- /dev/null +++ b/src/apps/atlassian/statuspage/custom/json.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::json; + +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/atlassian/statuspage/mode/components.pm b/src/apps/atlassian/statuspage/mode/components.pm new file mode 100644 index 0000000000..7022510e73 --- /dev/null +++ b/src/apps/atlassian/statuspage/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/atlassian/statuspage/mode/listcomponents.pm b/src/apps/atlassian/statuspage/mode/listcomponents.pm new file mode 100644 index 0000000000..fc95c3a8f0 --- /dev/null +++ b/src/apps/atlassian/statuspage/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/atlassian/statuspage/plugin.pm b/src/apps/atlassian/statuspage/plugin.pm new file mode 100644 index 0000000000..85042bbf9b --- /dev/null +++ b/src/apps/atlassian/statuspage/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::atlassian::statuspage::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} = { + 'components' => 'apps::atlassian::statuspage::mode::components', + 'list-components' => 'apps::atlassian::statuspage::mode::listcomponents' + }; + + $self->{custom_modes}->{json} = 'apps::atlassian::statuspage::custom::json'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Atlassian statuspage using API or JSON public files. + +=over 8 + +=back + +=cut