From 51c16b4419d640709d3352a260e4cd63cd96db14 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Wed, 19 Dec 2018 17:43:29 +0100 Subject: [PATCH] enh quantum dxi plugin --- storage/quantum/dxi/ssh/mode/compaction.pm | 2 - storage/quantum/dxi/ssh/mode/diskusage.pm | 2 - storage/quantum/dxi/ssh/mode/health.pm | 232 +++++++++++++ .../dxi/ssh/mode/hostbusadapterstatus.pm | 230 ++++++++++++ storage/quantum/dxi/ssh/mode/memory.pm | 239 +++++++++++++ storage/quantum/dxi/ssh/mode/network.pm | 232 +++++++++++++ storage/quantum/dxi/ssh/mode/reclamation.pm | 326 ++++++++++++++++++ storage/quantum/dxi/ssh/mode/reduction.pm | 2 - .../dxi/ssh/mode/storagearraystatus.pm | 224 ++++++++++++ storage/quantum/dxi/ssh/mode/systemstatus.pm | 237 +++++++++++++ storage/quantum/dxi/ssh/mode/throughput.pm | 225 ++++++++++++ storage/quantum/dxi/ssh/plugin.pm | 14 +- 12 files changed, 1956 insertions(+), 9 deletions(-) create mode 100644 storage/quantum/dxi/ssh/mode/health.pm create mode 100644 storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm create mode 100644 storage/quantum/dxi/ssh/mode/memory.pm create mode 100644 storage/quantum/dxi/ssh/mode/network.pm create mode 100644 storage/quantum/dxi/ssh/mode/reclamation.pm create mode 100644 storage/quantum/dxi/ssh/mode/storagearraystatus.pm create mode 100644 storage/quantum/dxi/ssh/mode/systemstatus.pm create mode 100644 storage/quantum/dxi/ssh/mode/throughput.pm diff --git a/storage/quantum/dxi/ssh/mode/compaction.pm b/storage/quantum/dxi/ssh/mode/compaction.pm index 961bbf574..647f36a2a 100644 --- a/storage/quantum/dxi/ssh/mode/compaction.pm +++ b/storage/quantum/dxi/ssh/mode/compaction.pm @@ -229,8 +229,6 @@ sub manage_selection { # End Time = # Compacted = 12.00 MB # Still to compact = 123.00 MB - # - # Command completed successfully. foreach (split(/\n/, $stdout)) { $self->{global}->{compaction_status} = $1 if ($_ =~ /.*Compaction\sStatus\s=\s(.*)$/i); diff --git a/storage/quantum/dxi/ssh/mode/diskusage.pm b/storage/quantum/dxi/ssh/mode/diskusage.pm index 309c20e16..95becbad1 100644 --- a/storage/quantum/dxi/ssh/mode/diskusage.pm +++ b/storage/quantum/dxi/ssh/mode/diskusage.pm @@ -276,8 +276,6 @@ sub manage_selection { # Deduplicated Data = 501.95 GB 5.02% # System Metadata = 147.83 GB 1.48% # Data Not Intended for Deduplication = 0.00 MB 0.00% - # - # Command completed successfully. foreach (split(/\n/, $stdout)) { $self->{global}->{disk_capacity} = $1 if ($_ =~ /.*Disk\sCapacity\s=\s(.*)$/i); diff --git a/storage/quantum/dxi/ssh/mode/health.pm b/storage/quantum/dxi/ssh/mode/health.pm new file mode 100644 index 000000000..4d22c8d09 --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/health.pm @@ -0,0 +1,232 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::health; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status is '" . $self->{result_values}->{status} . "' [state = " . $self->{result_values}->{state} . "]"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + return 0; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Health check '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All health check status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'status' }, { name => 'state' }, { name => 'name' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--list healthcheckstatus' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Ready|Success/i' }, + }); + + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach ('warning_status', 'critical_status') { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # Healthcheck Status + # Total count = 2 + # [HealthCheck = 1] + # Healthcheck Name = De-Duplication + # State = enabled + # Started = Mon Dec 17 05:00:01 2018 + # Finished = Mon Dec 17 05:02:01 2018 + # Status = Success + # [HealthCheck = 2] + # Healthcheck Name = Integrity + # State = disabled + # Started = + # Finished = + # Status = Ready + + my $id; + foreach (split(/\n/, $stdout)) { + $id = $1 if ($_ =~ /.*\[HealthCheck\s=\s(.*)\]$/i); + $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Status\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{state} = $1 if ($_ =~ /.*State\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*Healthcheck\sName\s=\s(.*)$/i && defined($id) && $id ne ''); + } +} + +1; + +__END__ + +=head1 MODE + +Check health status. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status}, %{state} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Ready|Success/i'). +Can used special variables like: %{name}, %{status}, %{state} + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--list healthcheckstatus'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm b/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm new file mode 100644 index 000000000..50227c723 --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm @@ -0,0 +1,230 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::hostbusadapterstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + return 0; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Hostbus Adapter '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All hostbus adapter status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--getstatus hostbusadapter' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Normal/i' }, + }); + + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach ('warning_status', 'critical_status') { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # List of Hostbus Adapters + # Total count = 4 + # [Hostbus Adapter = 1] + # Name = Fibre Channel Controller 1 + # Status = Normal + # [Hostbus Adapter = 2] + # Name = Fibre Channel Controller 2 + # Status = Normal + # [Hostbus Adapter = 3] + # Name = SAS HBA 1 + # Status = Normal + # [Hostbus Adapter = 4] + # Name = SAS HBA 2 + # Status = Normal + + my $id; + foreach (split(/\n/, $stdout)) { + $id = $1 if ($_ =~ /.*\[Hostbus\sAdapter\s=\s(.*)\]$/i); + $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Status\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*Name\s=\s(.*)$/i && defined($id) && $id ne ''); + } +} + +1; + +__END__ + +=head1 MODE + +Check hostbus adapters status. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Normal/i'). +Can used special variables like: %{name}, %{status} + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--getstatus hostbusadapter'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/memory.pm b/storage/quantum/dxi/ssh/mode/memory.pm new file mode 100644 index 000000000..a407f51c4 --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/memory.pm @@ -0,0 +1,239 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'used', + unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + + my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $self->{result_values}->{prct_used}, + $free_value . " " . $free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_total'}); + $self->{result_values}->{free} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_free'}); + + if ($self->{result_values}->{total} != 0) { + $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + } else { + $self->{result_values}->{free} = '0'; + $self->{result_values}->{prct_used} = '0'; + $self->{result_values}->{prct_free} = '0'; + } + + return 0; +} + +sub convert_to_bytes { + my ($class, %options) = @_; + + my ($value, $unit) = split(/\s+/, $options{raw_value}); + if ($unit =~ /kb*/i) { + $value = $value * 1024; + } elsif ($unit =~ /mb*/i) { + $value = $value * 1024 * 1024; + } elsif ($unit =~ /gb*/i) { + $value = $value * 1024 * 1024 * 1024; + } elsif ($unit =~ /tb*/i) { + $value = $value * 1024 * 1024 * 1024 * 1024; + } + + return $value; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', set => { + key_values => [ { name => 'total' }, { name => 'free' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--getstatus systemmemory' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } + + $instance_mode = $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # Total Memory = 270.76 GB + # Free Memory = 91.19 GB + + foreach (split(/\n/, $stdout)) { + $self->{global}->{total} = $1 if ($_ =~ /.*Total\sMemory\s=\s(.*)$/i); + $self->{global}->{free} = $1 if ($_ =~ /.*Free\sMemory\s=\s(.*)$/i); + } +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--getstatus systemmemory'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/network.pm b/storage/quantum/dxi/ssh/mode/network.pm new file mode 100644 index 000000000..fc8f5dc05 --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/network.pm @@ -0,0 +1,232 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::network; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status is '" . $self->{result_values}->{status} . "' [value = " . $self->{result_values}->{value} . "]"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'}; + return 0; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Port '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All component status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'status' }, { name => 'name' }, { name => 'value' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--getstatus networkport' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Up/i' }, + }); + + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach ('warning_status', 'critical_status') { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # Network Ports + # Total count = 5 + # [Port = 1] + # Name = eth1 + # Value = NA + # Status = Down + # [Port = 2] + # Name = eth2 + # Value = NA + # Status = Down + # [Port = 3] + # Name = eth3 + # Value = NA + # Status = Down + + my $id; + foreach (split(/\n/, $stdout)) { + $id = $1 if ($_ =~ /.*\[Port\s=\s(.*)\]$/i); + $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Status\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*Name\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{value} = $1 if ($_ =~ /.*Value\s=\s(.*)$/i && defined($id) && $id ne ''); + } +} + +1; + +__END__ + +=head1 MODE + +Check network ports status. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Up/i'). +Can used special variables like: %{name}, %{status} + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--getstatus networkport'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/reclamation.pm b/storage/quantum/dxi/ssh/mode/reclamation.pm new file mode 100644 index 000000000..e74d3837b --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/reclamation.pm @@ -0,0 +1,326 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::reclamation; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'Reclamation status: ' . $self->{result_values}->{reclamation_status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{reclamation_status} = $options{new_datas}->{$self->{instance} . '_reclamation_status'}; + return 0; +} + +sub custom_volume_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B', + value => $self->{result_values}->{volume}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}) + ); +} + +sub custom_volume_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{volume}, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_volume_output { + my ($self, %options) = @_; + + my ($volume_value, $volume_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{volume}); + my $msg = sprintf("%s: %s %s", $self->{result_values}->{display}, $volume_value, $volume_unit); + return $msg; +} + +sub custom_volume_calc { + my ($self, %options) = @_; + + $self->{result_values}->{volume} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + $self->{result_values}->{display} = $options{extra_options}->{display_ref}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + + return 0; +} + +sub convert_to_bytes { + my ($class, %options) = @_; + + my ($value, $unit) = split(/\s+/, $options{raw_value}); + if ($unit =~ /kb*/i) { + $value = $value * 1024; + } elsif ($unit =~ /mb*/i) { + $value = $value * 1024 * 1024; + } elsif ($unit =~ /gb*/i) { + $value = $value * 1024 * 1024 * 1024; + } elsif ($unit =~ /tb*/i) { + $value = $value * 1024 * 1024 * 1024 * 1024; + } + + return $value; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'reclamation_status' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'stage-status-progress', set => { + key_values => [ { name => 'stage_status_progress' } ], + output_template => 'Stage Status progress: %.2f %%', + perfdatas => [ + { label => 'stage_status_progress', value => 'stage_status_progress_absolute', template => '%.2f', + unit => '%', min => 0, max => 100 }, + ], + } + }, + { label => 'total-progress', set => { + key_values => [ { name => 'total_progress' } ], + output_template => 'Total progress: %.2f %%', + perfdatas => [ + { label => 'total_progress', value => 'total_progress_absolute', template => '%.2f', + unit => '%', min => 0, max => 100 }, + ], + } + }, + { label => 'data-scanned', set => { + key_values => [ { name => 'data_scanned' } ], + closure_custom_calc => $self->can('custom_volume_calc'), + closure_custom_calc_extra_options => { label_ref => 'data_scanned', display_ref => 'Data Scanned' }, + closure_custom_output => $self->can('custom_volume_output'), + closure_custom_perfdata => $self->can('custom_volume_perfdata'), + closure_custom_threshold_check => $self->can('custom_volume_threshold'), + } + }, + { label => 'reclaimable-space', set => { + key_values => [ { name => 'reclaimable_space' } ], + closure_custom_calc => $self->can('custom_volume_calc'), + closure_custom_calc_extra_options => { label_ref => 'reclaimable_space', display_ref => 'Reclaimable Space' }, + closure_custom_output => $self->can('custom_volume_output'), + closure_custom_perfdata => $self->can('custom_volume_perfdata'), + closure_custom_threshold_check => $self->can('custom_volume_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--getstatus reclamation' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{reclamation_status} !~ /ready/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # Reclamation Status = + # Stage Status Progress = 100 % + # Total Progress = 100 % + # Start Time = Sun Dec 16 15:30:00 2018 + # End Time = Sun Dec 16 16:08:57 2018 + # Data Scanned = 8.12 TB + # Number of Stages = 2 + # Reclaimable Space = 187.87 GB + + foreach (split(/\n/, $stdout)) { + $self->{global}->{reclamation_status} = $1 if ($_ =~ /.*Reclamation\sStatus\s=\s(.*)$/i); + $self->{global}->{stage_status_progress} = $1 if ($_ =~ /.*Stage\sStatus\sProgress\s=\s(.*)\s%$/i); + $self->{global}->{total_progress} = $1 if ($_ =~ /.*Total\sProgress\s=\s(.*)\s%$/i); + $self->{global}->{data_scanned} = $1 if ($_ =~ /.*Data\sScanned\s=\s(.*)$/i); + $self->{global}->{reclaimable_space} = $1 if ($_ =~ /.*Reclaimable\sSpace\s=\s(.*)$/i); + } +} + +1; + +__END__ + +=head1 MODE + +Check reclamation status and volumes. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='status' + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{reclamation_status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{reclamation_status} !~ /ready/i'). +Can used special variables like: %{reclamation_status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'status-progress', 'compacted', 'still-to-compact'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'status-progress', 'compacted', 'still-to-compact'. + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--getstatus reclamation'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/reduction.pm b/storage/quantum/dxi/ssh/mode/reduction.pm index 1246b3c87..3b63668b5 100644 --- a/storage/quantum/dxi/ssh/mode/reduction.pm +++ b/storage/quantum/dxi/ssh/mode/reduction.pm @@ -248,8 +248,6 @@ sub manage_selection { # - Deduplication Ratio = 3.95 : 1 # - Compression Ratio = 1.33 : 1 - # Command completed successfully. - foreach (split(/\n/, $stdout)) { $self->{global}->{size_before_reduction} = $1 if ($_ =~ /.*Data\sSize\sBefore\sReduction\s=\s(.*)$/i); $self->{global}->{incoming_namespace} = $1 if ($_ =~ /.*Incoming\sNamespace\s=\s(.*)$/i); diff --git a/storage/quantum/dxi/ssh/mode/storagearraystatus.pm b/storage/quantum/dxi/ssh/mode/storagearraystatus.pm new file mode 100644 index 000000000..d12ef425d --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/storagearraystatus.pm @@ -0,0 +1,224 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::storagearraystatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status is '" . $self->{result_values}->{status} . "'"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + return 0; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Storage array '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All storage array status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'status' }, { name => 'name' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--getstatus storagearray' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Normal/i' }, + }); + + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach ('warning_status', 'critical_status') { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # List of Storage Arrays: + # Total Count = 2 + # [Array = 1] + # Name = Qarray1 + # Status = Normal + # [Array = 2] + # Name = a0 + # Status = Normal + + my $id; + foreach (split(/\n/, $stdout)) { + $id = $1 if ($_ =~ /.*\[Array\s=\s(.*)\]$/i); + $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Status\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*Name\s=\s(.*)$/i && defined($id) && $id ne ''); + } +} + +1; + +__END__ + +=head1 MODE + +Check storage array status. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Normal/i'). +Can used special variables like: %{name}, %{status} + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--getstatus storagearray'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/systemstatus.pm b/storage/quantum/dxi/ssh/mode/systemstatus.pm new file mode 100644 index 000000000..f329e4bfb --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/systemstatus.pm @@ -0,0 +1,237 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::systemstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = "status is '" . $self->{result_values}->{status} . "' [type = " . $self->{result_values}->{type} . "] [value = " . $self->{result_values}->{value} . "]"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'}; + $self->{result_values}->{type} = $options{new_datas}->{$self->{instance} . '_type'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'}; + return 0; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Component '" . $options{instance_value}->{name} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All component status are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', set => { + key_values => [ { name => 'status' }, { name => 'name' }, { name => 'type' }, { name => 'value' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-getstatus systemboard' }, + "warning-status:s" => { name => 'warning_status' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Normal/i' }, + }); + + return $self; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach ('warning_status', 'critical_status') { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # System Board Components + # Total count = 45 + # [Component = 1] + # Name = IPMI + # Type = IPMI + # Value = NA + # Status = Normal + # [Component = 2] + # Name = Inlet Temperature + # Type = Temperature + # Value = 26 degrees C + # Status = Normal + # [Component = 3] + # Name = Exhaust Temperature + # Type = Temperature + # Value = 31 degrees C + # Status = Normal + + my $id; + foreach (split(/\n/, $stdout)) { + $id = $1 if ($_ =~ /.*\[Component\s=\s(.*)\]$/i); + $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Status\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*Name\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{type} = $1 if ($_ =~ /.*Type\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{value} = $1 if ($_ =~ /.*Value\s=\s(.*)$/i && defined($id) && $id ne ''); + } +} + +1; + +__END__ + +=head1 MODE + +Check system board status. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{name}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Normal/i'). +Can used special variables like: %{name}, %{status} + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '-getstatus systemboard'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/mode/throughput.pm b/storage/quantum/dxi/ssh/mode/throughput.pm new file mode 100644 index 000000000..c13c69596 --- /dev/null +++ b/storage/quantum/dxi/ssh/mode/throughput.pm @@ -0,0 +1,225 @@ +# +# Copyright 2018 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::quantum::dxi::ssh::mode::throughput; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_volume_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B/s', + value => $self->{result_values}->{volume}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}) + ); +} + +sub custom_volume_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{volume}, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_volume_output { + my ($self, %options) = @_; + + my ($volume_value, $volume_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{volume}); + my $msg = sprintf("%s: %s %s/s", $self->{result_values}->{display}, $volume_value, $volume_unit); + return $msg; +} + +sub custom_volume_calc { + my ($self, %options) = @_; + + $self->{result_values}->{volume} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + $self->{result_values}->{display} = $options{extra_options}->{display_ref}; + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + + return 0; +} + +sub convert_to_bytes { + my ($class, %options) = @_; + + my ($value, $unit) = split(/\s+/, $options{raw_value}); + if ($unit =~ /kb*/i) { + $value = $value * 1024; + } elsif ($unit =~ /mb*/i) { + $value = $value * 1024 * 1024; + } elsif ($unit =~ /gb*/i) { + $value = $value * 1024 * 1024 * 1024; + } elsif ($unit =~ /tb*/i) { + $value = $value * 1024 * 1024 * 1024 * 1024; + } + + return $value; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'read-rate', set => { + key_values => [ { name => 'read_rate' } ], + closure_custom_calc => $self->can('custom_volume_calc'), + closure_custom_calc_extra_options => { label_ref => 'read_rate', display_ref => 'Read Rate' }, + closure_custom_output => $self->can('custom_volume_output'), + closure_custom_perfdata => $self->can('custom_volume_perfdata'), + closure_custom_threshold_check => $self->can('custom_volume_threshold'), + } + }, + { label => 'write-rate', set => { + key_values => [ { name => 'write_rate' } ], + closure_custom_calc => $self->can('custom_volume_calc'), + closure_custom_calc_extra_options => { label_ref => 'write_rate', display_ref => 'Write Rate' }, + closure_custom_output => $self->can('custom_volume_output'), + closure_custom_perfdata => $self->can('custom_volume_perfdata'), + closure_custom_threshold_check => $self->can('custom_volume_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'syscli' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '--get ingestrate' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } + + $instance_mode = $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + + my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}, + ); + # Output data: + # Write Throughput = 0.03 MB/s + # Read Throughput = 6.98 MB/s + + foreach (split(/\n/, $stdout)) { + $self->{global}->{write_rate} = $1 if ($_ =~ /.*Write\sThroughput\s=\s(.*)$/i); + $self->{global}->{read_rate} = $1 if ($_ =~ /.*Read\sThroughput\s=\s(.*)$/i); + } +} + +1; + +__END__ + +=head1 MODE + +Check ingest throughput rate. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--warning-*> + +Threshold warning. +Can be: 'read-rate', 'write-rate'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'read-rate', 'write-rate'. + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'syscli'). + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '--get ingestrate'). + +=back + +=cut diff --git a/storage/quantum/dxi/ssh/plugin.pm b/storage/quantum/dxi/ssh/plugin.pm index 77cfc9123..ed46d1793 100644 --- a/storage/quantum/dxi/ssh/plugin.pm +++ b/storage/quantum/dxi/ssh/plugin.pm @@ -31,9 +31,17 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'compaction' => 'storage::quantum::dxi::ssh::mode::compaction', - 'disk-usage' => 'storage::quantum::dxi::ssh::mode::diskusage', - 'reduction' => 'storage::quantum::dxi::ssh::mode::reduction', + 'compaction' => 'storage::quantum::dxi::ssh::mode::compaction', + 'disk-usage' => 'storage::quantum::dxi::ssh::mode::diskusage', + 'hostbus-adapter-status' => 'storage::quantum::dxi::ssh::mode::hostbusadapterstatus', + 'health' => 'storage::quantum::dxi::ssh::mode::health', + 'memory' => 'storage::quantum::dxi::ssh::mode::memory', + 'network' => 'storage::quantum::dxi::ssh::mode::network', + 'reclamation' => 'storage::quantum::dxi::ssh::mode::reclamation', + 'reduction' => 'storage::quantum::dxi::ssh::mode::reduction', + 'storage-array-status' => 'storage::quantum::dxi::ssh::mode::storagearraystatus', + 'system-status' => 'storage::quantum::dxi::ssh::mode::systemstatus', + 'throughput' => 'storage::quantum::dxi::ssh::mode::throughput', ); return $self;