Skip to content

Commit

Permalink
Include port counts by cabinet - closes #585
Browse files Browse the repository at this point in the history
  • Loading branch information
barryo committed Sep 17, 2021
1 parent ac1baf9 commit 625b54c
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 6 deletions.
39 changes: 33 additions & 6 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
use Illuminate\Http\Request;
use Illuminate\View\View;

use IXP\Models\{
Aggregators\VirtualInterfaceAggregator,
use IXP\Models\{Aggregators\VirtualInterfaceAggregator,
Cabinet,
Customer,
Infrastructure,
Location,
Vlan,
VlanInterface
};
VlanInterface};

use IXP\Services\Grapher\Graph;

Expand Down Expand Up @@ -104,6 +103,7 @@ private function dashboardStats( Request $r ): array

foreach( $vis as $vi ) {
$location = $vi[ 'locationname' ];
$cabinet = $vi[ 'cabinetname' ];
$infrastructure = $vi[ 'infrastructure' ];
$custid = $vi[ 'customerid' ];

Expand All @@ -112,13 +112,26 @@ private function dashboardStats( Request $r ): array
'count' => 1,
'id' => $vi[ 'locationid' ],
'name' => $location,
'custs' => [ $custid ]
'custs' => [ $custid ],
'cabinets' => [],
];
} elseif( !in_array( $custid, $custsByLocation[ $location ][ 'custs' ], true ) ){
$custsByLocation[ $location ][ 'count' ]++;
$custsByLocation[ $location ][ 'custs' ][] = $custid;
}

if ( !isset( $custsByLocation[ $location ]['cabinets'][$cabinet] ) ) {
$custsByLocation[ $location ]['cabinets'][ $cabinet ] = [
'count' => 1,
'id' => $vi[ 'cabinetid' ],
'name' => $cabinet,
'custs' => [ $custid ]
];
} elseif( !in_array( $custid, $custsByLocation[ $location ]['cabinets'][$cabinet][ 'custs' ], true ) ){
$custsByLocation[ $location ]['cabinets'][$cabinet][ 'count' ]++;
$custsByLocation[ $location ]['cabinets'][$cabinet][ 'custs' ][] = $custid;
}

if ( !isset($speeds[ $vi[ 'speed' ] ])) {
$speeds[ $vi[ 'speed' ] ] = 1;
} else {
Expand All @@ -137,14 +150,27 @@ private function dashboardStats( Request $r ): array
}

if ( !isset($byLocation[ $location ])) {
$byLocation[ $location ] = [ 'id' => $vi[ 'locationid' ] ];
$byLocation[ $location ] = [
'id' => $vi[ 'locationid' ],
'cabinets' => [],
];
}
if ( !isset($byLocation[ $location ]['cabinets'][ $cabinet ] )) {
$byLocation[ $location ]['cabinets'][ $cabinet ] = [ 'id' => $vi[ 'cabinetid' ] ];
}

if ( !isset($byLocation[ $vi[ 'locationname' ] ][ $vi[ 'speed' ] ])) {
$byLocation[ $location ][ $vi[ 'speed' ] ] = 1;
} else {
$byLocation[ $location ][ $vi[ 'speed' ] ]++;
}

if ( !isset($byLocation[ $location ]['cabinets'][ $cabinet ][ $vi[ 'speed' ] ])) {
$byLocation[ $location ]['cabinets'][ $cabinet ][ $vi[ 'speed' ] ] = 1;
} else {
$byLocation[ $location ]['cabinets'][ $cabinet ][ $vi[ 'speed' ] ]++;
}

if ( !isset( $byLan[ $infrastructure ] ) ) {
$byLan[ $infrastructure ] = [ 'id' => $vi[ 'infrastructureid' ] ];
}
Expand Down Expand Up @@ -189,6 +215,7 @@ private function dashboardStats( Request $r ): array
$cTypes[ 'percentByVlan' ] = VirtualInterfaceAggregator::getPercentageCustomersByVlan();
$cTypes[ 'cached_at' ] = Carbon::now();
$cTypes[ 'infras' ] = Infrastructure::orderBy('name' )->get()->toArray();
$cTypes[ 'cabinets' ] = Cabinet::orderBy('name' )->get()->toArray();
$cTypes[ 'locations' ] = Location::orderBy('name' )->get()->toArray();
$cTypes[ 'vlans' ] = Vlan::publicOnly()->orderBy('number')->get()->keyBy('id')->toArray();

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Aggregators/VirtualInterfaceAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public static function getByLocation(): array
'i.name AS infrastructure',
'l.id AS locationid',
'l.name AS locationname',
'ca.id AS cabinetid',
'ca.name AS cabinetname',
] )
->from( 'virtualinterface AS vi' )
->Join( 'cust AS cust', 'cust.id', 'vi.custid' )
Expand Down
98 changes: 98 additions & 0 deletions resources/views/admin/dashboard.foil.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@
</div>
<?php endif; ?>









<?php if( count( $t->stats[ "usage" ] ) ): ?>
<div class="tw-my-10">
<h4 class="tw-mb-6">
Expand Down Expand Up @@ -432,6 +440,96 @@
</table>
</div>
<?php endif; ?>









<?php if( count( $t->stats[ "byLocation" ] ) ): ?>
<div class="tw-my-12">
<h4 class="tw-mb-6">
<?= ucfirst( config( 'ixp_fe.lang.customer.one' ) ) ?> Ports by Rack
</h4>


<?php foreach( $t->stats[ "byLocation"] as $location => $locationDetails ): ?>

<table class="table table-sm table-hover table-striped tw-shadow-md tw-rounded-sm">
<thead class="tw-text-sm">
<tr>
<th>
<?= $t->ee( $location ) ?>
</th>
<?php foreach( $t->stats[ "speeds" ] as $speed => $count ): ?>
<th class="tw-text-right">
<?= $t->scaleBits( $speed * 1000000, 0 ) ?>
</th>
<?php endforeach; ?>

<th class="tw-text-right">
Total
</th>
</tr>
</thead>

<tbody class="tw-text-sm">
<?php $colcount = 0 ?>
<?php foreach( $locationDetails['cabinets'] as $cabinet => $speed ): ?>
<?php $rowcount = 0 ?>
<tr>
<td>
<?= $t->ee( $cabinet ) ?>
</td>
<?php foreach( $t->stats[ "speeds"] as $s => $c ): ?>
<td class="tw-text-right">
<?php if( isset( $speed[ $s ] ) ): ?>
<?= $speed[ $s ] ?>
<?php $rowcount += $speed[ $s ] ?>
<?php else: ?>
0
<?php endif; ?>
</td>
<?php endforeach; ?>
<td class="tw-text-right">
<b>
<?= $rowcount ?>
</b>
</td>
</tr>
<?php $colcount = $rowcount + $colcount ?>
<?php endforeach; ?>
<tr>
<td>
<b>Totals</b>
</td>
<?php foreach( $t->stats[ "speeds"] as $s => $c ): ?>
<td class="tw-text-right">
<a href="<?= route( "switch@configuration", [ "location" => $locationDetails[ 'id' ], "speed" => $s ] ) ?>">
<?= $locationDetails[$s] ?? 0 ?>
</a>
</td>
<?php endforeach; ?>
<td class="tw-text-right">
<b>
<?= $colcount ?>
</b>
</td>
</tr>
</tbody>
</table>
<?php endforeach; ?>
</div>
<?php endif; ?>






</div>

<div class="col-12 col-xl-6">
Expand Down

0 comments on commit 625b54c

Please sign in to comment.