diff --git a/centreon-plugins/snmp_standard/mode/diskusage.pm b/centreon-plugins/snmp_standard/mode/diskusage.pm index 850438f35..a4a5824c0 100644 --- a/centreon-plugins/snmp_standard/mode/diskusage.pm +++ b/centreon-plugins/snmp_standard/mode/diskusage.pm @@ -33,11 +33,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total_absolute}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used_absolute}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free_absolute}); - my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used_absolute}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free_absolute} + ); } sub set_counters { @@ -53,10 +54,10 @@ sub set_counters { key_values => [ { name => 'count' } ], output_template => 'Partitions count : %d', perfdatas => [ - { label => 'count', value => 'count_absolute', template => '%d', min => 0 }, - ], + { label => 'count', value => 'count_absolute', template => '%d', min => 0 } + ] } - }, + } ]; $self->{maps_counters}->{diskpath} = [ @@ -65,8 +66,8 @@ sub set_counters { closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'used', value => 'used_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'usage-free', display_ok => 0, nlabel => 'storage.space.free.bytes', set => { @@ -74,8 +75,8 @@ sub set_counters { closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ { label => 'free', value => 'free_absolute', template => '%d', min => 0, max => 'total_absolute', - unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'usage-prct', display_ok => 0, nlabel => 'storage.space.usage.percentage', set => { @@ -83,8 +84,8 @@ sub set_counters { output_template => 'Used : %.2f %%', perfdatas => [ { label => 'used_prct', value => 'prct_used_absolute', template => '%.2f', min => 0, max => 100, - unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' } + ] } }, { label => 'inodes', nlabel => 'storage.inodes.usage.percentage', set => { @@ -92,10 +93,10 @@ sub set_counters { output_template => 'Inodes Used: %s %%', perfdatas => [ { label => 'inodes', value => 'inodes_absolute', template => '%d', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; } @@ -179,16 +180,18 @@ sub manage_selection { my $name_diskpath = $self->get_display_value(id => $_); if (!defined($result->{$oid_dskTotalHigh . "." . $_})) { - $self->{output}->add_option_msg(long_msg => sprintf( - "skipping partition '%s': not found (need to reload the cache)", - $name_diskpath) + $self->{output}->add_option_msg( + long_msg => sprintf( + "skipping partition '%s': not found (need to reload the cache)", + $name_diskpath + ) ); next; } my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_}) * 1024; if ($total_size == 0) { - $self->{output}->output_add(long_msg => sprintf("skipping partition '%s' (total size is 0)", $name_diskpath)); + $self->{output}->output_add(long_msg => sprintf("skipping partition '%s' (total size is 0)", $name_diskpath), debug => 1); next; } my $total_used = (($result->{$oid_dskUsedHigh . "." . $_} << 32) + $result->{$oid_dskUsedLow . "." . $_}) * 1024; @@ -221,7 +224,7 @@ sub manage_selection { } if (scalar(keys %{$self->{diskpath}}) <= 0) { - $self->{output}->add_option_msg(short_msg => "Issue with disk path information (see details)"); + $self->{output}->add_option_msg(short_msg => 'Issue with disk path information (see details)'); $self->{output}->option_exit(); } } @@ -232,9 +235,9 @@ sub reload_cache { $datas->{last_timestamp} = time(); $datas->{all_ids} = []; - + my $oid_dskPath = '.1.3.6.1.4.1.2021.9.1.2'; - + my $result = $self->{snmp}->get_table(oid => $oid_dskPath); foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result})) { next if ($key !~ /\.([0-9]+)$/); @@ -270,11 +273,11 @@ sub get_selection { my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{diskpath})) { # get by ID - my $name = $self->{statefile_cache}->get(name => "dskPath_" . $self->{option_results}->{diskpath}); + my $name = $self->{statefile_cache}->get(name => 'dskPath_' . $self->{option_results}->{diskpath}); push @{$self->{diskpath_id_selected}}, $self->{option_results}->{diskpath} if (defined($name)); } else { foreach my $i (@{$all_ids}) { - my $filter_name = $self->{statefile_cache}->get(name => "dskPath_" . $i); + my $filter_name = $self->{statefile_cache}->get(name => 'dskPath_' . $i); next if (!defined($filter_name)); if (!defined($self->{option_results}->{diskpath})) { @@ -292,7 +295,7 @@ sub get_selection { } } } - + if (scalar(@{$self->{diskpath_id_selected}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No disk path found. Can be: filters, cache file."); $self->{output}->option_exit(); @@ -301,12 +304,13 @@ sub get_selection { sub get_display_value { my ($self, %options) = @_; - my $value = $self->{statefile_cache}->get(name => "dskPath_" . $options{id}); - + my $value = $self->{statefile_cache}->get(name => 'dskPath_' . $options{id}); + if (defined($self->{option_results}->{display_transform_src})) { $self->{option_results}->{display_transform_dst} = '' if (!defined($self->{option_results}->{display_transform_dst})); eval "\$value =~ s{$self->{option_results}->{display_transform_src}}{$self->{option_results}->{display_transform_dst}}"; } + return $value; } diff --git a/centreon-plugins/snmp_standard/mode/storage.pm b/centreon-plugins/snmp_standard/mode/storage.pm index f1269077d..9321f5c29 100644 --- a/centreon-plugins/snmp_standard/mode/storage.pm +++ b/centreon-plugins/snmp_standard/mode/storage.pm @@ -106,7 +106,13 @@ sub custom_usage_threshold { $threshold_value = $self->{result_values}->{prct_used}; $threshold_value = $self->{result_values}->{prct_free} if (defined($self->{instance_mode}->{option_results}->{free})); } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } ]); + $exit = $self->{perfdata}->threshold_check( + value => $threshold_value, + threshold => [ + { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, + { label => 'warning-'. $self->{thlabel}, exit_litteral => 'warning' } + ] + ); return $exit; } @@ -116,11 +122,12 @@ sub custom_usage_output { my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, - $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); - return $msg; + return sprintf( + 'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)', + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free} + ); } sub custom_usage_calc { @@ -160,19 +167,19 @@ sub custom_access_output { sub set_counters { my ($self, %options) = @_; - + $self->{maps_counters_type} = [ { name => 'global', type => 0 }, { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok', skipped_code => { -10 => 1 } }, ]; - + $self->{maps_counters}->{global} = [ { label => 'count', nlabel => 'storage.partitions.count', display_ok => 0, set => { key_values => [ { name => 'count' } ], output_template => 'Partitions count : %d', perfdatas => [ - { label => 'count', value => 'count_absolute', template => '%d', min => 0 }, - ], + { label => 'count', value => 'count_absolute', template => '%d', min => 0 } + ] } }, ]; @@ -183,7 +190,7 @@ sub set_counters { 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'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } }, { label => 'access', nlabel => 'storage.access', set => { @@ -191,22 +198,22 @@ sub set_counters { closure_custom_output => $self->can('custom_access_output'), perfdatas => [ { label => 'access', value => 'access_absolute', template => '%d', min => 1, max => 2, - label_extra_instance => 1, instance_use => 'display_absolute' }, - ], + label_extra_instance => 1, instance_use => 'display_absolute' } + ] } - }, + } ]; } sub prefix_storage_output { my ($self, %options) = @_; - + return "Storage '" . $options{instance_value}->{display} . "' "; } sub default_storage_type { my ($self, %options) = @_; - + return '^(hrStorageFixedDisk|hrStorageNetworkDisk|hrFSBerkeleyFFS)$'; } @@ -214,7 +221,7 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'units:s' => { name => 'units', default => '%' }, 'free' => { name => 'free' }, @@ -235,7 +242,7 @@ sub new { $self->{storage_id_selected} = []; $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - + return $self; } @@ -248,7 +255,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Space reservation argument must be between 0 and 100 percent."); $self->{output}->option_exit(); } - + $self->{option_results}->{oid_filter} = lc($self->{option_results}->{oid_filter}); if ($self->{option_results}->{oid_filter} !~ /^(hrstoragedescr|hrfsmountpoint)$/) { $self->{output}->add_option_msg(short_msg => "Unsupported --oid-filter option."); @@ -265,7 +272,7 @@ sub check_options { sub access_result { my ($self, %options) = @_; - + return {} if (!defined($self->{option_results}->{add_access})); my $oid_hrFSAccess = '.1.3.6.1.2.1.25.3.8.1.5'; @@ -290,20 +297,20 @@ sub access_result { $result->{$_} = $snmp_result->{$oid_hrFSAccess . '.' . $relations->{$_}}; } } - + return $result; } sub manage_selection { my ($self, %options) = @_; - + $self->get_selection(snmp => $options{snmp}); - + my $oid_hrStorageAllocationUnits = '.1.3.6.1.2.1.25.2.3.1.4'; my $oid_hrStorageSize = '.1.3.6.1.2.1.25.2.3.1.5'; my $oid_hrStorageUsed = '.1.3.6.1.2.1.25.2.3.1.6'; my $oid_hrStorageType = '.1.3.6.1.2.1.25.2.3.1.2'; - + $options{snmp}->load( oids => [$oid_hrStorageAllocationUnits, $oid_hrStorageSize, $oid_hrStorageUsed], instances => $self->{storage_id_selected}, @@ -311,7 +318,7 @@ sub manage_selection { ); my $result = $options{snmp}->get_leef(); my $access_result = $self->access_result(snmp => $options{snmp}); - + $self->{global}->{count} = 0; $self->{storage} = {}; foreach (sort @{$self->{storage_id_selected}}) { @@ -330,12 +337,13 @@ sub manage_selection { # in bytes hrStorageAllocationUnits my $total_size = $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_}; if ($total_size <= 0) { - $self->{output}->add_option_msg( + $self->{output}->output_add( long_msg => sprintf( "skipping storage '%s': total size is <= 0 (%s)", $name_storage, int($total_size) - ) + ), + debug => 1 ); next; }