X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export%2Fbroadband_snmp_get.pm;h=1a8661286c0862430b640ee7ad18ddffbea06900;hb=674cb2d9d7105f4cc2871539b2e9f7088cdaa750;hp=faa51ed0684ad0689bfa14a918c00d12b03c2297;hpb=41dcb76c7a2cd0f020e4eb360944b99dae10c2a4;p=freeside.git diff --git a/FS/FS/part_export/broadband_snmp_get.pm b/FS/FS/part_export/broadband_snmp_get.pm index faa51ed06..1a8661286 100644 --- a/FS/FS/part_export/broadband_snmp_get.pm +++ b/FS/FS/part_export/broadband_snmp_get.pm @@ -30,8 +30,7 @@ tie my %options, 'Tie::IxHash', 'options' => \%options, 'no_machine' => 1, 'notes' => <<'END', -Use this export to configure the community and object ids for displaying realtime -SNMP data from the service IP address when viewing a provisioned service. Timeout is +Display broadband service status information via SNMP. Timeout is per object, and should be small enough for realtime use. This export takes no action during provisioning itself; it is expected that snmp will be separately configured on the service machine. @@ -62,15 +61,15 @@ Configuration for realtime snmp requests to svc_broadband IP address =item snmp_results SVC -Request statistics from SVC ip address. Returns an array of hashes with keys +Request statistics from SVC ip address. Returns an array of hashrefs with keys -objectID +error - error message -label +objectID - dotted decimal fully qualified OID -value +label - leaf textual identifier (e.g., 'sysDescr') -error - error when attempting to load this object +values - arrayref of arrayrefs describing values, [, , , ] =cut @@ -79,7 +78,7 @@ sub snmp_results { my $host = $svc->ip_addr; my $comm = $self->option('snmp_community'); my $vers = $self->option('snmp_version'); - my $time = ($self->option('snmp_timeout') || 1) * 1000; + my $time = ($self->option('snmp_timeout') || 1) * 1000000; my @oids = split("\n", $self->option('snmp_oid')); my %connect = ( 'DestHost' => $host, @@ -93,13 +92,34 @@ sub snmp_results { my @out; foreach my $oid (@oids) { $oid = $SNMP::MIB{$oid}->{'objectID'} if $SNMP::MIB{$oid}; - my $value = $snmp->get($oid.'.0'); - if ($snmp->{'ErrorStr'}) { - push @out, { 'error' => $snmp->{'ErrorStr'} }; + my @values; + if ($vers eq '1') { + my $varbind = new SNMP::Varbind [$oid]; + my $max = 1000; #sanity check + 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, [ @$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 + 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 value ); - $result{'value'} = $value; + my %result = map { $_ => $SNMP::MIB{$oid}{$_} } qw( objectID label ); + # unbless @values, for ease of JSON encoding + $result{'values'} = []; + foreach my $value (@values) { + push @{$result{'values'}}, [ map { $_ } @$value ]; + } push @out, \%result; } return @out;