Subnet Utilization report
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
* [#19] Ask for Reason when changing Port up/down Status, or VLAN
|
* [#19] Ask for Reason when changing Port up/down Status, or VLAN
|
||||||
* [#30] Support for expire_devices, expire_nodes, and expire_nodes_archive
|
* [#30] Support for expire_devices, expire_nodes, and expire_nodes_archive
|
||||||
* Port Log viewable via an icon by device port name (Port Control rights req'd)
|
* Port Log viewable via an icon by device port name (Port Control rights req'd)
|
||||||
|
* [#1] Subnet Utilization report (J. van Ingen)
|
||||||
|
|
||||||
[ENHANCEMENTS]
|
[ENHANCEMENTS]
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package App::Netdisco::DB::Result::Virtual::SubnetUtilization;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
|
use base 'DBIx::Class::Core';
|
||||||
|
|
||||||
|
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
|
||||||
|
|
||||||
|
__PACKAGE__->table('cidr_ips');
|
||||||
|
__PACKAGE__->result_source_instance->is_virtual(1);
|
||||||
|
__PACKAGE__->result_source_instance->view_definition(<<'ENDSQL');
|
||||||
|
SELECT net as subnet,
|
||||||
|
power(2, (32 - masklen(net))) as subnet_size,
|
||||||
|
count(DISTINCT ip) as active,
|
||||||
|
round(100 * count(DISTINCT ip) / power(2, (32 - masklen(net)))) as percent
|
||||||
|
FROM (
|
||||||
|
SELECT DISTINCT net, ni.ip
|
||||||
|
FROM subnets s1, node_ip ni
|
||||||
|
WHERE s1.net <<= ?::cidr
|
||||||
|
AND ni.ip <<= s1.net
|
||||||
|
AND ni.time_last > (now() - ?::interval)
|
||||||
|
AND s1.last_discover > (now() - ?::interval)
|
||||||
|
UNION
|
||||||
|
SELECT DISTINCT net, di.alias as ip
|
||||||
|
FROM subnets s2, device_ip di JOIN device d USING (ip)
|
||||||
|
WHERE s2.net <<= ?::cidr
|
||||||
|
AND di.alias <<= s2.net
|
||||||
|
AND s2.last_discover > (now() - ?::interval)
|
||||||
|
AND d.last_discover > (now() - ?::interval)
|
||||||
|
) as joined
|
||||||
|
GROUP BY net
|
||||||
|
ORDER BY percent ASC
|
||||||
|
ENDSQL
|
||||||
|
|
||||||
|
__PACKAGE__->add_columns(
|
||||||
|
"subnet",
|
||||||
|
{ data_type => "cidr", is_nullable => 0 },
|
||||||
|
"subnet_size",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"active",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
"percent",
|
||||||
|
{ data_type => "integer", is_nullable => 0 },
|
||||||
|
);
|
||||||
|
|
||||||
|
1;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package App::Netdisco::Web::Plugin::Report::SubnetUtilization;
|
||||||
|
|
||||||
|
use Dancer ':syntax';
|
||||||
|
use Dancer::Plugin::DBIC;
|
||||||
|
use Dancer::Plugin::Auth::Extensible;
|
||||||
|
|
||||||
|
use App::Netdisco::Web::Plugin;
|
||||||
|
|
||||||
|
register_report({
|
||||||
|
category => 'IP',
|
||||||
|
tag => 'subnets',
|
||||||
|
label => 'Subnet Utilization',
|
||||||
|
provides_csv => 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
get '/ajax/content/report/subnets' => require_login sub {
|
||||||
|
my $subnet = param('subnet') || '0.0.0.0/32';
|
||||||
|
my $age = param('age') || '7 days';
|
||||||
|
$age = '7 days' unless $age =~ m/^(?:\d+)\s+(?:day|week|month|year)s?$/;
|
||||||
|
|
||||||
|
my $set = schema('netdisco')->resultset('Virtual::SubnetUtilization')
|
||||||
|
->search(undef,{
|
||||||
|
bind => [ $subnet, $age, $age, $subnet, $age, $age ],
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( request->is_ajax ) {
|
||||||
|
template 'ajax/report/subnets.tt', { results => $set, },
|
||||||
|
{ layout => undef };
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header( 'Content-Type' => 'text/comma-separated-values' );
|
||||||
|
template 'ajax/report/subnets_csv.tt', { results => $set },
|
||||||
|
{ layout => undef };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
1;
|
||||||
@@ -50,6 +50,7 @@ web_plugins:
|
|||||||
- Report::PhonesDiscovered
|
- Report::PhonesDiscovered
|
||||||
- Report::SsidInventory
|
- Report::SsidInventory
|
||||||
- Report::VlanInventory
|
- Report::VlanInventory
|
||||||
|
- Report::SubnetUtilization
|
||||||
- AdminTask::JobQueue
|
- AdminTask::JobQueue
|
||||||
- AdminTask::PollerPerformance
|
- AdminTask::PollerPerformance
|
||||||
- AdminTask::SlowDevices
|
- AdminTask::SlowDevices
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[% IF results.count == 0 %]
|
[% IF results.count == 0 %]
|
||||||
<div class="span2 alert alert-info">The aren't enough jobs to report.</div>
|
<div class="span3 alert alert-info">The aren't enough jobs to report.</div>
|
||||||
[% ELSE %]
|
[% ELSE %]
|
||||||
<table class="table table-bordered table-condensed table-hover nd_floatinghead">
|
<table class="table table-bordered table-condensed table-hover nd_floatinghead">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
25
Netdisco/share/views/ajax/report/subnets.tt
Normal file
25
Netdisco/share/views/ajax/report/subnets.tt
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
[% IF results.count == 0 %]
|
||||||
|
<div class="span2 alert alert-info">No matching records.</div>
|
||||||
|
[% ELSE %]
|
||||||
|
<table class="table table-bordered table-condensed table-striped nd_floatinghead">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="nd_center-cell">Subnet</th>
|
||||||
|
<th class="nd_center-cell">Size</th>
|
||||||
|
<th class="nd_center-cell">Number of Active Nodes</th>
|
||||||
|
<th class="nd_center-cell">Percent Utilization</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</tbody>
|
||||||
|
[% FOREACH row IN results.all %]
|
||||||
|
<tr>
|
||||||
|
<td class="nd_center-cell">[% row.subnet | html_entity %]</td>
|
||||||
|
<td class="nd_center-cell">[% row.subnet_size | html_entity %]</td>
|
||||||
|
<td class="nd_center-cell">[% row.active | html_entity %]</td>
|
||||||
|
<td class="nd_center-cell">[% row.percent | html_entity %]</td>
|
||||||
|
</tr>
|
||||||
|
[% END %]
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
[% END %]
|
||||||
|
|
||||||
14
Netdisco/share/views/ajax/report/subnets_csv.tt
Normal file
14
Netdisco/share/views/ajax/report/subnets_csv.tt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[% USE CSV %]
|
||||||
|
[% CSV.dump([ 'Subnet' 'Size' 'Number of Active Nodes' 'Percent Utilization' ]) %]
|
||||||
|
|
||||||
|
[% FOREACH row IN results.all %]
|
||||||
|
[% mylist = [] %]
|
||||||
|
[% mylist.push(row.subnet) %]
|
||||||
|
[% mylist.push(row.subnet_size) %]
|
||||||
|
[% mylist.push(row.active) %]
|
||||||
|
[% mylist.push(row.percent) %]
|
||||||
|
[% CSV.dump(mylist) %]
|
||||||
|
|
||||||
|
[% END %]
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@
|
|||||||
|
|
||||||
// on page load, load the content for the active tab
|
// on page load, load the content for the active tab
|
||||||
[% IF params.tab %]
|
[% IF params.tab %]
|
||||||
[% IF params.tab == 'ipinventory' %]
|
[% IF params.tab == 'ipinventory' OR params.tab == 'subnets' %]
|
||||||
$('#[% params.tab %]_submit').click();
|
$('#[% params.tab %]_submit').click();
|
||||||
[% ELSE %]
|
[% ELSE %]
|
||||||
$('#[% params.tab %]_form').trigger("submit");
|
$('#[% params.tab %]_form').trigger("submit");
|
||||||
|
|||||||
28
Netdisco/share/views/sidebar/report/subnets.tt
Normal file
28
Netdisco/share/views/sidebar/report/subnets.tt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
<div class="clearfix">
|
||||||
|
<input id="nd_ipinventory-subnet" class="nd_sidebar-topinput nd_colored-input"
|
||||||
|
placeholder="CIDR Prefix/Subnet" required="required"
|
||||||
|
name="subnet" value="[% params.subnet | html_entity %]" type="text" autocomplete="off"
|
||||||
|
rel="tooltip" data-placement="left" data-offset="5" data-title="Prefix/Subnet in CIDR Format"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend class="nd_sidebar-legend">
|
||||||
|
<label><em><strong>Options</strong></em></label>
|
||||||
|
</legend>
|
||||||
|
<div class="clearfix">
|
||||||
|
<ul class="unstyled">
|
||||||
|
<li>
|
||||||
|
<em class="muted">Activity Period:</em><br/>
|
||||||
|
<select id="nd_mac-format" class="nd_side-select" name="age">
|
||||||
|
[% FOREACH size IN [ '7 days', '14 days', '30 days', '3 months', '1 year', '5 years' ] %]
|
||||||
|
<option[% ' selected="selected"' IF params.age == size %]>[% size %]</option>
|
||||||
|
[% END %]
|
||||||
|
</select>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<button id="[% report.tag %]_submit" type="submit" class="btn btn-info">
|
||||||
|
<i class="icon-search icon-large pull-left nd_navbar-icon"></i> Search Subnets</button>
|
||||||
Reference in New Issue
Block a user