[freeside-commits] branch FREESIDE_3_BRANCH updated. c21233541988b9a7bd531824b64f4af93bb10dac

Jonathan Prykop jonathan at 420.am
Thu Jan 21 15:54:34 PST 2016


The branch, FREESIDE_3_BRANCH has been updated
       via  c21233541988b9a7bd531824b64f4af93bb10dac (commit)
       via  89f20354f28d524a68fdb46b59b55ec79b7f08ea (commit)
      from  784cd44e2e7763acdd7ec8cb4f5681037f36cfe0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c21233541988b9a7bd531824b64f4af93bb10dac
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Thu Jan 21 17:35:10 2016 -0600

    RT#39115: View SNMP info on svc_broadband service [bug fixes to previous]

diff --git a/FS/FS/part_export/broadband_snmp_get.pm b/FS/FS/part_export/broadband_snmp_get.pm
index 18ba8ea..1a86612 100644
--- a/FS/FS/part_export/broadband_snmp_get.pm
+++ b/FS/FS/part_export/broadband_snmp_get.pm
@@ -96,18 +96,19 @@ sub snmp_results {
     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' };

commit 89f20354f28d524a68fdb46b59b55ec79b7f08ea
Author: Jonathan Prykop <jonathan at freeside.biz>
Date:   Thu Jan 21 16:42:08 2016 -0600

    RT#39115: View SNMP info on svc_broadband service [timeout fix & multiple value handling]

diff --git a/FS/FS/part_export/broadband_snmp_get.pm b/FS/FS/part_export/broadband_snmp_get.pm
index fafe91a..18ba8ea 100644
--- a/FS/FS/part_export/broadband_snmp_get.pm
+++ b/FS/FS/part_export/broadband_snmp_get.pm
@@ -61,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, [<obj>, <iid>, <val>, <type>]
 
 =cut
 
@@ -78,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,
@@ -92,13 +92,33 @@ 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 $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 ];
+      }
+    } 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);
+    }
+    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;      
diff --git a/httemplate/elements/broadband_snmp_get.html b/httemplate/elements/broadband_snmp_get.html
index d4cc4e4..213bc44 100644
--- a/httemplate/elements/broadband_snmp_get.html
+++ b/httemplate/elements/broadband_snmp_get.html
@@ -22,22 +22,29 @@ function broadband_snmp_get (svcnum) {
       if (objects.length) {
         var table = document.createElement('table');
         for (i = 0; i < objects.length; i++) {
-          var row = document.createElement('tr');
           var obj = objects[i];
           if (obj.error) {
+            var row = document.createElement('tr');
             var cell = document.createElement('td');
             cell.colSpan = '2';
             cell.innerHTML = obj['error'];
             row.appendChild(cell);
+            table.appendChild(row);
           } else {
+            for (j = 0; j < obj['values'].length; j++) {
+              var row = document.createElement('tr');
+              var value = obj['values'][j];
+              var label = (obj['values'].length > 1) ? (value[0] + '.' + value[1]) : obj['label'];
               var cell = document.createElement('td');
-              cell.innerHTML = obj['label'];
+              cell.innerHTML = label;
               row.appendChild(cell);
               cell = document.createElement('td');
-              cell.innerHTML = obj['value'];
+              cell.innerHTML = value[2];
+              cell.style.paddingLeft = '3em';
               row.appendChild(cell);
+              table.appendChild(row);
+            }
           }
-          table.appendChild(row);
         }
         var resultblock = document.getElementById('broadband_snmp_get');
         resultblock.innerHTML = '';

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_export/broadband_snmp_get.pm     |   43 ++++++++++++++++++++-------
 httemplate/elements/broadband_snmp_get.html |   15 +++++++---
 2 files changed, 43 insertions(+), 15 deletions(-)




More information about the freeside-commits mailing list