RT#39115 - added a optional display name for oid
authorChristopher Burger <burgerc@freeside.biz>
Tue, 10 Apr 2018 13:18:29 +0000 (09:18 -0400)
committerChristopher Burger <burgerc@freeside.biz>
Tue, 10 Apr 2018 13:18:29 +0000 (09:18 -0400)
FS/FS/part_export/broadband_snmp_get.pm
httemplate/edit/elements/part_export/broadband_snmp_get.html
httemplate/elements/broadband_snmp_get.html

index 1a86612..35dcd31 100644 (file)
@@ -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,7 +92,9 @@ 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') {
@@ -115,6 +119,7 @@ sub snmp_results {
       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) {
index faf179a..a426e61 100644 (file)
@@ -45,20 +45,23 @@ function receive_mib_get(obj, rownum) {
 </script>
 
 <table bgcolor="#cccccc" border=0 cellspacing=3>
-<TR><TH>Object ID</TH></TR>
+<TR><TH>Object Name</TH><TH>Object ID</TH></TR>
 <TR id="broadband_snmp_get_template">
   <TD>
+    <INPUT NAME="oid_name" ID="oid_name" SIZE="25">
+  </TD>
+  <TD>
     <INPUT NAME="oid" ID="oid" SIZE="54">
     <INPUT TYPE="button" VALUE="..." ID="openselector" onclick="open_select_mib_get(this)">
   </TD>
 </TR>
 <& /elements/auto-table.html,
   template_row  => 'broadband_snmp_get_template',
-  fieldorder    => ['oid'],
+  fieldorder    => ['oid_name','oid'],
   data          => \@data,
   table         => 'snmp',
 &>
-<INPUT TYPE="hidden" NAME="multi_options" VALUE="snmp_oid">
+<INPUT TYPE="hidden" NAME="multi_options" VALUE="snmp_oid,snmp_oid_name">
 <& foot.html, %opt &>
 <%init>
 my %opt = @_;
@@ -73,11 +76,13 @@ foreach my $field ( qw(snmp_version snmp_community snmp_timeout) ) {
 }
 
 my @oids    = split("\n", $part_export->option('snmp_oid'));
+my @oid_names    = split("\n", $part_export->option('snmp_oid_name'));
 
 my @data;
 while (@oids) {
   my @thisrow = (shift(@oids));
-  push @data, \@thisrow if grep length($_), @thisrow;
+  my $name = shift(@oid_names);
+  push @data, [$name, \@thisrow] if grep length($_), @thisrow;
 }
 
 my $popup_name = 'popup-'.time."-$$-".rand() * 2**32;
index 213bc44..1164504 100644 (file)
@@ -26,7 +26,7 @@ function broadband_snmp_get (svcnum) {
           if (obj.error) {
             var row = document.createElement('tr');
             var cell = document.createElement('td');
-            cell.colSpan = '2';
+            cell.colSpan = '3';
             cell.innerHTML = obj['error'];
             row.appendChild(cell);
             table.appendChild(row);
@@ -36,6 +36,9 @@ function broadband_snmp_get (svcnum) {
               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['name'];
+              row.appendChild(cell);
+              cell = document.createElement('td');
               cell.innerHTML = label;
               row.appendChild(cell);
               cell = document.createElement('td');