+ Fix a big problem with some equipments (no beginning at 1 index)

This commit is contained in:
Quentin Garnier 2014-01-24 10:54:47 +01:00
parent 65de07553b
commit 65f3507161
5 changed files with 12 additions and 17 deletions

View File

@ -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})) {

View File

@ -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})) {

View File

@ -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})) {

View File

@ -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) {

View File

@ -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;