diff --git a/storage/oracle/zs/restapi/custom/api.pm b/storage/oracle/zs/restapi/custom/api.pm new file mode 100644 index 000000000..fcc90135e --- /dev/null +++ b/storage/oracle/zs/restapi/custom/api.pm @@ -0,0 +1,220 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::custom::api; + +use strict; +use warnings; +use centreon::plugins::http; +use JSON::XS; + +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 => { + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'timeout:s' => { name => 'timeout' }, + '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 => 'REST API OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : ''; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 25; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : ''; + $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : ''; + $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 (!defined($self->{hostname}) || $self->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_username}) || $self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{api_password}) || $self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{credentials} = 1; + $self->{option_results}->{basic} = 1; + $self->{option_results}->{username} = $self->{api_username}; + $self->{option_results}->{password} = $self->{api_password}; +} + +sub settings { + my ($self, %options) = @_; + + return if (defined($self->{settings_done})); + $self->build_options_for_httplib(); + $self->{http}->add_header(key => 'Accept', value => 'application/json'); + $self->{http}->add_header(key => 'Content-Type', value => 'application/json'); + $self->{http}->set_options(%{$self->{option_results}}); + $self->{settings_done} = 1; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub request_api { + my ($self, %options) = @_; + + $self->settings(); + my $content = $self->{http}->request( + method => defined($options{method}) ? $options{method} : 'GET', + url_path => $options{url_path}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + cookies_file => '', # in memory + ); + + 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->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; +} + +1; + +__END__ + +=head1 NAME + +Oracle ZFS Rest API + +=head1 REST API OPTIONS + +Oracle ZFS Rest API + +=over 8 + +=item B<--hostname> + +Oracle ZFS hostname. + +=item B<--port> + +Port used (Default: 25) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-username> + +Oracle ZFS API username. + +=item B<--api-password> + +Oracle ZFS API password. + +=item B<--timeout> + +Set timeout in seconds (Default: 10). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/storage/oracle/zs/restapi/mode/components/chassis.pm b/storage/oracle/zs/restapi/mode/components/chassis.pm new file mode 100644 index 000000000..2f976135a --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/chassis.pm @@ -0,0 +1,57 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::chassis; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking chassis'); + $self->{components}->{chassis} = { name => 'chassis', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'chassis')); + + foreach my $chassis (values %{$self->{results}}) { + my $instance = $chassis->{name}; + + next if ($self->check_filter(section => 'chassis', instance => $instance)); + $self->{components}->{chassis}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "chassis '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'chassis', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Chassis '%s' status is '%s'", $instance, $status) + ); + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/components/cpu.pm b/storage/oracle/zs/restapi/mode/components/cpu.pm new file mode 100644 index 000000000..58e85bd6a --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/cpu.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::cpu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking cpu'); + $self->{components}->{cpu} = { name => 'cpu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'cpu')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{cpu}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'cpu', instance => $instance)); + $self->{components}->{cpu}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "cpu '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'cpu', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Cpu '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/components/disk.pm b/storage/oracle/zs/restapi/mode/components/disk.pm new file mode 100644 index 000000000..40bd7fea4 --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/disk.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::disk; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking disks'); + $self->{components}->{disk} = { name => 'disks', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'disk')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{disk}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'disk', instance => $instance)); + $self->{components}->{disk}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "disk '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'disk', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Disk '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/components/fan.pm b/storage/oracle/zs/restapi/mode/components/fan.pm new file mode 100644 index 000000000..2f53d4747 --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/fan.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::fan; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking fans'); + $self->{components}->{fan} = { name => 'fan', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'fan')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{fan}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'fan', instance => $instance)); + $self->{components}->{fan}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'fan', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Fan '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/components/memory.pm b/storage/oracle/zs/restapi/mode/components/memory.pm new file mode 100644 index 000000000..d59893988 --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/memory.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::memory; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking memories'); + $self->{components}->{memory} = { name => 'memory', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'memory')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{memory}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'memory', instance => $instance)); + $self->{components}->{memory}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "memory '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'memory', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Memory '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/components/psu.pm b/storage/oracle/zs/restapi/mode/components/psu.pm new file mode 100644 index 000000000..a6408ca91 --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/psu.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::psu; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking power supplies'); + $self->{components}->{psu} = { name => 'psu', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'psu')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{psu}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'psu', instance => $instance)); + $self->{components}->{psu}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "power supply '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Power supply '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/components/slot.pm b/storage/oracle/zs/restapi/mode/components/slot.pm new file mode 100644 index 000000000..a8c807ef1 --- /dev/null +++ b/storage/oracle/zs/restapi/mode/components/slot.pm @@ -0,0 +1,59 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::components::slot; + +use strict; +use warnings; + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => 'checking slots'); + $self->{components}->{slot} = { name => 'slot', total => 0, skip => 0 }; + return if ($self->check_filter(section => 'slot')); + + foreach my $chassis (values %{$self->{results}}) { + foreach (@{$chassis->{slot}}) { + my $instance = $chassis->{name} . ':' . $_->{label}; + + next if ($self->check_filter(section => 'slot', instance => $instance)); + $self->{components}->{slot}->{total}++; + + my $status = $_->{faulted} ? 'faulted' : 'ok'; + $self->{output}->output_add( + long_msg => sprintf( + "slot '%s' status is '%s' [instance = %s]", + $instance, $status, $instance, + ) + ); + + my $exit = $self->get_severity(label => 'default', section => 'slot', value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("Slot '%s' status is '%s'", $instance, $status) + ); + } + } + } +} + +1; diff --git a/storage/oracle/zs/restapi/mode/hardware.pm b/storage/oracle/zs/restapi/mode/hardware.pm new file mode 100644 index 000000000..d02d7a812 --- /dev/null +++ b/storage/oracle/zs/restapi/mode/hardware.pm @@ -0,0 +1,100 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(chassis|cpu|disk|fan|memory|psu|slot)$'; + + $self->{cb_hook2} = 'execute_custom'; + + $self->{thresholds} = { + default => [ + ['faulted', 'CRITICAL'], + ['ok', 'OK'], + ], + }; + + $self->{components_exec_load} = 0; + + $self->{components_path} = 'storage::oracle::zs::restapi::mode::components'; + $self->{components_module} = ['chassis', 'cpu', 'disk', 'fan', 'memory', 'psu', 'slot']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, force_new_perfdata => 1); + bless $self, $class; + + $options{options}->add_options(arguments => {}); + + return $self; +} + +sub execute_custom { + my ($self, %options) = @_; + + $self->{results} = {}; + my $result = $options{custom}->request_api(url_path => '/api/hardware/v1/chassis'); + foreach (@{$result->{chassis}}) { + my $chassis = $options{custom}->request_api(url_path => $_->{href}); + $self->{results}->{$_->{name}} = $chassis->{chassis}; + } +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'chassis', 'cpu', 'disk', 'fan', 'memory', 'psu', 'slot'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter='disk,hdd 0' + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='disk,WARNING,faulted' + +=back + +=cut diff --git a/storage/oracle/zs/restapi/mode/pools.pm b/storage/oracle/zs/restapi/mode/pools.pm new file mode 100644 index 000000000..fb6d9d52b --- /dev/null +++ b/storage/oracle/zs/restapi/mode/pools.pm @@ -0,0 +1,197 @@ +# +# Copyright 2019 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 storage::oracle::zs::restapi::mode::pools; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space_absolute}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space_absolute}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space_absolute}); + my $msg = sprintf('space usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_space_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space_absolute} + ); + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{pool} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => \&catalog_status_calc, + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold, + } + }, + { label => 'usage', nlabel => 'pool.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-free', nlabel => 'pool.space.free.bytes', display_ok => 0, set => { + key_values => [ { name => 'free_space' }, { name => 'used_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' }, { name => 'display' }, ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space_absolute', template => '%d', min => 0, max => 'total_space_absolute', + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'usage-prct', nlabel => 'pool.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'display' } ], + output_template => 'used : %.2f %%', + perfdatas => [ + { value => 'prct_used_space_absolute', template => '%.2f', min => 0, max => 100, + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +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-name:s' => { name => 'filter_name' }, + 'unknown-status:s' => { name => 'unknown_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /online|exported/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->change_macros(macros => ['warning_status', 'critical_status', 'unknown_status']); +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Pool '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{custom}->request_api(url_path => '/api/storage/v1/pools'); + + $self->{pool} = {}; + foreach (@{$results->{pools}}) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping pool '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{pool}->{$_->{name}} = { + display => $_->{name}, + status => $_->{status}, + total_space => $_->{usage}->{total}, + used_space => $_->{usage}->{used}, + free_space => $_->{usage}->{free}, + prct_used_space => + defined($_->{usage}->{total}) ? ($_->{usage}->{used} * 100 / $_->{usage}->{total}) : undef, + prct_free_space => + defined($_->{usage}->{total}) ? ($_->{usage}->{free} * 100 / $_->{usage}->{total}) : undef, + }; + } + + if (scalar(keys %{$self->{pool}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No pool found"); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check pool usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^usage$' + +=item B<--filter-name> + +Filter pool name (can be a regexp). + +=item B<--unknown-status> + +Set unknon threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /online|exported/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%). + +=back + +=cut diff --git a/storage/oracle/zs/restapi/plugin.pm b/storage/oracle/zs/restapi/plugin.pm new file mode 100644 index 000000000..0f8e09ef3 --- /dev/null +++ b/storage/oracle/zs/restapi/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2019 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 storage::oracle::zs::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->{version} = '0.1'; + %{ $self->{modes} } = ( + 'hardware' => 'storage::oracle::zs::restapi::mode::hardware', + 'pools' => 'storage::oracle::zs::restapi::mode::pools', + ); + + $self->{custom_modes}{api} = 'storage::oracle::zs::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Oracle ZFS Storage ZS in Rest API. + +=cut diff --git a/storage/oracle/zs/snmp/plugin.pm b/storage/oracle/zs/snmp/plugin.pm index 95d6f56e4..b5a148284 100644 --- a/storage/oracle/zs/snmp/plugin.pm +++ b/storage/oracle/zs/snmp/plugin.pm @@ -31,12 +31,12 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'hardware' => 'storage::oracle::zs::snmp::mode::hardware', - 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-shares' => 'storage::oracle::zs::snmp::mode::listshares', - 'interfaces' => 'snmp_standard::mode::interfaces', - 'share-usage' => 'storage::oracle::zs::snmp::mode::shareusage', - ); + 'hardware' => 'storage::oracle::zs::snmp::mode::hardware', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-shares' => 'storage::oracle::zs::snmp::mode::listshares', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'share-usage' => 'storage::oracle::zs::snmp::mode::shareusage', + ); return $self; }