diff --git a/lib/App/Netdisco/DB/Result/Device.pm b/lib/App/Netdisco/DB/Result/Device.pm index e3a794d8..7a6e37e0 100644 --- a/lib/App/Netdisco/DB/Result/Device.pm +++ b/lib/App/Netdisco/DB/Result/Device.pm @@ -191,6 +191,15 @@ Returns the row from the community string table, if one exists. __PACKAGE__->might_have( community => 'App::Netdisco::DB::Result::Community', 'ip'); +=head2 throughput + +Returns a sum of speeds on all ports on the device. + +=cut + +__PACKAGE__->has_one( + throughput => 'App::Netdisco::DB::Result::Virtual::DevicePortSpeed', 'ip'); + =head1 ADDITIONAL METHODS =head2 is_pseudo diff --git a/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm b/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm index 0775fdfc..87057264 100644 --- a/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm +++ b/lib/App/Netdisco/DB/Result/Virtual/DeviceLinks.pm @@ -11,10 +11,8 @@ __PACKAGE__->table('device_links'); __PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->view_definition(<add_columns( 'left_descr' => { data_type => 'text', }, - 'speed' => { - data_type => 'text', - }, 'right_ip' => { data_type => 'inet', }, diff --git a/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm b/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm new file mode 100644 index 00000000..5996c828 --- /dev/null +++ b/lib/App/Netdisco/DB/Result/Virtual/DevicePortSpeed.pm @@ -0,0 +1,36 @@ +package App::Netdisco::DB::Result::Virtual::DevicePortSpeed; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); + +__PACKAGE__->table('device_port_speed'); +__PACKAGE__->result_source_instance->is_virtual(1); +__PACKAGE__->result_source_instance->view_definition(<add_columns( + 'total' => { + data_type => 'integer', + }, +); + +__PACKAGE__->belongs_to('device', 'App::Netdisco::DB::Result::Device', + { 'foreign.ip' => 'self.ip' }); + +1; diff --git a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm index 52bb588b..6ed45c0f 100644 --- a/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm +++ b/lib/App/Netdisco/Web/Plugin/Device/Neighbors.pm @@ -64,8 +64,6 @@ ajax '/ajax/data/device/netmappositions' => require_login sub { } }; -# dynamicsize - ajax '/ajax/data/device/netmap' => require_login sub { my $q = param('q'); my $qdev = schema('netdisco')->resultset('Device') @@ -136,7 +134,9 @@ ajax '/ajax/data/device/netmap' => require_login sub { my $devices = schema('netdisco')->resultset('Device')->search({}, { columns => ['ip', 'dns', 'name'], - '+select' => [\'row_number() over()'], '+as' => ['row_number'], + '+select' => [\'row_number() over()', \'floor(log(throughput.total))'], + '+as' => ['row_number', 'log'], + join => 'throughput', }); DEVICE: while (my $device = $devices->next) { @@ -150,11 +150,12 @@ ajax '/ajax/data/device/netmap' => require_login sub { next DEVICE if $mapshow eq 'only' and not $first_hgrp; $id_for{$device->ip} = $device->get_column('row_number'); - (my $name = ($device->dns || lc($device->name) || $device->ip)) =~ s/$domain$//; + (my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//; $v3data{nodes}->{ ($device->get_column('row_number') - 1) } = { ID => $device->ip, - SIZEVALUE => 3000, + SIZEVALUE => (param('dynamicsize') ? + (($device->get_column('log') || 1) * 1000) : 3000), (param('colorgroups') ? (COLORVALUE => ($first_hgrp ? setting('host_group_displaynames')->{$first_hgrp} : 'Other')) : ()), LABEL => $name, diff --git a/share/config.yml b/share/config.yml index a34f6455..4085be9a 100644 --- a/share/config.yml +++ b/share/config.yml @@ -135,6 +135,7 @@ sidebar_defaults: device_netmap: mapshow: { default: neighbors } colorgroups: { default: checked } + dynamicsize: { default: null } report_moduleinventory: fruonly: { default: checked } matchall: { default: checked } diff --git a/share/views/ajax/device/netmap.tt b/share/views/ajax/device/netmap.tt index 31c89220..3ca74055 100644 --- a/share/views/ajax/device/netmap.tt +++ b/share/views/ajax/device/netmap.tt @@ -51,6 +51,8 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m .width( parseInt(jQuery('#netmap_pane').parent().css('width')) ) .height( window.innerHeight - 100 ) .showSelfLinks(true) + .minNodeRadius(6) + .maxNodeRadius(20) .minZoomFactor(0.1) .maxZoomFactor(10) .charge(-550) @@ -133,8 +135,12 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m if ('[% params.mapshow %]' == 'neighbors') { setTimeout(function() { - var node = graph.nodeDataById( graph['nd2']['centernode'] ); - graph.zoomSmooth(node.x, node.y, node.radius * 100); + if ('[% params.dynamicsize %]' == 'on') { + graph.zoomToFit(); + } else { + var node = graph.nodeDataById( graph['nd2']['centernode'] ); + graph.zoomSmooth(node.x, node.y, node.radius * 100); + } }, 1000); } }); diff --git a/share/views/sidebar/device/netmap.tt b/share/views/sidebar/device/netmap.tt index 4a4a8699..e20012a3 100644 --- a/share/views/sidebar/device/netmap.tt +++ b/share/views/sidebar/device/netmap.tt @@ -69,7 +69,7 @@ - + [% IF devgrp_list.size %] @@ -110,8 +110,8 @@