add quantum dxi plugin (#1280)

This commit is contained in:
Colin Gagnaire 2018-12-19 14:12:19 +01:00 committed by GitHub
parent cf4eea8d2c
commit 2aceb3e48d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1064 additions and 0 deletions

View File

@ -0,0 +1,316 @@
#
# Copyright 2018 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package storage::quantum::dxi::ssh::mode::compaction;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_status_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'Compaction status: ' . $self->{result_values}->{compaction_status};
return $msg;
}
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})
);
}
sub custom_volume_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{volume},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_volume_output {
my ($self, %options) = @_;
my ($volume_value, $volume_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{volume});
my $msg = sprintf("%s: %s %s", $self->{result_values}->{display}, $volume_value, $volume_unit);
return $msg;
}
sub custom_volume_calc {
my ($self, %options) = @_;
$self->{result_values}->{volume} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}});
$self->{result_values}->{display} = $options{extra_options}->{display_ref};
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
return 0;
}
sub convert_to_bytes {
my ($class, %options) = @_;
my ($value, $unit) = split(/\s+/, $options{raw_value});
if ($unit =~ /kb*/i) {
$value = $value * 1024;
} elsif ($unit =~ /mb*/i) {
$value = $value * 1024 * 1024;
} elsif ($unit =~ /gb*/i) {
$value = $value * 1024 * 1024 * 1024;
} elsif ($unit =~ /tb*/i) {
$value = $value * 1024 * 1024 * 1024 * 1024;
}
return $value;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
];
$self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => {
key_values => [ { name => 'compaction_status' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'),
}
},
{ label => 'status-progress', set => {
key_values => [ { name => 'status_progress' } ],
output_template => 'Status progress: %.2f %%',
perfdatas => [
{ label => 'status_progress', value => 'status_progress_absolute', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
{ label => 'compacted', set => {
key_values => [ { name => 'compacted' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'compacted', display_ref => 'Compacted' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'still-to-compact', set => {
key_values => [ { name => 'still_to_compact' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'still_to_compact', display_ref => 'Still to compact' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'syscli' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '--getstatus compaction' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{compaction_status} !~ /ready/i' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
$instance_mode = $self;
$self->change_macros();
}
sub change_macros {
my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
}
}
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = {};
my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
);
# Output data:
# Compaction Status = Ready
# Status Progress = 0 %
# Start Time =
# End Time =
# Compacted = 12.00 MB
# Still to compact = 123.00 MB
#
# Command completed successfully.
foreach (split(/\n/, $stdout)) {
$self->{global}->{compaction_status} = $1 if ($_ =~ /.*Compaction\sStatus\s=\s(.*)$/i);
$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);
}
}
1;
__END__
=head1 MODE
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).
Example: --filter-counters='status'
=item B<--warning-status>
Set warning threshold for status (Default: '').
Can used special variables like: %{compaction_status}
=item B<--critical-status>
Set critical threshold for status (Default: '%{compaction_status} !~ /ready/i').
Can used special variables like: %{compaction_status}
=item B<--warning-*>
Threshold warning.
Can be: 'status-progress', 'compacted', 'still-to-compact'.
=item B<--critical-*>
Threshold critical.
Can be: 'status-progress', 'compacted', 'still-to-compact'.
=item B<--ssh-option>
Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52').
=item B<--ssh-path>
Specify ssh command path (default: none)
=item B<--ssh-command>
Specify ssh command (default: 'ssh'). Useful to use 'plink'.
=item B<--timeout>
Timeout in seconds for the command (Default: 30).
=item B<--sudo>
Use 'sudo' to execute the command.
=item B<--command>
Command to get information (Default: 'syscli').
=item B<--command-path>
Command path.
=item B<--command-options>
Command options (Default: '--getstatus compaction').
=back
=cut

View File

@ -0,0 +1,359 @@
#
# Copyright 2018 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package storage::quantum::dxi::ssh::mode::diskusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => 'used',
unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value,
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
my ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
my $msg = sprintf("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;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{total} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_disk_capacity'});
$self->{result_values}->{used} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_used_disk_space'});
if ($self->{result_values}->{total} != 0) {
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
} else {
$self->{result_values}->{free} = '0';
$self->{result_values}->{prct_used} = '0';
$self->{result_values}->{prct_free} = '0';
}
return 0;
}
sub custom_volume_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B',
value => $self->{result_values}->{volume},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label})
);
}
sub custom_volume_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{volume},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_volume_output {
my ($self, %options) = @_;
my ($volume_value, $volume_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{volume});
my $msg = sprintf("%s: %s %s (%.2f%%)", $self->{result_values}->{display}, $volume_value, $volume_unit, $self->{result_values}->{prct_volume});
return $msg;
}
sub custom_volume_calc {
my ($self, %options) = @_;
$self->{result_values}->{volume} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}});
$self->{result_values}->{total} = $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};
} else {
$self->{result_values}->{free} = '0';
$self->{result_values}->{prct_volume} = '0';
}
return 0;
}
sub convert_to_bytes {
my ($class, %options) = @_;
my ($value, $unit) = split(/\s+/, $options{raw_value});
if ($unit =~ /kb*/i) {
$value = $value * 1024;
} elsif ($unit =~ /mb*/i) {
$value = $value * 1024 * 1024;
} elsif ($unit =~ /gb*/i) {
$value = $value * 1024 * 1024 * 1024;
} elsif ($unit =~ /tb*/i) {
$value = $value * 1024 * 1024 * 1024 * 1024;
}
return $value;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }
];
$self->{maps_counters}->{global} = [
{ label => 'usage', set => {
key_values => [ { name => 'used_disk_space' }, { name => 'disk_capacity' } ],
closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'),
}
},
{ label => 'free-space', set => {
key_values => [ { name => 'free_space' }, { name => 'disk_capacity' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'free_space', display_ref => 'Free Space' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'reclaimable-space', set => {
key_values => [ { name => 'reclaimable_space' }, { name => 'disk_capacity' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'reclaimable_space', display_ref => 'Reclaimable Space' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'deduplicated-data', set => {
key_values => [ { name => 'deduplicated_data' }, { name => 'disk_capacity' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'deduplicated_data', display_ref => 'Deduplicated Data' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'system-metadata', set => {
key_values => [ { name => 'system_metadata' }, { name => 'disk_capacity' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'system_metadata', display_ref => 'System Metadata' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'data-not-intended-for-deduplication', set => {
key_values => [ { name => 'data_not_intended_for_deduplication' }, { name => 'disk_capacity' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'data_not_intended_for_deduplication', display_ref => 'Data Not Intended for Deduplication' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'syscli' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '--get diskusage' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') {
$self->{option_results}->{remote} = 1;
}
$instance_mode = $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = {};
my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
);
# 2.2 Output data:
# Disk Capacity = 16.00 TB
# Available Disk Space = 15.66 TB
# - Free Space = 15.64 TB (97.78% of capacity)
# - Reclaimable Space = 15.55 GB (0.10% of capacity)
# Used Disk Space = 355.23 GB
# - Deduplicated Data = 238.12 GB (1.49% of capacity)
# - System Metadata = 69.30 GB (0.43% of capacity)
# - Data Not Intended for Deduplication = 32.26 GB (0.20% of capacity)
# 2.1 Output data:
# Disk Capacity = 10.00 TB
# Available Disk Space = 9.35 TB
# Used Disk Space = 649.78 GB
# Deduplicated Data = 501.95 GB 5.02%
# System Metadata = 147.83 GB 1.48%
# Data Not Intended for Deduplication = 0.00 MB 0.00%
#
# Command completed successfully.
foreach (split(/\n/, $stdout)) {
$self->{global}->{disk_capacity} = $1 if ($_ =~ /.*Disk\sCapacity\s=\s(.*)$/i);
$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);
}
}
1;
__END__
=head1 MODE
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-*>
Threshold warning.
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').
=back
=cut

View File

@ -0,0 +1,339 @@
#
# Copyright 2018 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package storage::quantum::dxi::ssh::mode::reduction;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_volume_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{label}, unit => 'B',
value => $self->{result_values}->{volume},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label})
);
}
sub custom_volume_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{volume},
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_volume_output {
my ($self, %options) = @_;
my ($volume_value, $volume_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{volume});
my $msg = sprintf("%s: %s %s", $self->{result_values}->{display}, $volume_value, $volume_unit);
return $msg;
}
sub custom_volume_calc {
my ($self, %options) = @_;
$self->{result_values}->{volume} = $instance_mode->convert_to_bytes(raw_value => $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}});
$self->{result_values}->{display} = $options{extra_options}->{display_ref};
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
return 0;
}
sub convert_to_bytes {
my ($class, %options) = @_;
my ($value, $unit) = split(/\s+/, $options{raw_value});
if ($unit =~ /kb*/i) {
$value = $value * 1024;
} elsif ($unit =~ /mb*/i) {
$value = $value * 1024 * 1024;
} elsif ($unit =~ /gb*/i) {
$value = $value * 1024 * 1024 * 1024;
} elsif ($unit =~ /tb*/i) {
$value = $value * 1024 * 1024 * 1024 * 1024;
}
return $value;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 }
];
$self->{maps_counters}->{global} = [
{ label => 'size-before-reduction', set => {
key_values => [ { name => 'size_before_reduction' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'size_before_reduction', display_ref => 'Data Size Before Reduction' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'size-after-reduction', set => {
key_values => [ { name => 'size_after_reduction' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'size_after_reduction', display_ref => 'Data Size After Reduction' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'incoming-namespace', set => {
key_values => [ { name => 'incoming_namespace' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'incoming_namespace', display_ref => 'Incoming Namespace' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'nfs-deduplicated-shares', set => {
key_values => [ { name => 'nfs_deduplicated_shares' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'nfs_deduplicated_shares', display_ref => 'NFS Deduplicated Shares' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'cifs-smb-deduplicated-shares', set => {
key_values => [ { name => 'cifs_smb_deduplicated_shares' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'cifs_smb_deduplicated_shares', display_ref => 'CIFS/SMB Deduplicated Shares' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'application-specific-deduplicated-shares', set => {
key_values => [ { name => 'application_specific_deduplicated_shares' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'application_specific_deduplicated_shares', display_ref => 'Application Specific Deduplicated Shares' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'deduplicated-partitions', set => {
key_values => [ { name => 'deduplicated_partitions' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'deduplicated_partitions', display_ref => 'Deduplicated Partitions' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'ost-storage-servers', set => {
key_values => [ { name => 'ost_storage_servers' } ],
closure_custom_calc => $self->can('custom_volume_calc'),
closure_custom_calc_extra_options => { label_ref => 'ost_storage_servers', display_ref => 'OST Storage Servers' },
closure_custom_output => $self->can('custom_volume_output'),
closure_custom_perfdata => $self->can('custom_volume_perfdata'),
closure_custom_threshold_check => $self->can('custom_volume_threshold'),
}
},
{ label => 'total-reduction-ratio', set => {
key_values => [ { name => 'total_reduction_ratio' } ],
output_template => 'Total Reduction Ratio: %.2f',
perfdatas => [
{ label => 'total_reduction_ratio', value => 'total_reduction_ratio_absolute', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
{ label => 'deduplication-ratio', set => {
key_values => [ { name => 'deduplication_ratio' } ],
output_template => 'Deduplication Ratio: %.2f',
perfdatas => [
{ label => 'deduplication_ratio', value => 'deduplication_ratio_absolute', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
{ label => 'compression-ratio', set => {
key_values => [ { name => 'compression_ratio' } ],
output_template => 'Compression Ratio: %.2f',
perfdatas => [
{ label => 'compression_ratio', value => 'compression_ratio_absolute', template => '%.2f',
unit => '%', min => 0, max => 100 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"hostname:s" => { name => 'hostname' },
"ssh-option:s@" => { name => 'ssh_option' },
"ssh-path:s" => { name => 'ssh_path' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"timeout:s" => { name => 'timeout', default => 30 },
"sudo" => { name => 'sudo' },
"command:s" => { name => 'command', default => 'syscli' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '--get 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;
}
$instance_mode = $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{global} = {};
my ($stdout, $exit_code) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
sudo => $self->{option_results}->{sudo},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options},
);
# Output data:
# Data Size Before Reduction = 346.08 TB
# - Incoming Namespace = 0.00 MB
# - NFS Deduplicated Shares = 125.98 GB
# - CIFS/SMB Deduplicated Shares = 2.04 TB
# - Application Specific Deduplicated Shares = 0.00 MB
# - Deduplicated Partitions = 343.91 TB
# - OST Storage Servers = 0.00 MB
# Data Size After Reduction = 66.00 TB
# Total Reduction Ratio = 5.24 : 1
# - Deduplication Ratio = 3.95 : 1
# - Compression Ratio = 1.33 : 1
# Command completed successfully.
foreach (split(/\n/, $stdout)) {
$self->{global}->{size_before_reduction} = $1 if ($_ =~ /.*Data\sSize\sBefore\sReduction\s=\s(.*)$/i);
$self->{global}->{incoming_namespace} = $1 if ($_ =~ /.*Incoming\sNamespace\s=\s(.*)$/i);
$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);
}
}
1;
__END__
=head1 MODE
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-*>
Threshold warning.
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

View File

@ -0,0 +1,50 @@
#
# Copyright 2018 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package storage::quantum::dxi::ssh::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'compaction' => 'storage::quantum::dxi::ssh::mode::compaction',
'disk-usage' => 'storage::quantum::dxi::ssh::mode::diskusage',
'reduction' => 'storage::quantum::dxi::ssh::mode::reduction',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Quantum DXi series appliances through SSH commands.
=cut