working folters and colors for host group and location

This commit is contained in:
Oliver Gorwits
2018-03-19 17:47:22 +00:00
parent bf87615a8a
commit a2ce65c8b8
6 changed files with 39 additions and 30 deletions

View File

@@ -14,8 +14,9 @@ __PACKAGE__->result_source_instance->view_definition(<<ENDSQL
sum( COALESCE(dpp.raw_speed,1) ) as total sum( COALESCE(dpp.raw_speed,1) ) as total
FROM device_port FROM device_port
LEFT OUTER JOIN device_port_properties dpp USING (ip, port) LEFT OUTER JOIN device_port_properties dpp USING (ip, port)
WHERE type = 'ethernetCsmacd' WHERE type !~* '^(53|ieee8023adLag|propVirtual|l2vlan|l3ipvlan|135|136|137)\$'
AND speed LIKE '%bps' AND port !~* 'vlan'
AND name !~* 'vlan'
GROUP BY ip GROUP BY ip
ORDER BY total DESC ORDER BY total DESC
ENDSQL ENDSQL

View File

@@ -41,7 +41,7 @@ hook 'before_template' => sub {
} }
# used in the device search sidebar template to set selected items # used in the device search sidebar template to set selected items
foreach my $opt (qw/hgroup location/) { foreach my $opt (qw/hgroup lgroup/) {
my $p = (ref [] eq ref param($opt) ? param($opt) my $p = (ref [] eq ref param($opt) ? param($opt)
: (param($opt) ? [param($opt)] : [])); : (param($opt) ? [param($opt)] : []));
$tokens->{"${opt}_lkp"} = { map { $_ => 1 } @$p }; $tokens->{"${opt}_lkp"} = { map { $_ => 1 } @$p };
@@ -82,7 +82,7 @@ get '/device' => require_login sub {
params->{'tab'} ||= 'details'; params->{'tab'} ||= 'details';
template 'device', { template 'device', {
display_name => ($others ? $first->ip : ($first->dns || $first->ip)), display_name => ($others ? $first->ip : ($first->dns || $first->ip)),
location_list => [ schema('netdisco')->resultset('Device')->get_distinct_col('location') ], lgroup_list => [ schema('netdisco')->resultset('Device')->get_distinct_col('location') ],
hgroup_list => setting('host_group_displaynames'), hgroup_list => setting('host_group_displaynames'),
device => params->{'tab'}, device => params->{'tab'},
}; };

View File

@@ -109,8 +109,9 @@ ajax '/ajax/data/device/netmap' => require_login sub {
my $vlan = param('vlan'); my $vlan = param('vlan');
undef $vlan if (defined $vlan and $vlan !~ m/^\d+$/); undef $vlan if (defined $vlan and $vlan !~ m/^\d+$/);
my $colorby = (param('colorby') || 'speed');
my $mapshow = (param('mapshow') || 'neighbors'); my $mapshow = (param('mapshow') || 'neighbors');
$mapshow = 'neighbors' if $mapshow !~ m/^(?:all|neighbors|location|hgroup)$/; $mapshow = 'neighbors' if $mapshow !~ m/^(?:all|neighbors)$/;
$mapshow = 'all' unless $qdev->in_storage; $mapshow = 'all' unless $qdev->in_storage;
# list of groups selected by user and passed in param # list of groups selected by user and passed in param
@@ -181,27 +182,30 @@ ajax '/ajax/data/device/netmap' => require_login sub {
next DEVICE if (($mapshow eq 'neighbors') or $vlan) next DEVICE if (($mapshow eq 'neighbors') or $vlan)
and (not $ok_dev{$device->ip}); and (not $ok_dev{$device->ip});
# if in locations mode then filter # if location picked then filter
next DEVICE if $mapshow eq 'location' and ((!defined $device->location) next DEVICE if ((scalar @lgrplist) and ((!defined $device->location)
or (0 == scalar grep {$_ eq $device->location} @lgrplist)); or (0 == scalar grep {$_ eq $device->location} @lgrplist)));
# if in host group mode then use ACLs to filter # if host groups piked then use ACLs to filter
my $first_hgrp = my $first_hgrp =
first { check_acl_only($device, setting('host_groups')->{$_}) } @hgrplist; first { check_acl_only($device, setting('host_groups')->{$_}) } @hgrplist;
next DEVICE if $mapshow eq 'hgroup' and not $first_hgrp; next DEVICE if ((scalar @hgrplist) and (not $first_hgrp));
++$logvals{ $device->get_column('log') || 1 }; ++$logvals{ $device->get_column('log') || 1 };
(my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//; (my $name = lc($device->dns || $device->name || $device->ip)) =~ s/$domain$//;
my %color_lkp = (
speed => (($device->get_column('log') || 1) * 1000),
hgroup => ($first_hgrp ?
setting('host_group_displaynames')->{$first_hgrp} : 'Other'),
lgroup => ($device->location || 'Other'),
);
my $node = { my $node = {
ID => $device->ip, ID => $device->ip,
SIZEVALUE => (param('dynamicsize') ? SIZEVALUE => (param('dynamicsize') ? $color_lkp{speed} : 3000),
(($device->get_column('log') || 1) * 1000) : 3000), ((exists $color_lkp{$colorby}) ? (COLORVALUE => $color_lkp{$colorby}) : ()),
(param('colorgroups') ? LABEL => $name,
(COLORVALUE => ($first_hgrp ? setting('host_group_displaynames')->{$first_hgrp}
: 'Other')) : ()),
LABEL => (param('showips')
? (($name eq $device->ip) ? $name : ($name .' '. $device->ip)) : $name),
ORIG_LABEL => $name, ORIG_LABEL => $name,
INFOSTRING => make_node_infostring($device), INFOSTRING => make_node_infostring($device),
LINK => uri_for('/device', { LINK => uri_for('/device', {
@@ -211,7 +215,7 @@ ajax '/ajax/data/device/netmap' => require_login sub {
})->path_query, })->path_query,
}; };
if ($mapshow ne 'neighbors' and exists $pos_for->{$device->ip}) { if (exists $pos_for->{$device->ip}) {
$node->{'fixed'} = 1; $node->{'fixed'} = 1;
$node->{'x'} = $pos_for->{$device->ip}->{'x'}; $node->{'x'} = $pos_for->{$device->ip}->{'x'};
$node->{'y'} = $pos_for->{$device->ip}->{'y'}; $node->{'y'} = $pos_for->{$device->ip}->{'y'};

View File

@@ -139,8 +139,7 @@ sidebar_defaults:
showips: { default: null } showips: { default: null }
showspeed: { default: null } showspeed: { default: null }
mapshow: { default: neighbors } mapshow: { default: neighbors }
colorby: { default: location } colorby: { default: speed }
colorgroups: { default: checked }
dynamicsize: { default: checked } dynamicsize: { default: checked }
report_moduleinventory: report_moduleinventory:
fruonly: { default: checked } fruonly: { default: checked }

View File

@@ -18,7 +18,7 @@ $.getJSON('[% uri_for('/ajax/data/device/netmap') %]?[% my_query %]', function(m
.dragMode(true) .dragMode(true)
.zoomMode(true) .zoomMode(true)
.pinMode(true) .pinMode(true)
[% '.showLegend(false)' IF NOT params.colorgroups %] [% '.showLegend(false)' UNLESS (params.colorby == 'hgroup' OR params.colorby == 'lgroup') %]
.showLinkDirection(false) .showLinkDirection(false)
.colorScheme('color10') .colorScheme('color10')
//.preventLabelOverlappingOnForceEnd( //.preventLabelOverlappingOnForceEnd(

View File

@@ -86,12 +86,12 @@
[% END %] [% END %]
</select> </select>
[% END %] [% END %]
[% IF location_list.size %] [% IF lgroup_list.size %]
<select class="nd_side-select" size="[% location_list.size > 4 ? 4 : location_list.size %]" <select class="nd_side-select" size="[% lgroup_list.size > 4 ? 4 : lgroup_list.size %]"
multiple="on" name="lgroup" id="nd_lgroup-select" multiple="on" name="lgroup" id="nd_lgroup-select"
rel="tooltip" data-placement="left" data-offset="5" data-title="Device Locations"/> rel="tooltip" data-placement="left" data-offset="5" data-title="Device Locations"/>
[% FOREACH loc IN location_list %] [% FOREACH loc IN lgroup_list %]
<option[% ' selected="selected"' IF location_lkp.exists(loc) %] <option[% ' selected="selected"' IF lgroup_lkp.exists(loc) %]
value="[% loc %]">[% loc | html_entity %]</option> value="[% loc %]">[% loc | html_entity %]</option>
[% END %] [% END %]
</select> </select>
@@ -99,16 +99,21 @@
<div class="clearfix nd_netmap-sidebar"> <div class="clearfix nd_netmap-sidebar">
[% IF hgroup_list.size OR location_list.size %] [% IF hgroup_list.size OR lgroup_list.size %]
<div class="clearfix input-prepend"> <div class="clearfix input-prepend">
<label><span id="nd_colorby-label-text">Color by: </span> <label><span id="nd_colorby-label-text">Color by: </span>
<select id="nd_colorby" name="colorby"> <select id="nd_colorby" name="colorby">
<option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'off' %]>Off</option> <option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'off' %]
value="off">Off</option>
<option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'speed' %]
value="speed">Throughput</option>
[% IF hgroup_list.size %] [% IF hgroup_list.size %]
<option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'hgroup' %]>Group</option> <option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'hgroup' %]
value="hgroup">Host Group</option>
[% END %] [% END %]
[% IF location_list.size %] [% IF lgroup_list.size %]
<option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'location' %]>Location</option> <option[% ' selected="selected"' IF vars.sidebar_defaults.device_netmap.colorby == 'lgroup' %]
value="lgroup">Location</option>
[% END %] [% END %]
</select> </select>
</label> </label>