From 46c7f13946474f0dead1260692874fe74e2819fb Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 19 Apr 2019 11:23:02 +0200 Subject: [PATCH] update fujitsu eternus dx modes with class counter --- .../fujitsu/eternus/dx/ssh/mode/cpu.pm | 174 +++--------- .../fujitsu/eternus/dx/ssh/mode/portstats.pm | 198 ++++---------- .../fujitsu/eternus/dx/ssh/mode/raidgroups.pm | 257 ++++++------------ .../eternus/dx/ssh/mode/volumestats.pm | 226 +++++---------- 4 files changed, 254 insertions(+), 601 deletions(-) diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm index cd5c0b99e..3f5b77760 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/cpu.pm @@ -20,26 +20,37 @@ package storage::fujitsu::eternus::dx::ssh::mode::cpu; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; +use centreon::plugins::misc; -my $maps_counters = { - cpu => { - '001_usage' => { - set => { +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' } + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'usage', nlabel => 'cpu.utilization.percentage', set => { key_values => [ { name => 'usage' }, { name => 'display' } ], output_template => 'Usage : %d %%', perfdatas => [ { label => 'cpu', value => 'usage_absolute', template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - } -}; + ]; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{display} . "' "; +} sub new { my ($class, %options) = @_; @@ -47,132 +58,41 @@ sub new { 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 }, - "command:s" => { name => 'command', default => 'show' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => 'performance -type cm' }, - "no-component:s" => { name => 'no_component' }, - "filter-name:s" => { name => 'filter_name' }, - }); - $self->{no_components} = undef; - - foreach my $key (('cpu')) { - foreach (keys %{$maps_counters->{$key}}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); - } - } - + $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 }, + "command:s" => { name => 'command', default => 'show' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => 'performance -type cm' }, + "filter-name:s" => { name => 'filter_name' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { $self->{option_results}->{remote} = 1; } - - foreach my $key (('cpu')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{cpu}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All CPUs are ok'); - } - - foreach my $id (sort keys %{$self->{cpu}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{cpu}}) { - my $obj = $maps_counters->{cpu}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{cpu}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "CPU '$self->{cpu}->{$id}->{display}' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "CPU '$self->{cpu}->{$id}->{display}' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "CPU '$self->{cpu}->{$id}->{display}' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); } sub manage_selection { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - ssh_pipe => 1, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + ssh_pipe => 1, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); # Can have 4 columns also. #Location Busy Rate(%) Copy Residual Quantity(MB) @@ -191,16 +111,16 @@ sub manage_selection { if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $cpu_name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $cpu_name . "': no matching filter name."); + $self->{output}->output_add(long_msg => "skipping '" . $cpu_name . "': no matching filter name."); next; } $self->{cpu}->{$cpu_name} = { display => $cpu_name, usage => $cpu_value }; } - + if (scalar(keys %{$self->{cpu}}) <= 0) { - $self->{output}->output_add(severity => defined($self->{no_components}) ? $self->{no_components} : 'unknown', - short_msg => 'No components are checked.'); + $self->{output}->add_option_msg(short_msg => "No component found."); + $self->{output}->option_exit(); } } @@ -247,10 +167,6 @@ Command path (Default: none). Command options (Default: 'performance -type cm'). -=item B<--no-component> - -Set the threshold where no components (Default: 'unknown' returns). - =item B<--filter-name> Filter by name (regexp can be used). diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm index e9f752fa1..3ca8cf100 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/portstats.pm @@ -20,56 +20,64 @@ package storage::fujitsu::eternus::dx::ssh::mode::portstats; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; +use centreon::plugins::misc; -my $maps_counters = { - port => { - '000_read-iops' => { - set => { +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'port', type => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'All ports are ok' } + ]; + + $self->{maps_counters}->{port} = [ + { label => 'read-iops', nlabel => 'port.io.read.usage.iops', set => { key_values => [ { name => 'read_iops' }, { name => 'display' } ], output_template => 'Read IOPS : %d', perfdatas => [ { label => 'read_iops', value => 'read_iops_absolute', template => '%d', unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '001_write-iops' => { - set => { + { label => 'write-iops', nlabel => 'port.io.write.usage.iops', set => { key_values => [ { name => 'write_iops' }, { name => 'display' } ], output_template => 'Write IOPS : %d', perfdatas => [ { label => 'write_iops', value => 'write_iops_absolute', template => '%d', unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '002_read-traffic' => { - set => { + { label => 'read-traffic', nlabel => 'port.traffic.read.usage.bitspersecond', set => { key_values => [ { name => 'read_traffic' }, { name => 'display' } ], output_template => 'Read Traffic : %s %s/s', output_change_bytes => 2, perfdatas => [ { label => 'read_traffic', value => 'read_traffic_absolute', template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '003_write-traffic' => { - set => { + { label => 'write-traffic', nlabel => 'port.traffic.write.usage.bitspersecond', set => { key_values => [ { name => 'write_traffic' }, { name => 'display' } ], output_template => 'Write Traffic : %s %s/s', output_change_bytes => 2, perfdatas => [ { label => 'write_traffic', value => 'write_traffic_absolute', template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - } -}; + ]; +} + +sub prefix_port_output { + my ($self, %options) = @_; + + return "Port '" . $options{instance_value}->{display} . "' "; +} sub new { my ($class, %options) = @_; @@ -77,132 +85,41 @@ sub new { 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 }, - "command:s" => { name => 'command', default => 'show' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => 'performance -type port' }, - "no-component:s" => { name => 'no_component' }, - "filter-name:s" => { name => 'filter_name' }, - }); - $self->{no_components} = undef; - - foreach my $key (('port')) { - foreach (keys %{$maps_counters->{$key}}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); - } - } - + $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 }, + "command:s" => { name => 'command', default => 'show' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => 'performance -type port' }, + "filter-name:s" => { name => 'filter_name' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { $self->{option_results}->{remote} = 1; } - - foreach my $key (('port')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{port}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Ports are ok'); - } - - foreach my $id (sort keys %{$self->{port}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{port}}) { - my $obj = $maps_counters->{port}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{port}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Port '$self->{port}->{$id}->{display}' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Port '$self->{port}->{$id}->{display}' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Port '$self->{port}->{$id}->{display}' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); } sub manage_selection { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - ssh_pipe => 1, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + ssh_pipe => 1, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); #Location IOPS(IOPS) Throughput(MB/s) # Read / Write Read / Write @@ -221,16 +138,17 @@ sub manage_selection { next; } - $self->{port}->{$port_name} = { display => $port_name, - read_iops => $port_read_iops, write_iops => $port_write_iops, - read_traffic => $port_read_traffic * 1000 * 1000 * 8, - write_traffic => $port_write_traffic * 1000 * 1000 * 8 - }; + $self->{port}->{$port_name} = { + display => $port_name, + read_iops => $port_read_iops, write_iops => $port_write_iops, + read_traffic => $port_read_traffic * 1000 * 1000 * 8, + write_traffic => $port_write_traffic * 1000 * 1000 * 8 + }; } - + if (scalar(keys %{$self->{port}}) <= 0) { - $self->{output}->output_add(severity => defined($self->{no_components}) ? $self->{no_components} : 'unknown', - short_msg => 'No components are checked.'); + $self->{output}->add_option_msg(short_msg => "No port found."); + $self->{output}->option_exit(); } } @@ -277,10 +195,6 @@ Command path (Default: none). Command options (Default: 'performance -type port'). -=item B<--no-component> - -Set the threshold where no components (Default: 'unknown' returns). - =item B<--filter-name> Filter by name (regexp can be used). diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm index 2a069a96a..cc191b1be 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/raidgroups.pm @@ -20,48 +20,16 @@ package storage::fujitsu::eternus::dx::ssh::mode::raidgroups; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; - -my $thresholds = { - rg => [ - ['Available', 'OK'], - ['Spare in Use', 'WARNING'], - ], -}; -my $instance_mode; - -my $maps_counters = { - rg => { - '000_status' => { - set => { threshold => 0, - key_values => [ { name => 'status' } ], - closure_custom_calc => \&custom_status_calc, - output_template => 'Status : %s', output_error_template => 'Status : %s', - output_use => 'status', - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&custom_threshold_output, - } - }, - '001_usage' => { - set => { - key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, - }, - }, - } -}; +use centreon::plugins::misc; sub custom_threshold_output { my ($self, %options) = @_; - return $instance_mode->get_severity(section => 'rg', value => $self->{result_values}->{status}); + return $self->{instance_mode}->get_severity(section => 'rg', value => $self->{result_values}->{status}); } sub custom_status_calc { @@ -73,22 +41,22 @@ sub custom_status_calc { sub custom_usage_perfdata { my ($self, %options) = @_; - - my $extra_label = ''; - if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { - $extra_label .= '_' . $self->{result_values}->{display}; - } - $self->{output}->perfdata_add(label => 'used' . $extra_label, 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', + nlabel => $self->{nlabel}, + instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total} + ); } sub custom_usage_threshold { my ($self, %options) = @_; - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, 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}->{prct_used}, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]); return $exit; } @@ -118,61 +86,70 @@ sub custom_usage_calc { return 0; } +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'rg', type => 1, cb_prefix_output => 'prefix_rg_output', message_multiple => 'All raid groups are ok' } + ]; + + $self->{maps_counters}->{rg} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' } ], + closure_custom_calc => $self->can('custom_status_calc'), + output_template => 'Status : %s', output_error_template => 'Status : %s', + output_use => 'status', + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'usage', nlabel => 'raidgroup.space.usage.bytes', set => { + key_values => [ { name => 'display' }, { name => 'total' }, { name => 'used' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub prefix_rg_output { + my ($self, %options) = @_; + + return "Raid Group '" . $options{instance_value}->{display} . "' "; +} + 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 }, - "command:s" => { name => 'command', default => 'show' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => 'raid-groups -csv' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "no-component:s" => { name => 'no_component' }, - "filter-name:s" => { name => 'filter_name' }, - "filter-level:s" => { name => 'filter_level' }, - }); - $self->{no_components} = undef; - - foreach my $key (('rg')) { - foreach (keys %{$maps_counters->{$key}}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); - } - } - + $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 }, + "command:s" => { name => 'command', default => 'show' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => 'raid-groups -csv' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "filter-name:s" => { name => 'filter_name' }, + "filter-level:s" => { name => 'filter_level' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { $self->{option_results}->{remote} = 1; } - - foreach my $key (('rg')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } - $instance_mode = $self; $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { @@ -188,86 +165,19 @@ sub check_options { $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; } - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{rg}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Raid Groups are ok'); - } - - foreach my $id (sort keys %{$self->{rg}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{rg}}) { - my $obj = $maps_counters->{rg}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{rg}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Raid Group '$self->{rg}->{$id}->{display}' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Raid Group '$self->{rg}->{$id}->{display}' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Raid Group '$self->{rg}->{$id}->{display}' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); } sub manage_selection { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - ssh_pipe => 1, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + ssh_pipe => 1, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); #[RAID Group No.],[RAID Group Name],[RAID Level],[Assigned CM],[Status],[Total Capacity(MB)],[Free Capacity(MB)] #1,RAIDGROUP001,RAID1+0,CM#0,Spare in Use,134656,132535 @@ -290,17 +200,26 @@ sub manage_selection { next; } - $self->{rg}->{$raid_num} = { status => $raid_status, total => $raid_total * 1024 * 1024, - used => ($raid_total * 1024 * 1024) - ($raid_free * 1024 * 1024), - display => $raid_name }; + $self->{rg}->{$raid_num} = { + status => $raid_status, total => $raid_total * 1024 * 1024, + used => ($raid_total * 1024 * 1024) - ($raid_free * 1024 * 1024), + display => $raid_name + }; } - + if (scalar(keys %{$self->{rg}}) <= 0) { - $self->{output}->output_add(severity => defined($self->{no_components}) ? $self->{no_components} : 'unknown', - short_msg => 'No components are checked.'); + $self->{output}->add_option_msg(short_msg => "No raid group found."); + $self->{output}->option_exit(); } } +my $thresholds = { + rg => [ + ['Available', 'OK'], + ['Spare in Use', 'WARNING'], + ], +}; + sub get_severity { my ($self, %options) = @_; my $status = 'UNKNOWN'; # default @@ -372,10 +291,6 @@ Set to overload default threshold values (syntax: section,status,regexp) It used before default thresholds (order stays). Example: --threshold-overload='rg,CRITICAL,^(?!(Available|Spare)$)' -=item B<--no-component> - -Set the threshold where no components (Default: 'unknown' returns). - =item B<--filter-name> Filter by name (regexp can be used). diff --git a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm index fef91db88..4a7774eb6 100644 --- a/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm +++ b/centreon-plugins/storage/fujitsu/eternus/dx/ssh/mode/volumestats.pm @@ -20,116 +20,118 @@ package storage::fujitsu::eternus::dx::ssh::mode::volumestats; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; +use centreon::plugins::misc; -my $maps_counters = { - vol => { - '000_read-iops' => { - set => { +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All Volumes are ok' } + ]; + + $self->{maps_counters}->{volume} = [ + { label => 'read-iops', nlabel => 'volume.io.read.usage.iops', set => { key_values => [ { name => 'read_iops' }, { name => 'display' } ], output_template => 'Read IOPS : %d', perfdatas => [ { label => 'read_iops', value => 'read_iops_absolute', template => '%d', unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '001_write-iops' => { - set => { + { label => 'write-iops', nlabel => 'volume.io.write.usage.iops', set => { key_values => [ { name => 'write_iops' }, { name => 'display' } ], output_template => 'Write IOPS : %d', perfdatas => [ { label => 'write_iops', value => 'write_iops_absolute', template => '%d', unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '002_read-traffic' => { - set => { + { label => 'read-traffic', nlabel => 'volume.traffic.read.usage.bitspersecond', set => { key_values => [ { name => 'read_throughput' }, { name => 'display' } ], output_template => 'Read Traffic : %s %s/s', output_change_bytes => 2, perfdatas => [ { label => 'read_throughput', value => 'read_throughput_absolute', template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '003_write-traffic' => { - set => { + { label => 'write-traffic', nlabel => 'volume.traffic.write.usage.bitspersecond', set => { key_values => [ { name => 'write_throughput' }, { name => 'display' } ], output_template => 'Write Traffic : %s %s/s', output_change_bytes => 2, perfdatas => [ { label => 'write_throughput', value => 'write_throughput_absolute', template => '%d', unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '004_read-response-time' => { - set => { + { label => 'read-response-time', nlabel => 'volume.io.read.time.response.milliseconds', set => { key_values => [ { name => 'read_response_time' }, { name => 'display' } ], output_template => 'Read Response Time : %d ms', perfdatas => [ { label => 'read_response_time', value => 'read_response_time_absolute', template => '%d', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '005_write-response-time' => { - set => { + { label => 'write-response-time', nlabel => 'volume.io.write.time.response.milliseconds', set => { key_values => [ { name => 'write_response_time' }, { name => 'display' } ], output_template => 'Write Response Time : %d ms', perfdatas => [ { label => 'write_response_time', value => 'write_response_time_absolute', template => '%d', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '006_read-processing-time' => { - set => { + { label => 'read-processing-time', nlabel => 'volume.io.read.time.processing.milliseconds', set => { key_values => [ { name => 'read_processing_time' }, { name => 'display' } ], output_template => 'Read Processing Time : %d ms', perfdatas => [ { label => 'read_processing_time', value => 'read_processing_time_absolute', template => '%d', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '007_write-processing-time' => { - set => { + { label => 'write-processing-time', nlabel => 'volume.io.write.time.processing.milliseconds', set => { key_values => [ { name => 'write_processing_time' }, { name => 'display' } ], output_template => 'Write Processing Time : %d ms', perfdatas => [ { label => 'write_processing_time', value => 'write_processing_time_absolute', template => '%d', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '008_read-cache-hit-rate' => { - set => { + { label => 'read-cache-hit-rate', nlabel => 'volume.io.read.cache.hits.percentage', set => { key_values => [ { name => 'read_cache_hit_rate' }, { name => 'display' } ], output_template => 'Read Cache Hit Rate : %d %%', perfdatas => [ { label => 'read_cache_hit_rate', value => 'read_cache_hit_rate_absolute', template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - '009_write-cache-hit-rate' => { - set => { + { label => 'write-cache-hit-rate', nlabel => 'volume.io.write.cache.hits.percentage', set => { key_values => [ { name => 'write_cache_hit_rate' }, { name => 'display' } ], output_template => 'Write Cache Hit Rate : %d %%', perfdatas => [ { label => 'write_cache_hit_rate', value => 'write_cache_hit_rate_absolute', template => '%d', unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, ], - }, + } }, - } -}; + ]; +} + +sub prefix_volume_output { + my ($self, %options) = @_; + + return "Volume '" . $options{instance_value}->{display} . "' "; +} sub new { my ($class, %options) = @_; @@ -137,132 +139,41 @@ sub new { 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 }, - "command:s" => { name => 'command', default => 'show' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => ' performance -type host-io' }, - "no-component:s" => { name => 'no_component' }, - "filter-name:s" => { name => 'filter_name' }, - }); - $self->{no_components} = undef; - - foreach my $key (('vol')) { - foreach (keys %{$maps_counters->{$key}}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); - } - } - + $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 }, + "command:s" => { name => 'command', default => 'show' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => ' performance -type host-io' }, + "filter-name:s" => { name => 'filter_name' }, + }); + return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); + $self->SUPER::check_options(%options); if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { $self->{option_results}->{remote} = 1; } - - foreach my $key (('vol')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{vol}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Volumes are ok'); - } - - foreach my $id (sort keys %{$self->{vol}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits = (); - foreach (sort keys %{$maps_counters->{vol}}) { - my $obj = $maps_counters->{vol}->{$_}->{obj}; - $obj->set(instance => $id); - - my ($value_check) = $obj->execute(values => $self->{vol}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(level => 1, extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Volume '$self->{vol}->{$id}->{display}' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Volume '$self->{vol}->{$id}->{display}' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Volume '$self->{vol}->{$id}->{display}' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); } sub manage_selection { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - ssh_pipe => 1, - command => $self->{option_results}->{command}, - command_path => $self->{option_results}->{command_path}, - command_options => $self->{option_results}->{command_options}); + my $stdout = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + ssh_pipe => 1, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); #Volume IOPS(IOPS) Throughput(MB/s) Response Time(msec.) Processing Time(msec.) Cache Hit Rate(%) #No. Name Read / Write Read / Write Read / Write Read / Write Read / Write / Prefetch @@ -270,7 +181,7 @@ sub manage_selection { # 1 VOL001 6621 5192 589 379 17055 12056 10025 10010 41 37 36 # 2 VOL002 7791 6608 613 292 12148 11045 10005 10007 41 37 36 - $self->{vol} = {}; + $self->{volume} = {}; my %template_label = (cache_hit_rate => { labels => ['read', 'write', 'prefetch'] }); my @template_values = (); foreach (split /\n/, $stdout) { @@ -307,14 +218,15 @@ sub manage_selection { $counters{read_throughput} *= 1000 * 1000 * 8 if (defined($counters{read_throughput})); $counters{write_throughput} *= 1000 * 1000 * 8 if (defined($counters{write_throughput})); - $self->{vol}->{$matches[0]} = { display => $matches[1], - %counters - }; + $self->{volume}->{$matches[0]} = { + display => $matches[1], + %counters + }; } - if (scalar(keys %{$self->{vol}}) <= 0) { - $self->{output}->output_add(severity => defined($self->{no_components}) ? $self->{no_components} : 'unknown', - short_msg => 'No components are checked.'); + if (scalar(keys %{$self->{volume}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No volume found."); + $self->{output}->option_exit(); } } @@ -361,10 +273,6 @@ Command path (Default: none). Command options (Default: 'performance -type host-io'). -=item B<--no-component> - -Set the threshold where no components (Default: 'unknown' returns). - =item B<--filter-name> Filter by name (regexp can be used).