diff --git a/centreon-plugins/apps/backup/rubrik/restapi/custom/api.pm b/centreon-plugins/apps/backup/rubrik/restapi/custom/api.pm new file mode 100644 index 000000000..9937aecc5 --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/custom/api.pm @@ -0,0 +1,195 @@ +# +# Copyright 2020 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::backup::rubrik::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->{http} = centreon::plugins::http->new(%options); + + 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}->{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->{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->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --hostname option.'); + $self->{output}->option_exit(); + } + if ($self->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --api-username option.'); + $self->{output}->option_exit(); + } + if ($self->{api_password} eq '') { + $self->{output}->add_option_msg(short_msg => 'Need to specify --api-password option.'); + $self->{output}->option_exit(); + } + + return 0; +} + +sub settings { + my ($self, %options) = @_; + + return {} if (defined($self->{settings_done})); + $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; + return { + credentials => 1, + basic => 1, + username => $self->{api_username}, + password => $self->{api_password} + }; +} + +sub get_connection_info { + my ($self, %options) = @_; + + return $self->{option_results}->{hostname} . ":" . $self->{option_results}->{port}; +} + +sub request_api { + my ($self, %options) = @_; + + my $settings = $self->settings(); + my ($content) = $self->{http}->request( + url_path => '/api/internal' . $options{endpoint}, + unknown_status => $self->{unknown_http_status}, + warning_status => $self->{warning_http_status}, + critical_status => $self->{critical_http_status}, + get_param => $options{get_param}, + %$settings + ); + + 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; +} + +1; + +__END__ + +=head1 NAME + +Rubrik Rest API + +=head1 REST API OPTIONS + +Rubrik Rest 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-username> + +API username. + +=item B<--api-password> + +API password. + +=item B<--timeout> + +Set timeout in seconds (Default: 30). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/backup/rubrik/restapi/mode/cluster.pm b/centreon-plugins/apps/backup/rubrik/restapi/mode/cluster.pm new file mode 100644 index 000000000..6d2a429c5 --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/mode/cluster.pm @@ -0,0 +1,198 @@ +# +# Copyright 2020 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::backup::rubrik::restapi::mode::cluster; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); +use POSIX; +use Digest::MD5 qw(md5_hex); + +sub custom_status_output { + my ($self, %options) = @_; + + return 'status: ' . $self->{result_values}->{status}; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "Cluster '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'clusters', type => 1, cb_prefix_output => 'prefix_cluster_output', message_multiple => 'All clusters are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{clusters} = [ + { label => 'status', type => 2, critical_default => '%{status} !~ /ok/i', set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => \&catalog_status_threshold_ng + } + }, + { label => 'read', nlabel => 'cluster.io.read.usage.bytespersecond', display_ok => 0, set => { + key_values => [ { name => 'read' } ], + output_template => 'read: %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { template => '%d', unit => 'B/s', label_extra_instance => 1 } + ] + } + }, + { label => 'write', nlabel => 'cluster.io.write.usage.bytespersecond', display_ok => 0, set => { + key_values => [ { name => 'write' } ], + output_template => 'write: %s %s/s', + output_change_bytes => 1, + perfdatas => [ + { template => '%d', unit => 'B/s', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'read-iops', nlabel => 'cluster.io.read.usage.iops', set => { + key_values => [ { name => 'read_iops' } ], + output_template => 'read iops: %s', + perfdatas => [ + { template => '%s', unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'write-iops', nlabel => 'cluster.io.write.usage.iops', set => { + key_values => [ { name => 'write_iops' } ], + output_template => 'write iops: %s', + perfdatas => [ + { template => '%s', unit => 'iops', min => 0, label_extra_instance => 1 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + 'cluster-id:s' => { name => 'cluster_id', default => 'me' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{option_results}->{cluster_id} = 'me' if ($self->{option_results}->{cluster_id} eq ''); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = 'rubrik_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + md5_hex($self->{option_results}->{cluster_id}); + + my $last_timestamp = $self->read_statefile_key(key => 'last_timestamp'); + $last_timestamp = time() - (5 * 60) if (!defined($last_timestamp)); + my $timespan = POSIX::ceil((time() - $last_timestamp) / 60); + $timespan = 1 if ($timespan <= 0); + + my $name = $options{custom}->request_api(endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/name'); + my $status = $options{custom}->request_api(endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/system_status'); + my $io_stats = $options{custom}->request_api( + endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/io_stats', + get_param => ['range=-' . $timespan . 'min'] + ); + + $self->{clusters} = { + $name => { + name => $name, + status => $status->{status}, + read => 0, + write => 0, + read_iops => 0, + write_iops => 0 + } + }; + + foreach my $entry (( + ['ioThroughput', 'readBytePerSecond', 'read'], ['ioThroughput', 'writeBytePerSecond', 'write'], + ['iops', 'readsPerSecond', 'read_iops'], ['iops', 'writesPerSecond', 'write_iops'] + )) { + my $count = 0; + foreach (@{$io_stats->{ $entry->[0] }->{ $entry->[1] }}) { + $self->{clusters}->{$name}->{ $entry->[2] } += $_->{stat}; + $count++; + } + $self->{clusters}->{$name}->{ $entry->[2] } = int($self->{clusters}->{$name}->{ $entry->[2] } / $count); + } +} + +1; + +__END__ + +=head1 MODE + +Check cluster. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--cluster-id> + +Which cluster to check (Default: 'me'). + +=item B<--unknown-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{name} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /ok/i'). +Can used special variables like: %{status}, %{name} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'read' (B/s), 'write' (B/s), 'read-iops', 'write-iops'. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/rubrik/restapi/mode/disks.pm b/centreon-plugins/apps/backup/rubrik/restapi/mode/disks.pm new file mode 100644 index 000000000..d88f9065c --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/mode/disks.pm @@ -0,0 +1,200 @@ +# +# Copyright 2020 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::backup::rubrik::restapi::mode::disks; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub cluster_long_output { + my ($self, %options) = @_; + + return "checking cluster '" . $options{instance_value}->{name} . "'"; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "cluster '" . $options{instance_value}->{name} . "' "; +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "disk '" . $options{instance_value}->{id} . "' "; +} + +sub prefix_global_cluster_output { + my ($self, %options) = @_; + + return 'disks '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'clusters', type => 3, cb_prefix_output => 'prefix_cluster_output', cb_long_output => 'cluster_long_output', indent_long_output => ' ', message_multiple => 'All clusters are ok', + group => [ + { name => 'cluster', type => 0, cb_prefix_output => 'prefix_global_cluster_output' }, + { name => 'disks', type => 1, display_long => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'disks are ok', skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{cluster} = [ + { label => 'cluster-disks-total', nlabel => 'cluster.disks.total.count', display_ok => 0, set => { + key_values => [ { name => 'disks_total' } ], + output_template => 'total %d', + perfdatas => [ + { template => '%d', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'cluster-disks-active', nlabel => 'cluster.disks.active.count', display_ok => 0, set => { + key_values => [ { name => 'disks_active' }, { name => 'disks_total' } ], + output_template => 'active %d', + perfdatas => [ + { template => '%d', min => 0, max => 'disks_total', label_extra_instance => 1 } + ] + } + } + ]; + + $self->{maps_counters}->{disks} = [ + { label => 'disk-status', type => 2, critical_default => '%{status} !~ /active/i', set => { + key_values => [ { name => 'status' }, { name => 'id' } ], + closure_custom_output => $self->can('custom_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 => { + 'cluster-id:s' => { name => 'cluster_id', default => 'me' }, + 'filter-disk-id:s' => { name => 'filter_disk_id' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{option_results}->{cluster_id} = 'me' if ($self->{option_results}->{cluster_id} eq ''); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $name = $options{custom}->request_api(endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/name'); + my $disks = $options{custom}->request_api(endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/disk'); + + $self->{clusters} = { + $name => { + name => $name, + cluster => { + disks_total => 0, + disks_active => 0 + }, + disks => {} + } + }; + foreach (@{$disks->{data}}) { + my $id = $_->{nodeId} . ':' . $_->{id}; + next if (defined($options{filter_disk_id}) && $options{filter_disk_id} ne '' && + $id !~ /$options{filter_disk_id}/); + + $self->{clusters}->{$name}->{disks}->{$id} = { + id => $id, + status => lc($_->{status}) + }; + $self->{clusters}->{$name}->{cluster}->{ 'disks_' . lc($_->{status}) }++ + if (defined($self->{clusters}->{$name}->{cluster}->{ 'disks_' . lc($_->{status}) })); + $self->{clusters}->{$name}->{cluster}->{disks_total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check cluster disks. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='disk-status' + +=item B<--cluster-id> + +Which cluster to check (Default: 'me'). + +=item B<--filter-disk-id> + +Filter disks by disk id (can be a regexp). + +=item B<--unknown-disks-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{id} + +=item B<--warning-disk-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{id} + +=item B<--critical-disk-status> + +Set critical threshold for status (Default: '%{status} !~ /active/i'). +Can used special variables like: %{status}, %{id} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cluster-disks-total', 'cluster-disks-active'. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/rubrik/restapi/mode/nodes.pm b/centreon-plugins/apps/backup/rubrik/restapi/mode/nodes.pm new file mode 100644 index 000000000..a5a29860a --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/mode/nodes.pm @@ -0,0 +1,200 @@ +# +# Copyright 2020 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::backup::rubrik::restapi::mode::nodes; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); + +sub custom_status_output { + my ($self, %options) = @_; + + return sprintf( + 'status: %s', + $self->{result_values}->{status} + ); +} + +sub cluster_long_output { + my ($self, %options) = @_; + + return "checking cluster '" . $options{instance_value}->{name} . "'"; +} + +sub prefix_cluster_output { + my ($self, %options) = @_; + + return "cluster '" . $options{instance_value}->{name} . "' "; +} + +sub prefix_node_output { + my ($self, %options) = @_; + + return "node '" . $options{instance_value}->{id} . "' [ip address: " . $options{instance_value}->{ip_address} . '] '; +} + +sub prefix_global_cluster_output { + my ($self, %options) = @_; + + return 'nodes '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'clusters', type => 3, cb_prefix_output => 'prefix_cluster_output', cb_long_output => 'cluster_long_output', indent_long_output => ' ', message_multiple => 'All clusters are ok', + group => [ + { name => 'cluster', type => 0, cb_prefix_output => 'prefix_global_cluster_output' }, + { name => 'nodes', type => 1, display_long => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'nodes are ok', skipped_code => { -10 => 1 } } + ] + } + ]; + + $self->{maps_counters}->{cluster} = [ + { label => 'cluster-nodes-total', nlabel => 'cluster.nodes.total.count', display_ok => 0, set => { + key_values => [ { name => 'nodes_total' } ], + output_template => 'total: %d', + perfdatas => [ + { template => '%d', min => 0, label_extra_instance => 1 } + ] + } + }, + { label => 'cluster-nodes-ok', nlabel => 'cluster.nodes.ok.count', display_ok => 0, set => { + key_values => [ { name => 'nodes_ok' }, { name => 'nodes_total' } ], + output_template => 'ok: %d', + perfdatas => [ + { template => '%d', min => 0, max => 'nodes_total', label_extra_instance => 1 } + ] + } + } + ]; + + $self->{maps_counters}->{nodes} = [ + { label => 'node-status', type => 2, critical_default => '%{status} !~ /ok/i', set => { + key_values => [ { name => 'status' }, { name => 'id' }, { name => 'ip_address' } ], + closure_custom_output => $self->can('custom_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 => { + 'cluster-id:s' => { name => 'cluster_id', default => 'me' }, + 'filter-node-id:s' => { name => 'filter_node_id' } + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{option_results}->{cluster_id} = 'me' if ($self->{option_results}->{cluster_id} eq ''); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $name = $options{custom}->request_api(endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/name'); + my $nodes = $options{custom}->request_api(endpoint => '/cluster/' . $self->{option_results}->{cluster_id} . '/node'); + + $self->{clusters} = { + $name => { + name => $name, + cluster => { + nodes_total => 0, + nodes_ok => 0 + }, + nodes => {} + } + }; + foreach (@{$nodes->{data}}) { + next if (defined($options{filter_node_id}) && $options{filter_node_id} ne '' && + $_->{id} !~ /$options{filter_node_id}/); + + $self->{clusters}->{$name}->{nodes}->{ $_->{id} } = { + id => $_->{id}, + ip_address => $_->{ipAddress}, + status => lc($_->{status}) + }; + $self->{clusters}->{$name}->{cluster}->{ 'nodes_' . lc($_->{status}) }++ + if (defined($self->{clusters}->{$name}->{cluster}->{ 'nodes_' . lc($_->{status}) })); + $self->{clusters}->{$name}->{cluster}->{nodes_total}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check cluster nodes. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='node-status' + +=item B<--cluster-id> + +Which cluster to check (Default: 'me'). + +=item B<--filter-node-id> + +Filter nodes by node id (can be a regexp). + +=item B<--unknown-node-status> + +Set unknown threshold for status. +Can used special variables like: %{status}, %{ip_address}, %{id} + +=item B<--warning-node-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{ip_address}, %{id} + +=item B<--critical-node-status> + +Set critical threshold for status (Default: '%{status} !~ /ok/i'). +Can used special variables like: %{status}, %{ip_address}, %{id} + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'cluster-nodes-total', 'cluster-nodes-ok'. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/rubrik/restapi/mode/storage.pm b/centreon-plugins/apps/backup/rubrik/restapi/mode/storage.pm new file mode 100644 index 000000000..38b37a0db --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/mode/storage.pm @@ -0,0 +1,144 @@ +# +# Copyright 2020 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::backup::rubrik::restapi::mode::storage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_space}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_space}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_space}); + 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}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_space} + ); + return $msg; +} + +sub prefix_ss_output { + my ($self, %options) = @_; + + return 'Storage system '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ss', type => 0, cb_prefix_output => 'prefix_ss_output' } + ]; + + $self->{maps_counters}->{ss} = [ + { label => 'usage', nlabel => 'storage.space.usage.bytes', set => { + key_values => [ { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_used_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'used_space', template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-free', nlabel => 'storage.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' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { value => 'free_space', template => '%d', min => 0, max => 'total_space', unit => 'B', cast_int => 1 } + ] + } + }, + { label => 'usage-prct', nlabel => 'storage.space.usage.percentage', display_ok => 0, set => { + key_values => [ { name => 'prct_used_space' }, { name => 'used_space' }, { name => 'free_space' }, { name => 'prct_free_space' }, { name => 'total_space' } ], + closure_custom_output => $self->can('custom_usage_output'), + perfdatas => [ + { template => '%.2f', min => 0, max => 100, unit => '%' } + ] + } + }, + { label => 'full-remaining-days', nlabel => 'storage.full.remaining.days.count', set => { + key_values => [ { name => 'full_remaining_days' } ], + output_template => 'remaining days before filled: %s', + perfdatas => [ + { template => '%s', unit => 'd', min => 0 } + ] + } + } + ]; +} + +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 => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $storage = $options{custom}->request_api(endpoint => '/stats/system_storage'); + my $runway = $options{custom}->request_api(endpoint => '/stats/runway_remaining'); + + $self->{ss} = { + total_space => $storage->{total}, + used_space => $storage->{total} - $storage->{available}, + free_space => $storage->{available}, + prct_used_space => + (($storage->{total} - $storage->{available}) * 100 / $storage->{total}), + prct_free_space => + ($storage->{available} * 100 / $storage->{total}), + full_remaining_days => $runway->{days} + }; +} + +1; + +__END__ + +=head1 MODE + +Check storage system. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='remaining' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'usage' (B), 'usage-free' (B), 'usage-prct' (%), +'full-remaining-days'. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/rubrik/restapi/mode/tasks.pm b/centreon-plugins/apps/backup/rubrik/restapi/mode/tasks.pm new file mode 100644 index 000000000..671824ad9 --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/mode/tasks.pm @@ -0,0 +1,134 @@ +# +# Copyright 2020 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::backup::rubrik::restapi::mode::tasks; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub prefix_global_output { + my ($self, %options) = @_; + + return 'Tasks '; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'succeeded', nlabel => 'tasks.succeeded.count', set => { + key_values => [ { name => 'succeeded', diff => 1 } ], + output_template => 'succeeded: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'failed', nlabel => 'tasks.failed.count', set => { + key_values => [ { name => 'failed', diff => 1 } ], + output_template => 'failed: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + }, + { label => 'canceled', nlabel => 'tasks.canceled.count', set => { + key_values => [ { name => 'canceled', diff => 1 } ], + output_template => 'canceled: %s', + perfdatas => [ + { template => '%s', min => 0 } + ] + } + } + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); + bless $self, $class; + + $options{options}->add_options(arguments => { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = 'rubrik_' . $self->{mode} . '_' . md5_hex($options{custom}->get_connection_info()) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + my $reports = $options{custom}->request_api(endpoint => '/report'); + my $report_id; + foreach (@{$reports->{data}}) { + if ($_->{name} eq 'Protection Tasks Details') { + $report_id = $_->{id}; + last; + } + } + if (!defined($report_id)) { + $self->{output}->add_option_msg(short_msg => "Cannot find report name 'Protection Tasks Details'"); + $self->{output}->option_exit(); + } + + my $tasks = $options{custom}->request_api( + endpoint => '/report/' . $report_id . '/chart', + get_param => ['timezone_offset=0', 'chart_id=chart0'] + ); + + $self->{global} = {}; + foreach (@{$tasks->[0]->{dataColumns}}) { + $self->{global}->{ lc($_->{label}) } = $_->{dataPoints}->[0]->{value}; + } + +} + +1; + +__END__ + +=head1 MODE + +Check tasks. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='failed' + +=item B<--warning-*> B<--critical-*> + +Thresholds. +Can be: 'succeeded', 'failed', 'canceled'. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/rubrik/restapi/plugin.pm b/centreon-plugins/apps/backup/rubrik/restapi/plugin.pm new file mode 100644 index 000000000..3ac92e8f8 --- /dev/null +++ b/centreon-plugins/apps/backup/rubrik/restapi/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2020 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::backup::rubrik::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} = { + 'cluster' => 'apps::backup::rubrik::restapi::mode::cluster', + 'disks' => 'apps::backup::rubrik::restapi::mode::disks', + 'nodes' => 'apps::backup::rubrik::restapi::mode::nodes', + 'storage' => 'apps::backup::rubrik::restapi::mode::storage', + 'tasks' => 'apps::backup::rubrik::restapi::mode::tasks' + }; + + $self->{custom_modes}->{api} = 'apps::backup::rubrik::restapi::custom::api'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Rubrik using Rest API. + +=cut