From ca8e414845e22497ca3e6fd662be82ef6b0ab2ae Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 17 Jun 2016 16:13:08 +0200 Subject: [PATCH] + update emc clariion disk --- centreon/common/emc/navisphere/mode/disk.pm | 385 +++++++------------- 1 file changed, 134 insertions(+), 251 deletions(-) diff --git a/centreon/common/emc/navisphere/mode/disk.pm b/centreon/common/emc/navisphere/mode/disk.pm index d5c7b1fcf..23a215467 100644 --- a/centreon/common/emc/navisphere/mode/disk.pm +++ b/centreon/common/emc/navisphere/mode/disk.pm @@ -20,133 +20,14 @@ package centreon::common::emc::navisphere::mode::disk; -sub get_absolute { - my ($self, %options) = @_; - my $name = $options{instance} . '_' . $options{label}; - my $value; - - $self->{new_datas}->{$name} = $1; - - $self->{old_datas}->{$name} = $self->{statefile_value}->get(name => $name); - return undef if (!defined($self->{old_datas}->{$name})); - - # Reward... put to 0 - if ($self->{old_datas}->{$name} > $self->{new_datas}->{$name}) { - $self->{old_datas}->{$name} = 0; - } - - $value = ($self->{new_datas}->{$name} - $self->{old_datas}->{$name}); - - return ($value, $value); -} - -sub get_bytes_per_seconds { - my ($self, %options) = @_; - my $name = $options{instance} . '_' . $options{label}; - my $value; - - $self->{new_datas}->{$name} = $1; - if (!defined($self->{old_datas}->{last_timestamp})) { - $self->{old_datas}->{last_timestamp} = $self->{statefile_value}->get(name => 'last_timestamp'); - } - $self->{old_datas}->{$name} = $self->{statefile_value}->get(name => $name); - return undef if (!defined($self->{old_datas}->{last_timestamp}) || !defined($self->{old_datas}->{$name})); - - # Reward... put to 0 - if ($self->{old_datas}->{$name} > $self->{new_datas}->{$name}) { - $self->{old_datas}->{$name} = 0; - } - # At least one second - my $delta_time = $self->{new_datas}->{last_timestamp} - $self->{old_datas}->{last_timestamp}; - if ($delta_time <= 0) { - $delta_time = 1; - } - - $value = ($self->{new_datas}->{$name} - $self->{old_datas}->{$name}) / $delta_time; - my ($scale_value, $scale_unit) = $self->{perfdata}->change_bytes(value => $value); - - return ($value, $scale_value . ' ' . $scale_unit); -} - -sub get_utils { - my ($self, %options) = @_; - my $name = $options{instance} . '_' . $options{label}; - my $value; - - $self->{new_datas}->{$name . '_busy'} = $1; - $self->{new_datas}->{$name . '_idle'} = $2; - - $self->{old_datas}->{$name . '_busy'} = $self->{statefile_value}->get(name => $name . '_busy'); - $self->{old_datas}->{$name . '_idle'} = $self->{statefile_value}->get(name => $name . '_idle'); - return undef if (!defined($self->{old_datas}->{$name . '_busy'}) || !defined($self->{old_datas}->{$name . '_idle'})); - - # Reward... put to 0 - if ($self->{old_datas}->{$name . '_busy'} > $self->{new_datas}->{$name . '_busy'}) { - $self->{old_datas}->{$name . '_busy'} = 0; - } - if ($self->{old_datas}->{$name . '_idle'} > $self->{new_datas}->{$name . '_idle'}) { - $self->{old_datas}->{$name . '_idle'} = 0; - } - - my $total_ticks = ($self->{new_datas}->{$name . '_idle'} - $self->{old_datas}->{$name . '_idle'}) + - ($self->{new_datas}->{$name . '_busy'} - $self->{old_datas}->{$name . '_busy'}); - if ($total_ticks <= 0) { - return (0, 0); - } - $value = ($self->{new_datas}->{$name . '_busy'} - $self->{old_datas}->{$name . '_busy'}) * 100 / $total_ticks; - - return ($value, $value); -} - -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::statefile; use centreon::plugins::misc; +use Digest::MD5 qw(md5_hex); -my $maps_counters = { - hard_read_errors => { thresholds => { - warning_hard_read_errors => { label => 'warning-hard-read-errors', exit_value => 'warning' }, - critical_hard_read_errors => { label => 'critical-hard-read-errors', exit_value => 'critical' }, - }, - matching => 'Hard Read Errors:\s+(\d+)', closure => \&get_absolute, - output_msg => 'Hard Read Errors : %d', perfdata => '%s', - unit => '', - }, - hard_write_errors => { thresholds => { - warning_hard_write_errors => { label => 'warning-hard-write-errors', exit_value => 'warning' }, - critical_hard_write_errors => { label => 'critical-hard-write-errors', exit_value => 'critical' }, - }, - matching => 'Hard Write Errors:\s+(\d+)', closure => \&get_absolute, - output_msg => 'Hard Write Errors : %d', perfdata => '%s', - unit => '', - }, - write_io => { thresholds => { - warning_write_io => { label => 'warning-write-io', exit_value => 'warning' }, - critical_write_io => { label => 'critical-write-io', exit_value => 'critical' }, - }, - matching => 'Kbytes Written:\s+(\d+)', closure => \&get_bytes_per_seconds, - output_msg => 'Write I/O : %s', perfdata => '%d', - unit => 'B', - }, - read_io => { thresholds => { - warning_read_io => { label => 'warning-read-io', exit_value => 'warning' }, - critical_read_io => { label => 'critical-read-io', exit_value => 'critical' }, - }, - matching => 'Kbytes Read:\s+(\d+)', closure => \&get_bytes_per_seconds, - output_msg => 'Read I/O : %s', perfdata => '%d', - unit => 'B', - }, - utils => { thresholds => { - warning_utils => { label => 'warning-utils', exit_value => 'warning' }, - critical_utils => { label => 'critical-utils', exit_value => 'critical' }, - }, - matching => 'Busy Ticks:\s+(\d+).*Idle Ticks:\s+(\d+)', closure => \&get_utils, - output_msg => 'Utils : %.2f %%', perfdata => '%.2f', - unit => '%', - }, -}; +my $instance_mode; my @states = ( ['^enabled$' , 'OK'], @@ -168,92 +49,144 @@ my @states = ( ['^.*$' , 'CRITICAL'], ); +sub custom_threshold_output { + my ($self, %options) = @_; + + foreach (@states) { + if ($self->{result_values}->{state} =~ /$_->[0]/) { + return $_->[1]; + } + } + + return 'ok'; +} + +sub custom_state_output { + my ($self, %options) = @_; + + my $msg = sprintf("state is '%s'", $self->{result_values}->{state}); + return $msg; +} + +sub custom_state_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_utils_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disks are OK', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{disk} = [ + { label => 'state', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_state_calc'), + closure_custom_output => $self->can('custom_state_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'hard-read-errors', set => { + key_values => [ { name => 'hard_read_errors', diff => 1 }, { name => 'display' } ], + output_template => 'Hard Read Errors : %d', + perfdatas => [ + { label => 'hard_read_errors', value => 'hard_read_errors_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'hard-write-errors', set => { + key_values => [ { name => 'hard_write_errors', diff => 1 }, { name => 'display' } ], + output_template => 'Hard Write Errors : %d', + perfdatas => [ + { label => 'hard_write_errors', value => 'hard_write_errors_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'read-io', set => { + key_values => [ { name => 'read_io', diff => 1 }, { name => 'display' } ], + output_template => 'Read I/O : %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { label => 'read_io', value => 'read_io_absolute', template => '%s', + min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'write-io', set => { + key_values => [ { name => 'write_io', diff => 1 }, { name => 'display' } ], + output_template => 'Write I/O : %s %s/s', + per_second => 1, output_change_bytes => 1, + perfdatas => [ + { label => 'write_io', value => 'write_io_absolute', template => '%s', + min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'utils', set => { + key_values => [ { name => 'busy_ticks', diff => 1 }, { name => 'idle_ticks', diff => 1 }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_utils_calc'), + output_template => 'Utils : %s %%', output_use => 'utils', + perfdatas => [ + { label => 'utils', value => 'utils', template => '%s', + min => 0, max => 100, unit => '%%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); bless $self, $class; $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "threshold-overload:s@" => { name => 'threshold_overload' }, "filter-raidgroupid:s" => { name => 'filter_raidgroupid', }, "filter-disk:s" => { name => 'filter_disk', }, }); - foreach (keys %{$maps_counters}) { - foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - $options{options}->add_options(arguments => { - $maps_counters->{$_}->{thresholds}->{$name}->{label} . ':s' => { name => $name }, - }); - } - } - - $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; } sub check_options { my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - if (($self->{perfdata}->threshold_validate(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, value => $self->{option_results}->{$name})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong " . $maps_counters->{$_}->{thresholds}->{$name}->{label} . " threshold '" . $self->{option_results}->{$name} . "'."); - $self->{output}->option_exit(); - } - } - } + $self->SUPER::check_options(%options); - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /(.*?)=(.*)/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - - my ($filter, $threshold) = ($1, $2); - if ($self->{output}->is_litteral_status(status => $threshold) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$filter} = $threshold; - } - - $self->{statefile_value}->check_options(%options); + $instance_mode = $self; } -sub get_severity { +sub manage_selection { my ($self, %options) = @_; - my $status = 'unknown'; - foreach my $entry (@states) { - if ($options{value} =~ /${$entry}[0]/i) { - $status = ${$entry}[1]; - foreach my $filter (keys %{$self->{overload_th}}) { - if (${$entry}[0] =~ /$filter/i) { - $status = $self->{overload_th}->{$filter}; - last; - } - } - last; - } - } - - return $status; -} - -sub run { - my ($self, %options) = @_; - my $clariion = $options{custom}; - - my $response = $clariion->execute_command(cmd => 'getdisk -state -bytrd -bytwrt -hw -hr -busyticks -idleticks -rg'); - - my ($total_num_disks, $skip_num_disks) = (0, 0); - $self->{new_datas} = {}; - $self->{statefile_value}->read(statefile => "cache_clariion_" . $clariion->{hostname} . '_' . $self->{mode}); - $self->{new_datas}->{last_timestamp} = time(); + $self->{disk} = {}; + $self->{cache_name} = "cache_clariion_" . $options{custom}->{hostname} . '_' . $options{custom}->{mode} . '_' . + (defined($self->{option_results}->{filter_disk}) ? md5_hex($self->{option_results}->{filter_disk}) : md5_hex('all')); + + my $response = $options{custom}->execute_command(cmd => 'getdisk -state -bytrd -bytwrt -hw -hr -busyticks -idleticks -rg'); #Bus 1 Enclosure 7 Disk 13 #State: Enabled @@ -275,76 +208,31 @@ sub run { if (defined($self->{option_results}->{filter_disk}) && $self->{option_results}->{filter_disk} ne '' && $disk_instance !~ /$self->{option_results}->{filter_disk}/) { $skip_num_disks++; - $self->{output}->output_add(long_msg => "Skipping disk '" . $disk_instance . "': no matching filter disk"); + $self->{output}->output_add(long_msg => "skipping disk '" . $disk_instance . "': no matching filter disk", debug => 1); next; } if (defined($self->{option_results}->{filter_raidgroupid}) && $self->{option_results}->{filter_raidgroupid} ne '' && $values =~ /^Raid Group ID:\s+(\S+)/mi && $1 !~ /$self->{option_results}->{filter_raidgroupid}/) { $skip_num_disks++; - $self->{output}->output_add(long_msg => "Skipping disk '" . $disk_instance . "': no matching filter raid group id"); + $self->{output}->output_add(long_msg => "skipping disk '" . $disk_instance . "': no matching filter raid group id", debug => 1); next; } - $total_num_disks++; - $values =~ /^State:\s+(.*?)(\n|$)/msi; - - my $state = centreon::plugins::misc::trim($1); - my $exit = $self->get_severity(value => $state); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Disk '%s' state is %s", - $disk_instance, $state)); - # Don't check values if in critical/warning - next; + my $datas = {}; + while ($value =~ /^(.*?:)(.*?)\n/msgi) { + $datas->{centreon::plugins::misc:trim(lc($1))} = centreon::plugins::misc:trim($2); } - # Work on values. No check if in 'Hot Spare Ready' or 'Unbound' - next if ($state =~ /^(Hot Spare Ready|Unbound)$/i); - - my ($short_msg, $long_msg) = ('', ''); - my @exits; - foreach (keys %{$maps_counters}) { - next if ($values !~ /$maps_counters->{$_}->{matching}/msi); - my ($value_check, $value_output) = &{$maps_counters->{$_}->{closure}}($self, - instance => $disk_instance, label => $_); - next if (!defined($value_check)); - my ($warning, $critical); - - foreach my $name (keys %{$maps_counters->{$_}->{thresholds}}) { - my $exit2 = $self->{perfdata}->threshold_check(value => $value_check, threshold => [ { label => $maps_counters->{$_}->{thresholds}->{$name}->{label}, 'exit_litteral' => $maps_counters->{$_}->{thresholds}->{$name}->{exit_value} }]); - $long_msg .= ' ' . sprintf($maps_counters->{$_}->{output_msg}, $value_output); - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= ' ' . sprintf($maps_counters->{$_}->{output_msg}, $value_output); - } - push @exits, $exit2; - - $warning = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'warning'); - $critical = $self->{perfdata}->get_perfdata_for_output(label => $maps_counters->{$_}->{thresholds}->{$name}->{label}) if ($maps_counters->{$_}->{thresholds}->{$name}->{exit_value} eq 'critical'); - } - - $self->{output}->perfdata_add(label => $_ . '_' . $disk_instance, unit => $maps_counters->{$_}->{unit}, - value => sprintf($maps_counters->{$_}->{perfdata}, $value_check), - warning => $warning, - critical => $critical, - min => 0); - } - - $self->{output}->output_add(long_msg => "Disk '$disk_instance':$long_msg"); - $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 => "Disk '$disk_instance':$short_msg" - ); - } + $self->{disk}->{$disk_instance} = { + display => $disk_instance, + hard_read_errors => $datas->{'hard read errors'}, + hard_write_errors => $datas->{'hard write errors'}, + read_io => $datas->{'kbytes read'} * 1024, + write_io => $datas->{'kbytes write'} * 1024, + busy_ticks => $datas->{'busy ticks'}, + idle_ticks => $datas->{'idle ticks'}, + }; } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s disks are ok.", - $total_num_disks . '/' . $skip_num_disks) - ); - $self->{statefile_value}->write(data => $self->{new_datas}); - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -367,11 +255,6 @@ Can be: 'read-errors', 'write-errors', 'read-io', 'write-io', 'utils'. Threshold critical. Can be: 'read-errors', 'write-errors', 'read-io', 'write-io', 'utils'. -=item B<--threshold-overload> - -Set to overload default threshold value. -Example: --threshold-overload='(enabled)=critical' - =item B<--filter-disk> Filter Disk (regexp can be used).