diff --git a/centreon-plugins/snmp_standard/mode/diskio.pm b/centreon-plugins/snmp_standard/mode/diskio.pm index 713d0047e..aff850b5c 100644 --- a/centreon-plugins/snmp_standard/mode/diskio.pm +++ b/centreon-plugins/snmp_standard/mode/diskio.pm @@ -207,14 +207,14 @@ sub run { sub reload_cache { my ($self) = @_; my $datas = {}; + $datas->{all_ids} = []; my $oid_diskIODevice = '.1.3.6.1.4.1.2021.13.15.1.1.2'; my $result = $self->{snmp}->get_table(oid => $oid_diskIODevice); - my $last_num = 0; foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; $datas->{"device_" . $1} = $result->{$key}; - $last_num = $1; } if (scalar(keys %$datas) <= 0) { @@ -222,7 +222,6 @@ sub reload_cache { $self->{output}->option_exit(); } - $datas->{total_device} = $last_num; $self->{statefile_cache}->write(data => $datas); } @@ -243,7 +242,7 @@ sub manage_selection { $self->{statefile_cache}->read(); } - my $total_device = $self->{statefile_cache}->get(name => 'total_device'); + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{device})) { # get by ID push @{$self->{device_id_selected}}, $self->{option_results}->{device}; @@ -253,7 +252,7 @@ sub manage_selection { $self->{output}->option_exit(); } } else { - for (my $i = 0; $i <= $total_device; $i++) { + foreach my $i (@{$all_ids}) { my $filter_name = $self->{statefile_cache}->get(name => "device_" . $i); next if (!defined($filter_name)); if (!defined($self->{option_results}->{device})) { diff --git a/centreon-plugins/snmp_standard/mode/inodes.pm b/centreon-plugins/snmp_standard/mode/inodes.pm index a02ed2066..7043a9ea4 100644 --- a/centreon-plugins/snmp_standard/mode/inodes.pm +++ b/centreon-plugins/snmp_standard/mode/inodes.pm @@ -139,11 +139,12 @@ sub reload_cache { my $datas = {}; my $result = $self->{snmp}->get_table(oid => $oid_dskPath); + $datas->{all_ids} = []; my $last_num = 0; foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; $datas->{'dskPath_' . $1} = $self->{output}->to_utf8($result->{$key}); - $last_num = $1; } if (scalar(keys %$datas) <= 0) { @@ -151,7 +152,6 @@ sub reload_cache { $self->{output}->option_exit(); } - $datas->{total_diskpath} = $last_num; $self->{statefile_cache}->write(data => $datas); } @@ -172,7 +172,7 @@ sub manage_selection { $self->{statefile_cache}->read(); } - my $total_storage = $self->{statefile_cache}->get(name => 'total_diskpath'); + 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 push @{$self->{diskpath_id_selected}}, $self->{option_results}->{diskpath}; @@ -182,7 +182,7 @@ sub manage_selection { $self->{output}->option_exit(); } } else { - for (my $i = 0; $i <= $total_storage; $i++) { + foreach my $i (@{$all_ids}) { my $filter_name = $self->{statefile_cache}->get(name => 'dskPath_' . $i); next if (!defined($filter_name)); if (!defined($self->{option_results}->{diskpath})) { diff --git a/centreon-plugins/snmp_standard/mode/packeterrors.pm b/centreon-plugins/snmp_standard/mode/packeterrors.pm index c5091985d..eb777926c 100644 --- a/centreon-plugins/snmp_standard/mode/packeterrors.pm +++ b/centreon-plugins/snmp_standard/mode/packeterrors.pm @@ -356,12 +356,12 @@ sub reload_cache { $datas->{oid_filter} = $self->{option_results}->{oid_filter}; $datas->{oid_display} = $self->{option_results}->{oid_display}; + $datas->{all_ids} = []; my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}}); - my $last_num = 0; foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { next if ($key !~ /\.([0-9]+)$/); + push @{$datas->{all_ids}}, $1; $datas->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - $last_num = $1; } if (scalar(keys %$datas) <= 0) { @@ -377,7 +377,6 @@ sub reload_cache { } } - $datas->{total_interface} = $last_num; $self->{statefile_cache}->write(data => $datas); } @@ -401,7 +400,7 @@ sub manage_selection { $self->{statefile_cache}->read(); } - my $total_interface = $self->{statefile_cache}->get(name => 'total_interface'); + my $all_ids = $self->{statefile_cache}->get(name => 'all_ids'); if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) { # get by ID push @{$self->{interface_id_selected}}, $self->{option_results}->{interface}; @@ -411,7 +410,7 @@ sub manage_selection { $self->{output}->option_exit(); } } else { - for (my $i = 0; $i <= $total_interface; $i++) { + foreach my $i (@{$all_ids}) { my $filter_name = $self->{statefile_cache}->get(name => $self->{option_results}->{oid_filter} . "_" . $i); next if (!defined($filter_name)); if (!defined($self->{option_results}->{interface})) { diff --git a/centreon-plugins/snmp_standard/mode/storage.pm b/centreon-plugins/snmp_standard/mode/storage.pm index 8606367c9..91715b708 100644 --- a/centreon-plugins/snmp_standard/mode/storage.pm +++ b/centreon-plugins/snmp_standard/mode/storage.pm @@ -253,12 +253,10 @@ sub reload_cache { $datas->{oid_display} = $self->{option_results}->{oid_display}; $datas->{all_ids} = []; my $result = $self->{snmp}->get_table(oid => $oids_hrStorageTable{$self->{option_results}->{oid_filter}}); - my $last_num = 0; foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { next if ($key !~ /\.([0-9]+)$/); push @{$datas->{all_ids}}, $1; $datas->{$self->{option_results}->{oid_filter} . "_" . $1} = $self->{output}->to_utf8($result->{$key}); - $last_num = $1; } if (scalar(keys %$datas) <= 0) { diff --git a/centreon-plugins/snmp_standard/mode/traffic.pm b/centreon-plugins/snmp_standard/mode/traffic.pm index 3dd63741c..7e1b1462b 100644 --- a/centreon-plugins/snmp_standard/mode/traffic.pm +++ b/centreon-plugins/snmp_standard/mode/traffic.pm @@ -301,7 +301,6 @@ sub reload_cache { $datas->{oid_display} = $self->{option_results}->{oid_display}; $datas->{all_ids} = []; my $result = $self->{snmp}->get_table(oid => $oids_iftable{$self->{option_results}->{oid_filter}}); - my $last_num = 0; foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { next if ($key !~ /\.([0-9]+)$/); push @{$datas->{all_ids}}, $1;