implement dynamic sizing option

This commit is contained in:
Oliver Gorwits
2017-12-24 18:12:04 +00:00
parent e4b19be5d7
commit 938848551e
7 changed files with 63 additions and 15 deletions

View File

@@ -191,6 +191,15 @@ Returns the row from the community string table, if one exists.
__PACKAGE__->might_have( __PACKAGE__->might_have(
community => 'App::Netdisco::DB::Result::Community', 'ip'); 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 =head1 ADDITIONAL METHODS
=head2 is_pseudo =head2 is_pseudo

View File

@@ -11,10 +11,8 @@ __PACKAGE__->table('device_links');
__PACKAGE__->result_source_instance->is_virtual(1); __PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(<<ENDSQL __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
SELECT dp.ip AS left_ip, dp.port AS left_port, dp.name AS left_descr, SELECT dp.ip AS left_ip, dp.port AS left_port, dp.name AS left_descr,
dp.speed AS speed,
dp2.ip AS right_ip, dp2.port AS right_port, dp2.name AS right_descr dp2.ip AS right_ip, dp2.port AS right_port, dp2.name AS right_descr
FROM ( SELECT device_port.ip, device_port.port, device_port.name, FROM ( SELECT device_port.ip, device_port.port, device_port.name,
device_port.speed,
device_port.remote_ip, device_port.remote_port device_port.remote_ip, device_port.remote_port
FROM device_port FROM device_port
WHERE device_port.remote_port IS NOT NULL ) dp WHERE device_port.remote_port IS NOT NULL ) dp
@@ -35,9 +33,6 @@ __PACKAGE__->add_columns(
'left_descr' => { 'left_descr' => {
data_type => 'text', data_type => 'text',
}, },
'speed' => {
data_type => 'text',
},
'right_ip' => { 'right_ip' => {
data_type => 'inet', data_type => 'inet',
}, },

View File

@@ -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(<<ENDSQL
SELECT ip,
sum(btrim(speed, ' MGTbps')::float *
(CASE btrim(speed, ' 0123456789.')
WHEN 'Gbps' THEN 1000
WHEN 'Tbps' THEN 1000000
ELSE 1 END)) AS total
FROM device_port
WHERE type = 'ethernetCsmacd'
AND speed LIKE '%bps'
GROUP BY ip
ORDER BY total DESC
ENDSQL
);
__PACKAGE__->add_columns(
'total' => {
data_type => 'integer',
},
);
__PACKAGE__->belongs_to('device', 'App::Netdisco::DB::Result::Device',
{ 'foreign.ip' => 'self.ip' });
1;

View File

@@ -64,8 +64,6 @@ ajax '/ajax/data/device/netmappositions' => require_login sub {
} }
}; };
# dynamicsize
ajax '/ajax/data/device/netmap' => require_login sub { ajax '/ajax/data/device/netmap' => require_login sub {
my $q = param('q'); my $q = param('q');
my $qdev = schema('netdisco')->resultset('Device') 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({}, { my $devices = schema('netdisco')->resultset('Device')->search({}, {
columns => ['ip', 'dns', 'name'], 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) { 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; next DEVICE if $mapshow eq 'only' and not $first_hgrp;
$id_for{$device->ip} = $device->get_column('row_number'); $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) } = { $v3data{nodes}->{ ($device->get_column('row_number') - 1) } = {
ID => $device->ip, ID => $device->ip,
SIZEVALUE => 3000, SIZEVALUE => (param('dynamicsize') ?
(($device->get_column('log') || 1) * 1000) : 3000),
(param('colorgroups') ? (param('colorgroups') ?
(COLORVALUE => ($first_hgrp ? setting('host_group_displaynames')->{$first_hgrp} : 'Other')) : ()), (COLORVALUE => ($first_hgrp ? setting('host_group_displaynames')->{$first_hgrp} : 'Other')) : ()),
LABEL => $name, LABEL => $name,

View File

@@ -135,6 +135,7 @@ sidebar_defaults:
device_netmap: device_netmap:
mapshow: { default: neighbors } mapshow: { default: neighbors }
colorgroups: { default: checked } colorgroups: { default: checked }
dynamicsize: { default: null }
report_moduleinventory: report_moduleinventory:
fruonly: { default: checked } fruonly: { default: checked }
matchall: { default: checked } matchall: { default: checked }

View File

@@ -51,6 +51,8 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
.width( parseInt(jQuery('#netmap_pane').parent().css('width')) ) .width( parseInt(jQuery('#netmap_pane').parent().css('width')) )
.height( window.innerHeight - 100 ) .height( window.innerHeight - 100 )
.showSelfLinks(true) .showSelfLinks(true)
.minNodeRadius(6)
.maxNodeRadius(20)
.minZoomFactor(0.1) .minZoomFactor(0.1)
.maxZoomFactor(10) .maxZoomFactor(10)
.charge(-550) .charge(-550)
@@ -133,8 +135,12 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
if ('[% params.mapshow %]' == 'neighbors') { if ('[% params.mapshow %]' == 'neighbors') {
setTimeout(function() { setTimeout(function() {
if ('[% params.dynamicsize %]' == 'on') {
graph.zoomToFit();
} else {
var node = graph.nodeDataById( graph['nd2']['centernode'] ); var node = graph.nodeDataById( graph['nd2']['centernode'] );
graph.zoomSmooth(node.x, node.y, node.radius * 100); graph.zoomSmooth(node.x, node.y, node.radius * 100);
}
}, 1000); }, 1000);
} }
}); });

View File

@@ -69,7 +69,7 @@
<input type="radio" name="mapshow" id="nd_mapshow-only" <input type="radio" name="mapshow" id="nd_mapshow-only"
[% 'checked' IF vars.sidebar_defaults.device_netmap.mapshow == 'only' %] [% 'checked' IF vars.sidebar_defaults.device_netmap.mapshow == 'only' %]
[% 'disabled' IF NOT devgrp_list.size %] value="only"> [% 'disabled' IF NOT devgrp_list.size %] value="only">
<label for="nd_mapshow-only">Host Groups[% ':' IF devgrp_list.size %]</label> <label for="nd_mapshow-only">Host Groups</label>
</div> </div>
[% IF devgrp_list.size %] [% IF devgrp_list.size %]
@@ -110,8 +110,8 @@
<div class="clearfix input-prepend"> <div class="clearfix input-prepend">
<label class="add-on"> <label class="add-on">
<input type="checkbox" id="dynamicsize" name="dynamicsize" disabled <input type="checkbox" id="dynamicsize" name="dynamicsize"
[% 'checked="checked"' IF params.dynamicsize %]/> [% 'checked="checked"' IF vars.sidebar_defaults.device_netmap.dynamicsize %]/>
</label> </label>
<label class="nd_checkboxlabel" for="dynamicsize"> <label class="nd_checkboxlabel" for="dynamicsize">
<span class="nd_searchcheckbox uneditable-input">Dynamic Size</span> <span class="nd_searchcheckbox uneditable-input">Dynamic Size</span>