Permalink
Browse files

Show connected devices (issue-85) (#90)

* Separate interface tab into its own component

* Add device query to get connected devices. Display data on interfaces tab of device page

* Corrections

* Show all possible IPs for a given MAC. Include IDs and values of each record to avoid additional queries in UI, and to make query more useful if it's ever called via REST

* Avoid duplicate names in list
  • Loading branch information...
cvicente committed Nov 22, 2017
1 parent d183f20 commit 643cf644566bf8b90117ad5566eb698ba29c3076
Showing with 419 additions and 285 deletions.
  1. +26 −274 htdocs/management/device.html
  2. +278 −0 htdocs/management/interfaces.mhtml
  3. +58 −0 lib/Netdot/Model/Device.pm
  4. +57 −11 t/Device.t
@@ -81,11 +81,6 @@
my $fqdn;
my (@arp_caches, @fwt);
my @modules;
my %ifacecolors = (
manual => "cccccc",
removed => "ff8e8e",
);
print '%ARGS is <pre>', Dumper(%ARGS), '</pre><br>' if $DEBUG;
# Check if user can access this section
@@ -672,281 +667,38 @@
% }
<!-- End Basics Section -->
%#######################################################################
%#
%# Interfaces section
%#
%#######################################################################
% my (@headers, @rows, @row, @rowstyles);
%if ( $view eq "Interfaces" || $view eq "All" ){
<script language="javascript">
<!--
/*
* Show only interfaces belonging to selected VLAN
*
*/
function showVlan(){
var name = document.showvlans.showvlan.value;
window.location = "device.html?id=<% $id %>&view=<% $view %>&showvlan="+name;
}
-->
</script>
<%perl>
my $ifs = $o->interfaces_by($ifsort);
#
# Store values in a hash first. Thay way we can quicly verify if
# at least one of the interfaces has that field set to some value
# and decide whether to add that column or not
#
my %intinfo;
foreach my $if ( @$ifs ){
foreach my $field ( qw/jack room_char jack_char description neighbor/ ){
if ( defined($if->$field) ){
$intinfo{$field}{$if->id} = $if->$field;
}
}
}
# Use this var to avoid checking for permissions for each int
my $can_edit = ($manager && $manager->can($user, "edit", $o))? 1 : 0;
### Headers
my @closet_jacks;
(@headers, @rows) = ();
if ( $editints ){
push @headers, '[del]';
}
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=number">Number</a>';
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=name">Name</a>';
if ( ! $editints ){
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=speed">Speed</a>';
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=vlan">VLAN</a>';
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=oper_status">Status</a>';
}
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=monitored">Mon?</a>';
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=snmp">SNMP?</a>';
if ( exists $intinfo{jack} || $editints ){
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=jack">Jack(cable)</a>';
my @closets = $o->room->closets if ( $o->room );
foreach my $cl ( @closets ) {
push @closet_jacks, $cl->horizontalcables;
}
@closet_jacks = sort { $a->get_label cmp $b->get_label } @closet_jacks;
}
if ( exists $intinfo{room_char} || $editints ){
push @headers, 'Room';
}
if ( exists $intinfo{jack_char} || $editints ){
push @headers, 'Jack';
}
if ( exists $intinfo{description} || $editints ){
push @headers, '<a href="device.html?id=' . $id . '&view=' . $view . '&ifsort=descr">Descr.</a>';
}
push @headers, 'Neighbor';
### Actual data
foreach my $if ( @$ifs ){
next if ( !exists $ifvlans{$if}{$showvlan} && $showvlan ne "all" );
my (@row) = ();
if ( $editints ){
push @row, '<input type="checkbox" name="' . "Interface__" . $if->id . "__delete" . '" >';
}
push @row, $ui->form_field(object=>$if, column=>"number", edit=>$editints, htmlExtra=>"style=\"width: 5em;\"",
linkPage=>"interface.html", returnValOnly=>1);
push @row, $ui->form_field(object=>$if, column=>"name", edit=>$editints, htmlExtra=>"style=\"width: 10em;\"",
linkPage=>"interface.html", returnValOnly=>1);
if ( !$editints ){
push @row, $if->speed_pretty;
push @row,
&{sub{
my $ac = "";
if ( exists $ifvlans{$if} ){
if ( (keys %{$ifvlans{$if}} > 3) ) {
my $rc = "<select name=\"vlan_list\" ";
my $sc = "onChange=\"window.open(this.options[this.selectedIndex].value,'_top')\">\n";
my $tc = "<option value=\"$refresh_url\" selected>--Select--</option>\n";
$ac = $rc . $sc . $tc;
foreach my $v ( sort { $a <=> $b } keys %{$ifvlans{$if}} ) {
my $link = "view.html?table=Vlan&id=$vlans{$v}";
$ac .= "<option value=\"$link\">$v</option>\n";
}
$ac .= "</select>\n";
}else{
my @links;
foreach my $v ( keys %{$ifvlans{$if}} ){
push @links, sprintf("<a href=\"view.html?table=Vlan&id=%s\">%s</a>", $vlans{$v}, $v );
}
$ac .= join ', ', @links;
}
$ac;
}
}};
push @row, $ui->form_field(object=>$if, column=>"oper_status", edit=>$editints, returnValOnly=>1);
}
push @row, $ui->form_field(object=>$if, column=>"monitored", edit=>$editints, returnValOnly=>1);
push @row, $ui->form_field(object=>$if, column=>"snmp_managed", edit=>$editints, returnValOnly=>1);
if ( exists $intinfo{jack} || $editints ){
my %args = (object=>$if, column=>"jack", linkPage=>"view.html", edit=>$editints, returnValOnly=>1);
if ( @closet_jacks && (scalar(@closet_jacks) <= $ui->config->get('DEFAULT_SELECTMAX')) ){
$args{defaults} = \@closet_jacks;
}
push @row, $ui->form_field(%args);
}
if ( exists $intinfo{room_char} || $editints ){
push @row, $ui->form_field(object=>$if, column=>"room_char", edit=>$editints, htmlExtra =>"style=\"width: 4em;\"",
returnValOnly=>1);
}
if ( exists $intinfo{jack_char} || $editints ){
push @row, $ui->form_field(object=>$if, column=>"jack_char", edit=>$editints, htmlExtra =>"style=\"width: 7em;\"",
returnValOnly=>1);
}
if ( exists $intinfo{description} || $editints ){
push @row, $ui->form_field(object=>$if, column=>"description", edit=>$editints, returnValOnly=>1);
}
my $ac = "";
if ( exists $intinfo{neighbor}{$if->id} ){
$ac = $ui->form_field(object=>$if, column=>"neighbor", edit=>$editints, linkPage=>1, returnValOnly=>1);
$ac .= "<br>";
}
if ( !$editints && $can_edit ){
# Do not allow user to add neighbors on virtual interfaces
if ( $if->type ne "53" && $if->type ne "propVirtual" ){
$ac .= "<a class=\"hand\" onClick=\"window.open('addneighbor.html?int_id=$if&url=$refresh_url', 'Add Neighbor', 'width=600,height=200')\">[add]</a>";
}
}
push @row, $ac;
push @rows, \@row;
my $doc_status = $if->doc_status;
if ( exists $ifacecolors{$doc_status} ){
push @rowstyles, "background-color: #$ifacecolors{$doc_status};";
}else{
push @rowstyles, "";
}
} #foreach
</%perl>
<!-- Interface Table -->
<div class="container">
<div class="containerheadleft">
Interfaces
</div>
<div class="containerheadright">
% if ( $editints ){
<form name="netdotform" action="device.html" method="POST">
<input type="hidden" name="id" value="<% $id %>">
<input type="hidden" name="view" value="<% $view %>">
<input type="hidden" name="ifsort" value="<% $ifsort %>">
<input type="button" name="cancel_button" value="cancel" onClick="history.go(-1);">
<input type="submit" name="submit" value="save">
% }else{
<form name="showvlans">
VLAN view: <select name="showvlan" onChange="showVlan();">
% if ( $showvlan eq 'all' ){
<option value="all" SELECTED>all</option>
% }else{
<option value="all">all</option>
% }
% foreach my $vid ( sort { $a <=> $b } keys %vlans ){
% if ( $showvlan eq $vid ){
<option value="<% $vid %>" SELECTED><% $vid %></option>
% }else{
<option value="<% $vid %>"><% $vid %></option>
% }
% }
</select>
</form>
Legend:
% foreach my $status ( keys %ifacecolors ){
<span style="background-color: #<% $ifacecolors{$status} %>;"><% $status %></span>
% }
&nbsp;&nbsp;
% if ( $manager && $manager->can($user, "edit", $o) ){
<a href="device.html?id=<% $id %>&view=<% $view %>&ifsort=<% $ifsort %>&editints=1">[edit]</a>
% }
% }
</div>
<div class="containerbody">
<& /generic/data_table.mhtml, field_headers=>\@headers, data=>\@rows, rowstyle=>\@rowstyles &>
</div>
<div class="containerheadright">
% if ( $editints ){
<input type="button" name="cancel_button" value="cancel" onClick="history.go(-1);">
<input type="submit" name="submit" value="save">
% }
</div>
</div>
% if ( ! $editints && ($view eq "Interfaces" || $view eq "All") ){
% if ( $manager && $manager->can($user, 'edit', $o) ){
<div class="container">
<div class="containerheadleft">
Options
</div>
<div class="containerheadright">&nbsp;</div>
<div class="containerbody">
<p>
<form name="add_ints_form" action="device.html" method="POST">
<input type="hidden" name="id" value="<% $id %>">
<input type="hidden" name="view" value="<% $view %>">
Manually
<input type="submit" name="intadd" value="Add">
<input type="text" name="intaddnum" value="1" size="3"> interfaces
</form>
</p>
<p>
<form name="overwrite_form" action="device.html" method="POST">
<input type="hidden" name="id" value="<% $id %>">
<input type="hidden" name="view" value="<% $view %>">
SNMP Updates Overwrite Descriptions:
<select name="overwrite_if_descr">
<option value="" selected>--Select--</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
<input type="submit" name="Set" value="Set">
</form>
</p>
</div>
% }
% }
</div>
% if ($editints){
</form>
% }
% } # if view eq "Interfaces"
#######################################################################
#
# Interfaces section
#
#######################################################################
if ( $view eq "Interfaces" || $view eq "All" ){
$m->comp('/management/interfaces.mhtml',
device=>$o,
ifsort=>$ifsort,
view=>$view,
editints=>$editints,
user=>$user,
ifvlans=>\%ifvlans,
vlans=>\%vlans,
showvlan=>$showvlan,
refresh_url=>$refresh_url,
);
}
<!-- End Interfaces Section -->
#######################################################################
#
# Modules
#
#######################################################################
%#######################################################################
%#
%# Modules
%#
%#######################################################################
my (@headers, @rows, @row);
% if ( $view eq "Modules" || $view eq "All"){
if ( $view eq "Modules" || $view eq "All"){
<%perl>
my %modules;
if ( @modules ){
foreach my $m ( @modules ) {
Oops, something went wrong.

0 comments on commit 643cf64

Please sign in to comment.