diff --git a/storage/quantum/dxi/ssh/custom/api.pm b/storage/quantum/dxi/ssh/custom/api.pm new file mode 100644 index 000000000..51f9b2bee --- /dev/null +++ b/storage/quantum/dxi/ssh/custom/api.pm @@ -0,0 +1,187 @@ +# +# 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 storage::quantum::dxi::ssh::custom::api; + +use strict; +use warnings; +use centreon::plugins::ssh; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => { + 'hostname:s' => { name => 'hostname' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' } + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'QUANTUM OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{ssh} = centreon::plugins::ssh->new(%options); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{ssh}->check_options(option_results => $self->{option_results}); + } + + return 0; +} + +sub convert_to_bytes { + my ($self, %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 execute_command { + my ($self, %options) = @_; + + my $content; + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + ($content) = $self->{ssh}->execute( + hostname => $self->{option_results}->{hostname}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef, + timeout => $self->{option_results}->{timeout}, + sudo => $self->{option_results}->{sudo} + ); + } else { + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') { + $self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command for local)'); + $self->{output}->option_exit(); + } + ($content) = centreon::plugins::misc::execute( + output => $self->{output}, + options => { timeout => $self->{option_results}->{timeout} }, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef + ); + } + + return $content; +} + +1; + +__END__ + +=head1 NAME + +quantum dxi + +=head1 SYNOPSIS + +quantum dxi + +=head1 QUANTUM OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=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. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/storage/quantum/dxi/ssh/mode/compaction.pm b/storage/quantum/dxi/ssh/mode/compaction.pm index 2b0b2ef25..aceea5e4d 100644 --- a/storage/quantum/dxi/ssh/mode/compaction.pm +++ b/storage/quantum/dxi/ssh/mode/compaction.pm @@ -28,78 +28,61 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = 'Compaction status: ' . $self->{result_values}->{compaction_status}; - return $msg; + + return 'Compaction status: ' . $self->{result_values}->{compaction_status}; } sub custom_status_calc { my ($self, %options) = @_; - + $self->{result_values}->{compaction_status} = $options{new_datas}->{$self->{instance} . '_compaction_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}) - ); + + $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; + return $self->{perfdata}->threshold_check( + value => $self->{result_values}->{volume}, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ] + ); } 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; + return sprintf('%s: %s %s', $self->{result_values}->{display}, $volume_value, $volume_unit); } sub custom_volume_calc { my ($self, %options) = @_; - $self->{result_values}->{volume} = $self->{instance_mode}->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + $self->{result_values}->{volume} = $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 => 'compaction_status' } ], @@ -143,22 +126,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 compaction' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{compaction_status} !~ /ready/i' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{compaction_status} !~ /ready/i' }, + }); + return $self; } @@ -166,25 +139,13 @@ 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; - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } 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}, - ); + + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus compaction'); # Output data: # Compaction Status = Ready # Status Progress = 0 % @@ -193,11 +154,12 @@ sub manage_selection { # Compacted = 12.00 MB # Still to compact = 123.00 MB + $self->{global} = {}; foreach (split(/\n/, $stdout)) { - $self->{global}->{compaction_status} = $1 if ($_ =~ /.*Compaction\sStatus\s=\s(.*)$/i); - $self->{global}->{status_progress} = $1 if ($_ =~ /.*Status\sProgress\s=\s(.*)\s%$/i); - $self->{global}->{compacted} = $1 if ($_ =~ /.*Compacted\s=\s(.*)$/i); - $self->{global}->{still_to_compact} = $1 if ($_ =~ /.*Still\sto\scompact\s=\s(.*)$/i); + $self->{global}->{compaction_status} = $1 if (/.*Compaction\sStatus\s=\s(.*)$/i); + $self->{global}->{status_progress} = $1 if (/.*Status\sProgress\s=\s(.*)\s%$/i); + $self->{global}->{compacted} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Compacted\s=\s(.*)$/i); + $self->{global}->{still_to_compact} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Still\sto\scompact\s=\s(.*)$/i); } } @@ -211,10 +173,6 @@ Check compaction status and volumes. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--filter-counters> Only display some counters (regexp can be used). @@ -230,48 +188,11 @@ Can used special variables like: %{compaction_status} Set critical threshold for status (Default: '%{compaction_status} !~ /ready/i'). Can used special variables like: %{compaction_status} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. 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 compaction'). - =back =cut diff --git a/storage/quantum/dxi/ssh/mode/dedupnas.pm b/storage/quantum/dxi/ssh/mode/dedupnas.pm index 293ba3318..da013a0b5 100644 --- a/storage/quantum/dxi/ssh/mode/dedupnas.pm +++ b/storage/quantum/dxi/ssh/mode/dedupnas.pm @@ -30,11 +30,12 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Status is '%s' [State: %s], Duration: %s, Percent complete: %s%%", + return sprintf( + "Status is '%s' [State: %s], Duration: %s, Percent complete: %s%%", $self->{result_values}->{status}, $self->{result_values}->{state}, centreon::plugins::misc::change_seconds(value => $self->{result_values}->{duration}), - $self->{result_values}->{percent_complete}); - return $msg; + $self->{result_values}->{percent_complete} + ); } sub custom_status_calc { @@ -113,20 +114,10 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 dedupnas' }, - "warning-status:s" => { name => 'warning_status', default => '%{state} !~ /Enabled/i' }, - "critical-status:s" => { name => 'critical_status', default => '' }, - }); + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '%{state} !~ /Enabled/i' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, + }); return $self; } @@ -135,25 +126,13 @@ 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; - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --list dedupnas'); # Output data: # List of all deduped NAS on source: # Total count = 2 @@ -186,17 +165,18 @@ sub manage_selection { # Actual data sent = 0 # Average data sent = 0 + $self->{global} = {}; my $id; foreach (split(/\n/, $stdout)) { - $id = $1 if ($_ =~ /.*\[dedupnas\s=\s(.*)\]$/i); - $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*NAS\sshare\sname\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{state} = $1 if ($_ =~ /.*Replication\sstate\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{start_time} = $1 if ($_ =~ /.*Replication\sstart\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{completion_time} = $1 if ($_ =~ /.*Replication\scompletion\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Replication\sstatus\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{percent_complete} = $1 if ($_ =~ /.*Percent\scomplete\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{original_size} = $1 if ($_ =~ /.*Original\sdata\ssize\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{sent_size} = $1 if ($_ =~ /.*Actual\sdata\ssent\s=\s(.*)$/i && defined($id) && $id ne ''); + $id = $1 if (/.*\[dedupnas\s=\s(.*)\]$/i); + $self->{global}->{$id}->{name} = $1 if (/.*NAS\sshare\sname\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{state} = $1 if (/.*Replication\sstate\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{start_time} = $1 if (/.*Replication\sstart\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{completion_time} = $1 if (/.*Replication\scompletion\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{status} = $1 if (/.*Replication\sstatus\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{percent_complete} = $1 if (/.*Percent\scomplete\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{original_size} = $1 if (/.*Original\sdata\ssize\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{sent_size} = $1 if (/.*Actual\sdata\ssent\s=\s(.*)$/i && defined($id) && $id ne ''); $self->{global}->{$id}->{status} = "-" if (defined($id) && $id ne '' && !defined($self->{global}->{$id}->{status})); $self->{global}->{$id}->{start_time} = "-" if (defined($id) && !defined($self->{global}->{$id}->{start_time})); $self->{global}->{$id}->{completion_time} = "-" if (defined($id) && !defined($self->{global}->{$id}->{completion_time})); @@ -213,10 +193,6 @@ Check deduped NAS on source. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--filter-counters> Only display some counters (regexp can be used). @@ -232,48 +208,11 @@ Can used special variables like: %{status}, %{state}, %{duration}, %{percent_com Set critical threshold for status (Default: ''). Can used special variables like: %{status}, %{state}, %{duration}, %{percent_complete}. -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'original-data-size', 'sent-data-size'. -=item B<--critical-*> - -Threshold critical. -Can be: 'original-data-size', 'sent-data-size'. - -=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 dedupnas'). - =back =cut diff --git a/storage/quantum/dxi/ssh/mode/dedupvtl.pm b/storage/quantum/dxi/ssh/mode/dedupvtl.pm index a253f632a..2cc2e19df 100644 --- a/storage/quantum/dxi/ssh/mode/dedupvtl.pm +++ b/storage/quantum/dxi/ssh/mode/dedupvtl.pm @@ -30,12 +30,11 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - my $msg = sprintf("Status is '%s' [State: %s], Duration: %s, Percent complete: %s%%", + return sprintf("Status is '%s' [State: %s], Duration: %s, Percent complete: %s%%", $self->{result_values}->{status}, $self->{result_values}->{state}, centreon::plugins::misc::change_seconds(value => $self->{result_values}->{duration}), $self->{result_values}->{percent_complete} ); - return $msg; } sub custom_status_calc { @@ -78,8 +77,10 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'status' }, { name => 'state' }, { name => 'start_time' }, - { name => 'completion_time' }, { name => 'percent_complete' }, { name => 'name' } ], + key_values => [ + { name => 'status' }, { name => 'state' }, { name => 'start_time' }, + { name => 'completion_time' }, { name => 'percent_complete' }, { name => 'name' } + ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -115,17 +116,8 @@ sub new { bless $self, $class; $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 dedupvtl' }, - 'warning-status:s' => { name => 'warning_status', default => '%{state} !~ /Enabled/i' }, - 'critical-status:s' => { name => 'critical_status', default => '' }, + 'warning-status:s' => { name => 'warning_status', default => '%{state} !~ /Enabled/i' }, + 'critical-status:s' => { name => 'critical_status', default => '' }, }); return $self; @@ -135,26 +127,13 @@ 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; - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --list dedupvtl'); # Output data: # List of all deduped VTL on source: # Total count = 2 @@ -187,17 +166,18 @@ sub manage_selection { # Actual data sent = 4352486416 # Average data sent = 1.9672e+07 + $self->{global} = {}; my $id; foreach (split(/\n/, $stdout)) { - $id = $1 if ($_ =~ /.*\[dedupvtl\s=\s(.*)\]$/i); - $self->{global}->{$id}->{name} = $1 if ($_ =~ /.*VTL\sname\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{state} = $1 if ($_ =~ /.*Replication\sstate\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{start_time} = $1 if ($_ =~ /.*Replication\sstart\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{completion_time} = $1 if ($_ =~ /.*Replication\scompletion\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{status} = $1 if ($_ =~ /.*Replication\sstatus\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{percent_complete} = $1 if ($_ =~ /.*Percent\scomplete\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{original_size} = $1 if ($_ =~ /.*Original\sdata\ssize\s=\s(.*)$/i && defined($id) && $id ne ''); - $self->{global}->{$id}->{sent_size} = $1 if ($_ =~ /.*Actual\sdata\ssent\s=\s(.*)$/i && defined($id) && $id ne ''); + $id = $1 if (/.*\[dedupvtl\s=\s(.*)\]$/i); + $self->{global}->{$id}->{name} = $1 if (/.*VTL\sname\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{state} = $1 if (/.*Replication\sstate\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{start_time} = $1 if (/.*Replication\sstart\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{completion_time} = $1 if (/.*Replication\scompletion\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{status} = $1 if (/.*Replication\sstatus\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{percent_complete} = $1 if (/.*Percent\scomplete\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{original_size} = $1 if (/.*Original\sdata\ssize\s=\s(.*)$/i && defined($id) && $id ne ''); + $self->{global}->{$id}->{sent_size} = $1 if (/.*Actual\sdata\ssent\s=\s(.*)$/i && defined($id) && $id ne ''); $self->{global}->{$id}->{status} = "-" if (defined($id) && $id ne '' && !defined($self->{global}->{$id}->{status})); $self->{global}->{$id}->{start_time} = "-" if (defined($id) && !defined($self->{global}->{$id}->{start_time})); $self->{global}->{$id}->{completion_time} = "-" if (defined($id) && !defined($self->{global}->{$id}->{completion_time})); @@ -214,10 +194,6 @@ Check deduped VTL on source. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--filter-counters> Only display some counters (regexp can be used). @@ -233,48 +209,11 @@ Can used special variables like: %{status}, %{state}, %{duration}, %{percent_com Set critical threshold for status (Default: ''). Can used special variables like: %{status}, %{state}, %{duration}, %{percent_complete}. -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'original-data-size', 'sent-data-size'. -=item B<--critical-*> - -Threshold critical. -Can be: 'original-data-size', 'sent-data-size'. - -=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 dedupvtl'). - =back =cut diff --git a/storage/quantum/dxi/ssh/mode/diskusage.pm b/storage/quantum/dxi/ssh/mode/diskusage.pm index afe624695..f0a5da430 100644 --- a/storage/quantum/dxi/ssh/mode/diskusage.pm +++ b/storage/quantum/dxi/ssh/mode/diskusage.pm @@ -27,18 +27,20 @@ use warnings; 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}); + + $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($self->{instance_mode}->{option_results}->{free})); @@ -46,24 +48,30 @@ sub custom_usage_threshold { $threshold_value = $self->{result_values}->{prct_used}; $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{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' } ]); + $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("Capacity: %s Used: %s (%.2f%%) Available: %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; + + return sprintf( + "Capacity: %s Used: %s (%.2f%%) Available: %s (%.2f%%)", + $total_value . " " . $total_unit, + $used_value . " " . $used_unit, $self->{result_values}->{prct_used}, + $free_value . " " . $free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -87,28 +95,29 @@ sub custom_usage_calc { 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}) - ); + + $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; + return $self->{perfdata}->threshold_check( + value => $self->{result_values}->{volume}, + threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ] + ); } 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 (%.2f%%)", $self->{result_values}->{display}, $volume_value, $volume_unit, $self->{result_values}->{prct_volume}); - return $msg; + return sprintf('%s: %s %s (%.2f%%)', $self->{result_values}->{display}, $volume_value, $volume_unit, $self->{result_values}->{prct_volume}); } sub custom_volume_calc { @@ -118,7 +127,7 @@ sub custom_volume_calc { $self->{result_values}->{total} = $self->{instance_mode}->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_disk_capacity'}); $self->{result_values}->{display} = $options{extra_options}->{display_ref}; $self->{result_values}->{label} = $options{extra_options}->{label_ref}; - + if ($self->{result_values}->{total} != 0) { $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{volume}; $self->{result_values}->{prct_volume} = $self->{result_values}->{volume} * 100 / $self->{result_values}->{total}; @@ -149,11 +158,11 @@ sub convert_to_bytes { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0, skipped_code => { -10 => 1 } } ]; - + $self->{maps_counters}->{global} = [ { label => 'usage', set => { key_values => [ { name => 'used_disk_space' }, { name => 'disk_capacity' } ], @@ -215,45 +224,19 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $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 diskusage' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, + '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; - } -} - 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --get diskusage'); # 2.2 Output data: # Disk Capacity = 16.00 TB # Available Disk Space = 15.66 TB @@ -271,15 +254,16 @@ sub manage_selection { # System Metadata = 147.83 GB 1.48% # Data Not Intended for Deduplication = 0.00 MB 0.00% + $self->{global} = {}; foreach (split(/\n/, $stdout)) { - $self->{global}->{disk_capacity} = $1 if ($_ =~ /.*Disk\sCapacity\s=\s(.*)$/i); - $self->{global}->{available_disk_space} = $1 if ($_ =~ /.*Available\sDisk\sSpace\s=\s(.*)$/i); - $self->{global}->{free_space} = $1 if ($_ =~ /.*Free\sSpace\s=\s(.*)\s+.*%.*$/i); - $self->{global}->{reclaimable_space} = $1 if ($_ =~ /.*Reclaimable\sSpace\s=\s(.*)\s+.*%.*$/i); - $self->{global}->{used_disk_space} = $1 if ($_ =~ /.*Used\sDisk\sSpace\s=\s(.*)$/i); - $self->{global}->{deduplicated_data} = $1 if ($_ =~ /.*Deduplicated\sData\s=\s(.*)\s+.*%.*$/i); - $self->{global}->{system_metadata} = $1 if ($_ =~ /.*System\sMetadata\s=\s(.*)\s+.*%.*$/i); - $self->{global}->{data_not_intended_for_deduplication} = $1 if ($_ =~ /.*Data\sNot\sIntended\sfor\sDeduplication\s=\s(.*)\s+.*%.*$/i); + $self->{global}->{disk_capacity} = $1 if (/.*Disk\sCapacity\s=\s(.*)$/i); + $self->{global}->{available_disk_space} = $1 if (/.*Available\sDisk\sSpace\s=\s(.*)$/i); + $self->{global}->{free_space} = $1 if (/.*Free\sSpace\s=\s(.*)\s+.*%.*$/i); + $self->{global}->{reclaimable_space} = $1 if (/.*Reclaimable\sSpace\s=\s(.*)\s+.*%.*$/i); + $self->{global}->{used_disk_space} = $1 if (/.*Used\sDisk\sSpace\s=\s(.*)$/i); + $self->{global}->{deduplicated_data} = $1 if (/.*Deduplicated\sData\s=\s(.*)\s+.*%.*$/i); + $self->{global}->{system_metadata} = $1 if (/.*System\sMetadata\s=\s(.*)\s+.*%.*$/i); + $self->{global}->{data_not_intended_for_deduplication} = $1 if (/.*Data\sNot\sIntended\sfor\sDeduplication\s=\s(.*)\s+.*%.*$/i); } } @@ -293,58 +277,16 @@ Check disk usage. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--filter-counters> Only display some counters (regexp can be used). Example: --filter-counters='usage' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'usage', 'free-space','reclaimable-space', 'deduplicated-data', -'system-metadata', 'data-not-intended-for-deduplication' - -=item B<--critical-*> - -Threshold critical. -Can be: 'usage', 'free-space','reclaimable-space', 'deduplicated-data', -'system-metadata', 'data-not-intended-for-deduplication' - -=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 diskusage'). +'system-metadata', 'data-not-intended-for-deduplication'. =back diff --git a/storage/quantum/dxi/ssh/mode/health.pm b/storage/quantum/dxi/ssh/mode/health.pm index f700ff510..7f63cab4a 100644 --- a/storage/quantum/dxi/ssh/mode/health.pm +++ b/storage/quantum/dxi/ssh/mode/health.pm @@ -28,14 +28,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = "status is '" . $self->{result_values}->{status} . "' [state = " . $self->{result_values}->{state} . "]"; - return $msg; + + return "status is '" . $self->{result_values}->{status} . "' [state = " . $self->{result_values}->{state} . "]"; } 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'}; @@ -50,11 +49,11 @@ sub prefix_output { 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' } ], @@ -71,32 +70,18 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Ready|Success/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; - } $self->change_macros(macros => ['warning_status', 'critical_status']); } @@ -104,15 +89,7 @@ sub check_options { 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --list healthcheckstatus'); # Output data: # Healthcheck Status # Total count = 2 @@ -129,12 +106,13 @@ sub manage_selection { # Finished = # Status = Ready + $self->{global} = {}; 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 ''); + $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 ''); } } @@ -148,10 +126,6 @@ Check health status. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--warning-status> Set warning threshold for status (Default: ''). @@ -162,38 +136,6 @@ Can used special variables like: %{name}, %{status}, %{state} 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 index 913a6d834..e7b7b3861 100644 --- a/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm +++ b/storage/quantum/dxi/ssh/mode/hostbusadapterstatus.pm @@ -28,14 +28,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = "status is '" . $self->{result_values}->{status} . "'"; - return $msg; + + return "status is '" . $self->{result_values}->{status} . "'"; } 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; @@ -49,11 +48,11 @@ sub prefix_output { 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' } ], @@ -70,32 +69,18 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Normal/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; - } $self->change_macros(macros => ['warning_status', 'critical_status']); } @@ -103,15 +88,7 @@ sub check_options { 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus hostbusadapter'); # Output data: # List of Hostbus Adapters # Total count = 4 @@ -128,11 +105,12 @@ sub manage_selection { # Name = SAS HBA 2 # Status = Normal + $self->{global} = {}; 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 ''); + $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 ''); } } @@ -146,10 +124,6 @@ Check hostbus adapters status. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--warning-status> Set warning threshold for status (Default: ''). @@ -160,38 +134,6 @@ Can used special variables like: %{name}, %{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 index d1b36ff99..bbe5dfd9a 100644 --- a/storage/quantum/dxi/ssh/mode/memory.pm +++ b/storage/quantum/dxi/ssh/mode/memory.pm @@ -27,18 +27,20 @@ use warnings; 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}); + + $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($self->{instance_mode}->{option_results}->{free})); @@ -46,24 +48,29 @@ sub custom_usage_threshold { $threshold_value = $self->{result_values}->{prct_used}; $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{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' } ]); + $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; + return 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} + ); } sub custom_usage_calc { @@ -104,11 +111,11 @@ sub convert_to_bytes { 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' } ], @@ -125,52 +132,27 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, + + $options{options}->add_options(arguments => { + '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; - } -} - 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus systemmemory'); # Output data: # Total Memory = 270.76 GB # Free Memory = 91.19 GB + $self->{global} = {}; foreach (split(/\n/, $stdout)) { - $self->{global}->{total} = $1 if ($_ =~ /.*Total\sMemory\s=\s(.*)$/i); - $self->{global}->{free} = $1 if ($_ =~ /.*Free\sMemory\s=\s(.*)$/i); + $self->{global}->{total} = $1 if (/.*Total\sMemory\s=\s(.*)$/i); + $self->{global}->{free} = $1 if (/.*Free\sMemory\s=\s(.*)$/i); } } @@ -184,10 +166,6 @@ Check memory usage. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--warning-usage> Threshold warning. @@ -196,38 +174,6 @@ Threshold warning. 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 index 4ce2eaf3b..765a255ee 100644 --- a/storage/quantum/dxi/ssh/mode/network.pm +++ b/storage/quantum/dxi/ssh/mode/network.pm @@ -28,14 +28,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = "status is '" . $self->{result_values}->{status} . "' [value = " . $self->{result_values}->{value} . "]"; - return $msg; + + return "status is '" . $self->{result_values}->{status} . "' [value = " . $self->{result_values}->{value} . "]"; } 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'}; @@ -50,11 +49,11 @@ sub prefix_output { 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' } ], @@ -71,22 +70,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Up/i' }, + }); + return $self; } @@ -94,25 +83,13 @@ 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; - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus networkport'); # Output data: # Network Ports # Total count = 5 @@ -129,12 +106,13 @@ sub manage_selection { # Value = NA # Status = Down + $self->{global} = {}; 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 ''); + $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 ''); } } @@ -148,10 +126,6 @@ Check network ports status. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--warning-status> Set warning threshold for status (Default: ''). @@ -162,38 +136,6 @@ Can used special variables like: %{name}, %{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 index b9107b19c..11e2006a0 100644 --- a/storage/quantum/dxi/ssh/mode/reclamation.pm +++ b/storage/quantum/dxi/ssh/mode/reclamation.pm @@ -28,9 +28,8 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = 'Reclamation status: ' . $self->{result_values}->{reclamation_status}; - return $msg; + + return 'Reclamation status: ' . $self->{result_values}->{reclamation_status}; } sub custom_status_calc { @@ -42,64 +41,49 @@ sub custom_status_calc { 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}) - ); + + $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' } ]); + + 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; + return sprintf('%s: %s %s', $self->{result_values}->{display}, $volume_value, $volume_unit); } sub custom_volume_calc { my ($self, %options) = @_; - $self->{result_values}->{volume} = $self->{instance_mode}->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + $self->{result_values}->{volume} = $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' } ], @@ -152,22 +136,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status', default => '' }, + 'critical-status:s' => { name => 'critical_status', default => '%{reclamation_status} !~ /ready/i' }, + }); + return $self; } @@ -175,25 +149,13 @@ 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; - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus reclamation'); # Output data: # Reclamation Status = # Stage Status Progress = 100 % @@ -204,12 +166,13 @@ sub manage_selection { # Number of Stages = 2 # Reclaimable Space = 187.87 GB + $self->{global} = {}; 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); + $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} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Data\sScanned\s=\s(.*)$/i); + $self->{global}->{reclaimable_space} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Reclaimable\sSpace\s=\s(.*)$/i); } } @@ -223,10 +186,6 @@ 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). @@ -242,48 +201,11 @@ Can used special variables like: %{reclamation_status} Set critical threshold for status (Default: '%{reclamation_status} !~ /ready/i'). Can used special variables like: %{reclamation_status} -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. 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 d7b27b48f..e76854e6d 100644 --- a/storage/quantum/dxi/ssh/mode/reduction.pm +++ b/storage/quantum/dxi/ssh/mode/reduction.pm @@ -27,64 +27,49 @@ use warnings; 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}) - ); + + $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' } ]); + + 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; + return sprintf('%s: %s %s', $self->{result_values}->{display}, $volume_value, $volume_unit); } sub custom_volume_calc { my ($self, %options) = @_; - $self->{result_values}->{volume} = $self->{instance_mode}->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + $self->{result_values}->{volume} = $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 => 'size-before-reduction', set => { key_values => [ { name => 'size_before_reduction' } ], @@ -192,43 +177,17 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $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 datareductionstat' }, }); - + 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; - } -} - 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --get datareductionstat'); # Output data: # Data Size Before Reduction = 346.08 TB # - Incoming Namespace = 0.00 MB @@ -242,18 +201,19 @@ sub manage_selection { # - Deduplication Ratio = 3.95 : 1 # - Compression Ratio = 1.33 : 1 + $self->{global} = {}; 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); - $self->{global}->{nfs_deduplicated_shares} = $1 if ($_ =~ /.*NFS\sDeduplicated\sShares\s=\s(.*)$/i); - $self->{global}->{cifs_smb_deduplicated_shares} = $1 if ($_ =~ /.*CIFS\/SMB\sDeduplicated\sShares\s=\s(.*)$/i); - $self->{global}->{application_specific_deduplicated_shares} = $1 if ($_ =~ /.*Application\sSpecific\sDeduplicated\sShares\s=\s(.*)$/i); - $self->{global}->{deduplicated_partitions} = $1 if ($_ =~ /.*Deduplicated\sPartitions\s=\s(.*)$/i); - $self->{global}->{ost_storage_servers} = $1 if ($_ =~ /.*OST\sStorage\sServers\s=\s(.*)$/i); - $self->{global}->{size_after_reduction} = $1 if ($_ =~ /.*Data\sSize\sAfter\sReduction\s=\s(.*)$/i); - $self->{global}->{total_reduction_ratio} = $1 if ($_ =~ /.*Total\sReduction\sRatio\s=\s(.*)\s:\s1$/i); - $self->{global}->{deduplication_ratio} = $1 if ($_ =~ /.*Deduplication\sRatio\s=\s(.*)\s:\s1$/i); - $self->{global}->{compression_ratio} = $1 if ($_ =~ /.*Compression\sRatio\s=\s(.*)\s:\s1$/i); + $self->{global}->{size_before_reduction} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Data\sSize\sBefore\sReduction\s=\s(.*)$/i); + $self->{global}->{incoming_namespace} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Incoming\sNamespace\s=\s(.*)$/i); + $self->{global}->{nfs_deduplicated_shares} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*NFS\sDeduplicated\sShares\s=\s(.*)$/i); + $self->{global}->{cifs_smb_deduplicated_shares} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*CIFS\/SMB\sDeduplicated\sShares\s=\s(.*)$/i); + $self->{global}->{application_specific_deduplicated_shares} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Application\sSpecific\sDeduplicated\sShares\s=\s(.*)$/i); + $self->{global}->{deduplicated_partitions} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Deduplicated\sPartitions\s=\s(.*)$/i); + $self->{global}->{ost_storage_servers} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*OST\sStorage\sServers\s=\s(.*)$/i); + $self->{global}->{size_after_reduction} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Data\sSize\sAfter\sReduction\s=\s(.*)$/i); + $self->{global}->{total_reduction_ratio} = $1 if (/.*Total\sReduction\sRatio\s=\s(.*)\s:\s1$/i); + $self->{global}->{deduplication_ratio} = $1 if (/.*Deduplication\sRatio\s=\s(.*)\s:\s1$/i); + $self->{global}->{compression_ratio} = $1 if (/.*Compression\sRatio\s=\s(.*)\s:\s1$/i); } } @@ -267,65 +227,20 @@ Check data reduction statistics. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--filter-counters> Only display some counters (regexp can be used). Example: --filter-counters='ratio' -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. +Thresholds. Can be: 'size-before-reduction', 'size-after-reduction', 'incoming-namespace', 'nfs-deduplicated-shares', cifs-smb-deduplicated-shares', 'application-specific-deduplicated-shares', 'deduplicated-partitions', 'ost-storage-servers', 'total-reduction-ratio', 'deduplication-ratio', 'compression-ratio'. -=item B<--critical-*> - -Threshold critical. -Can be: 'size-before-reduction', 'size-after-reduction', 'incoming-namespace', -'nfs-deduplicated-shares', cifs-smb-deduplicated-shares', -'application-specific-deduplicated-shares', 'deduplicated-partitions', -'ost-storage-servers', 'total-reduction-ratio', -'deduplication-ratio', 'compression-ratio'. - -=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 datareductionstat'). - =back =cut diff --git a/storage/quantum/dxi/ssh/mode/storagearraystatus.pm b/storage/quantum/dxi/ssh/mode/storagearraystatus.pm index 741ffa66c..b205d5435 100644 --- a/storage/quantum/dxi/ssh/mode/storagearraystatus.pm +++ b/storage/quantum/dxi/ssh/mode/storagearraystatus.pm @@ -28,14 +28,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) sub custom_status_output { my ($self, %options) = @_; - - my $msg = "status is '" . $self->{result_values}->{status} . "'"; - return $msg; + + return "status is '" . $self->{result_values}->{status} . "'"; } 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; @@ -49,11 +48,11 @@ sub prefix_output { 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' } ], @@ -70,32 +69,18 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Normal/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; - } $self->change_macros(macros => ['warning_status', 'critical_status']); } @@ -103,15 +88,7 @@ sub check_options { 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus storagearray'); # Output data: # List of Storage Arrays: # Total Count = 2 @@ -122,11 +99,12 @@ sub manage_selection { # Name = a0 # Status = Normal + $self->{global} = {}; 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 ''); + $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 ''); } } @@ -140,10 +118,6 @@ Check storage array status. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--warning-status> Set warning threshold for status (Default: ''). @@ -154,38 +128,6 @@ Can used special variables like: %{name}, %{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 index ff6e88497..94c35fc4f 100644 --- a/storage/quantum/dxi/ssh/mode/systemstatus.pm +++ b/storage/quantum/dxi/ssh/mode/systemstatus.pm @@ -28,14 +28,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold) 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; + + return "status is '" . $self->{result_values}->{status} . "' [type = " . $self->{result_values}->{type} . "] [value = " . $self->{result_values}->{value} . "]"; } 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'}; @@ -51,11 +50,11 @@ sub prefix_output { 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' } ], @@ -72,22 +71,12 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, - }); - + + $options{options}->add_options(arguments => { + 'warning-status:s' => { name => 'warning_status' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /Normal/i' } + }); + return $self; } @@ -95,25 +84,13 @@ 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; - } - $self->change_macros(macros => ['warning_status', 'critical_status']); } 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --getstatus systemboard'); # Output data: # System Board Components # Total count = 45 @@ -133,13 +110,14 @@ sub manage_selection { # Value = 31 degrees C # Status = Normal + $self->{global} = {}; 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 ''); + $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 ''); } } @@ -153,10 +131,6 @@ Check system board status. =over 8 -=item B<--hostname> - -Hostname to query. - =item B<--warning-status> Set warning threshold for status (Default: ''). @@ -167,38 +141,6 @@ Can used special variables like: %{name}, %{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 index c6db26edf..264547730 100644 --- a/storage/quantum/dxi/ssh/mode/throughput.pm +++ b/storage/quantum/dxi/ssh/mode/throughput.pm @@ -27,64 +27,49 @@ use warnings; 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}) - ); + + $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' } ]); + + 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; + return sprintf("%s: %s %s/s", $self->{result_values}->{display}, $volume_value, $volume_unit); } sub custom_volume_calc { my ($self, %options) = @_; - $self->{result_values}->{volume} = $self->{instance_mode}->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}}); + $self->{result_values}->{volume} = $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' } ], @@ -111,50 +96,24 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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' }, + + $options{options}->add_options(arguments => { }); - + 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; - } -} - 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}, - ); + my $stdout = $options{custom}->execute_command(command => 'syscli --get ingestrate'); # Output data: # Write Throughput = 0.03 MB/s # Read Throughput = 6.98 MB/s - + $self->{global} = {}; 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); + $self->{global}->{write_rate} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Write\sThroughput\s=\s(.*)$/i) + $self->{global}->{read_rate} = $options{custom}->convert_to_bytes(raw_value => $1) if (/.*Read\sThroughput\s=\s(.*)$/i); } } @@ -168,52 +127,11 @@ Check ingest throughput rate. =over 8 -=item B<--hostname> +=item B<--warning-*> B<--critical-*> -Hostname to query. - -=item B<--warning-*> - -Threshold warning. +Thresholds. 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 276acd7fa..fb634d62f 100644 --- a/storage/quantum/dxi/ssh/plugin.pm +++ b/storage/quantum/dxi/ssh/plugin.pm @@ -22,7 +22,7 @@ package storage::quantum::dxi::ssh::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; @@ -45,6 +45,7 @@ sub new { 'system-status' => 'storage::quantum::dxi::ssh::mode::systemstatus', 'throughput' => 'storage::quantum::dxi::ssh::mode::throughput', ); + $self->{custom_modes}{api} = 'storage::quantum::dxi::ssh::custom::api'; return $self; }