X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fbroadband_snmp_get.pm;h=35dcd31541e7f24c25cda8b5f0592737d3db6e44;hb=1a320aa8f679a355bd3678ccceb5d7ecf7b0aeba;hp=18ba8ea558a340b84465a1c5bab41aa87815dd05;hpb=e877b3248acbff4fa9fb5606e878175577c332d3;p=freeside.git diff --git a/FS/FS/part_export/broadband_snmp_get.pm b/FS/FS/part_export/broadband_snmp_get.pm index 18ba8ea55..35dcd3154 100644 --- a/FS/FS/part_export/broadband_snmp_get.pm +++ b/FS/FS/part_export/broadband_snmp_get.pm @@ -21,6 +21,7 @@ tie my %options, 'Tie::IxHash', 'snmp_community' => { 'label'=>'Community', 'default'=>'public' }, 'snmp_timeout' => { label=>'Timeout (seconds)', 'default'=>1 }, 'snmp_oid' => { label=>'Object ID', multiple=>1 }, + 'snmp_oid_name' => { label=>'Object Name', multiple=>1 }, ; %info = ( @@ -80,6 +81,7 @@ sub snmp_results { my $vers = $self->option('snmp_version'); my $time = ($self->option('snmp_timeout') || 1) * 1000000; my @oids = split("\n", $self->option('snmp_oid')); + my @oidnames = split("\n", $self->option('snmp_oid_name')); my %connect = ( 'DestHost' => $host, 'Community' => $comm, @@ -90,30 +92,34 @@ sub snmp_results { return { 'error' => 'Error creating SNMP session' } unless $snmp; return { 'error' => $snmp->{'ErrorStr'} } if $snmp->{'ErrorStr'}; my @out; - foreach my $oid (@oids) { + for (my $i=0; $i <= $#oids; $i++) { + my $oid = $oids[$i]; + my $oidname = $oidnames[$i]; $oid = $SNMP::MIB{$oid}->{'objectID'} if $SNMP::MIB{$oid}; my @values; if ($vers eq '1') { my $varbind = new SNMP::Varbind [$oid]; my $max = 1000; #sanity check - while ($max > 0 and $snmp->getnext($varbind)) { + while ($max > 0 and defined($snmp->getnext($varbind))) { last if $snmp->{'ErrorStr'}; last unless $SNMP::MIB{$varbind->[0]}; # does this happen? my $nextoid = $SNMP::MIB{$varbind->[0]}->{'objectID'}; last unless $nextoid =~ /^$oid/; $max--; - push @values, new SNMP::Varbind [ @$varbind ]; + push @values, [ @$varbind ]; } } else { # not clear on what max-repeaters (25) does, plucked value from example code # but based on testing, it isn't capping number of returned values - @values = $snmp->bulkwalk(0,25,$oid); + my ($values) = $snmp->bulkwalk(0,25,$oid); + @values = @$values if $values; } if ($snmp->{'ErrorStr'} || !@values) { push @out, { 'error' => $snmp->{'ErrorStr'} || 'No values retrieved' }; next; } my %result = map { $_ => $SNMP::MIB{$oid}{$_} } qw( objectID label ); + $result{'name'} = $oidname; # unbless @values, for ease of JSON encoding $result{'values'} = []; foreach my $value (@values) {