Skip to content

Commit

Permalink
[REVIEW] - [ZF] Migrate remaining statistics / smokeping controllers -
Browse files Browse the repository at this point in the history
…closes islandbridgenetworks/IXP-Manager#119
  • Loading branch information
yannrobin committed Mar 27, 2018
1 parent 6911eb7 commit 784cb81
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 46 deletions.
10 changes: 5 additions & 5 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ APP_LOG_LEVEL=debug

# MySQL Connection Details
DB_CONNECTION="mysql"
DB_HOST="127.0.0.1"
DB_DATABASE="inex"
DB_USERNAME="inex"
DB_PASSWORD="inex"
DB_HOST="ixpmanager-mysql"
DB_DATABASE="ixpmanager"
DB_USERNAME="ixpmanager"
DB_PASSWORD="ixpmanager"
#######################################################################################
# Identity. Used throughout IXP Manager in various ways.
# This has grown organically and we intend to clean this up in a coming release and
Expand Down Expand Up @@ -95,7 +95,7 @@ MAIL_PORT=1025
### Graphing - see https://ixp-manager.readthedocs.org/en/latest/features/grapher.html

# For Docker MRTG testing, change this to: "mrtg|dummy".
GRAPHER_BACKENDS="smokeping|mrtg|sflow|dummy"
GRAPHER_BACKENDS="dummy"



Expand Down
20 changes: 0 additions & 20 deletions .idea/IXP-Manager.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/Providers/GrapherServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Illuminate\Support\ServiceProvider;

use IXP\Exceptions\Services\Grapher\ConfigurationException;
use IXP\Services\Grapher;
use IXP\Services\Grapher\Renderer\Extensions\Grapher as GrapherRendererExtension;

use Entities\User as UserEntity;
Expand Down Expand Up @@ -91,7 +92,7 @@ public function boot()
/**
* Register the application services.
*
* @return void|\IXP\Services\Grapher
* @return void|Grapher
* @throws
*/
public function register()
Expand All @@ -105,7 +106,7 @@ public function register()

$this->app->singleton(
'IXP\Services\Grapher', function() {
return new \IXP\Services\Grapher;
return new Grapher;
});

$this->commands( $this->commands );
Expand Down
5 changes: 4 additions & 1 deletion app/Services/Grapher/Backend/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
use Entities\IXP;

/**
* Grapher Backend -> Mrtg
* Grapher Backend -> Dummy
*
* @author Barry O'Donovan <[email protected]>
* @category Grapher
Expand Down Expand Up @@ -195,7 +195,10 @@ public function data( Graph $graph ): array {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
public function png( Graph $graph ): string {
return @file_get_contents( $this->resolveFilePath( $graph, 'png' ) );
Expand Down
13 changes: 10 additions & 3 deletions app/Services/Grapher/Backend/Mrtg.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ public static function supports(): array {
* {inheritDoc}
*
* @param Graph $graph
*
* @return array
*
* @throws
*/
public function data( Graph $graph ): array {
Expand All @@ -347,7 +349,9 @@ public function data( Graph $graph ): array {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
public function png( Graph $graph ): string {
Expand Down Expand Up @@ -376,7 +380,9 @@ public function png( Graph $graph ): string {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
public function rrd( Graph $graph ): string {
Expand All @@ -394,7 +400,9 @@ public function rrd( Graph $graph ): string {

/**
* For larger IXPs, allow sharding of directories over 16 possible base directories
*
* @param int $id The customer entity id
*
* @return string shared path -> e.g. 18 -> 18 % 16 = 2 / 00016 -> 2/00016
*/
private function shardMemberDir( int $id ): string {
Expand All @@ -407,7 +415,9 @@ private function shardMemberDir( int $id ): string {
*
* @param Graph $graph
* @param string $type
*
* @return string
*
* @throws
*/
public function resolveFilePath( Graph $graph, string $type ): string {
Expand Down Expand Up @@ -471,7 +481,4 @@ public function resolveFilePath( Graph $graph, string $type ): string {
throw new CannotHandleRequestException("Backend asserted it could process but cannot handle graph of type: {$graph->type()}" );
}
}



}
34 changes: 28 additions & 6 deletions app/Services/Grapher/Backend/Sflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

use IXP\Contracts\Grapher\Backend as GrapherBackendContract;
use IXP\Exceptions\Services\Grapher\CannotHandleRequestException;
use IXP\Services\Grapher\Backend as GrapherBackend;

use IXP\Services\Grapher\Graph;
Expand All @@ -37,7 +38,7 @@
use Log;

/**
* Grapher Backend -> Mrtg
* Grapher Backend -> Sflow
*
* @author Barry O'Donovan <[email protected]>
* @category Grapher
Expand Down Expand Up @@ -92,8 +93,9 @@ public function isMultiFileConfigurationSupported(): bool {
*
* {inheritDoc}
*
* @param IXP $ixp The IXP to generate the config for (multi-IXP mode)
* @param int $config_type The type of configuration to generate
* @param IXP $ixp The IXP to generate the config for (multi-IXP mode)
* @param int $type The type of configuration to generate
*
* @return array
*/
public function generateConfiguration( IXP $ixp, int $type = self::GENERATED_CONFIG_TYPE_MONOLITHIC ): array
Expand Down Expand Up @@ -141,7 +143,10 @@ public static function supports(): array {
* {inheritDoc}
*
* @param \IXP\Services\Grapher\Graph $graph
*
* @return array
*
* @throws
*/
public function data( Graph $graph ): array {
try {
Expand All @@ -159,7 +164,10 @@ public function data( Graph $graph ): array {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
public function png( Graph $graph ): string {
try {
Expand All @@ -177,7 +185,10 @@ public function png( Graph $graph ): string {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
public function rrd( Graph $graph ): string {
try {
Expand Down Expand Up @@ -207,26 +218,31 @@ private function translateCategory( $c ): string {
* For a given graph, return the filename where the appropriate data
* will be found.
*
* @param Graph $graph
* @param Graph $graph
* @param string $type
*
* @return string
*
* @throws
*/
private function resolveFileName( Graph $graph, $type ): string {
$config = config('grapher.backends.sflow');

switch( $graph->classType() ) {
case 'Vlan':
/** @var Graph\Vlan $graph */
return sprintf( "aggregate.%s.%s.vlan%05d.%s",
$graph->protocol(), $this->translateCategory( $graph->category() ),
$graph->vlan()->getNumber(), $type );
break;

case 'VlanInterface':
/** @var Graph\VlanInterface $graph */
return sprintf( "individual.%s.%s.src-%05d.%s",
$graph->protocol(), $this->translateCategory( $graph->category() ),
$graph->vlanInterface()->getId(), $type );
break;

case 'P2p':
/** @var Graph\P2p $graph */
return sprintf( "p2p.%s.%s.src-%05d.dst-%05d.%s",
$graph->protocol(), $this->translateCategory( $graph->category() ),
$graph->svli()->getId(), $graph->dvli()->getId(), $type );
Expand All @@ -242,25 +258,31 @@ private function resolveFileName( Graph $graph, $type ): string {
* will be found.
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
private function resolveFilePath( Graph $graph, $type ): string {
$config = config('grapher.backends.sflow');

switch( $graph->classType() ) {
case 'Vlan':
/** @var Graph\Vlan $graph */
return sprintf( "%s/%s/%s/aggregate/%s", $config['root'],
$graph->protocol(), $this->translateCategory( $graph->category() ),
$this->resolveFileName( $graph, $type ) );
break;

case 'VlanInterface':
/** @var Graph\VlanInterface $graph */
return sprintf( "%s/%s/%s/individual/%s", $config['root'],
$graph->protocol(), $this->translateCategory( $graph->category() ),
$this->resolveFileName( $graph, $type ) );
break;

case 'P2p':
/** @var Graph\P2p $graph */
return sprintf( "%s/%s/%s/p2p/src-%05d/%s", $config['root'],
$graph->protocol(), $this->translateCategory( $graph->category() ),
$graph->svli()->getId(), $this->resolveFileName( $graph, $type ) );
Expand Down
6 changes: 6 additions & 0 deletions app/Services/Grapher/Backend/Smokeping.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public function data( Graph $graph ): array {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
public function png( Graph $graph ): string {
return @file_get_contents( $this->resolveFilePath( $graph ) );
Expand All @@ -148,6 +151,7 @@ public function png( Graph $graph ): string {
* {inheritDoc}
*
* @param Graph $graph
*
* @return string
*/
public function rrd( Graph $graph ): string {
Expand All @@ -160,7 +164,9 @@ public function rrd( Graph $graph ): string {
* will be found.
*
* @param Graph $graph
*
* @return string
*
* @throws
*/
private function resolveFilePath( Graph $graph ): string {
Expand Down
17 changes: 9 additions & 8 deletions app/Services/Grapher/Graph/Smokeping.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class Smokeping extends Graph {
*/
const PERIOD_DEFAULT = self::PERIOD_3HOURS;


/**
* Array of valid periods for drill down graphs
*/
Expand All @@ -92,8 +91,6 @@ class Smokeping extends Graph {
self::PERIOD_1YEAR => "1year"
];



/**
* Set the period we should use
* @param int $v
Expand Down Expand Up @@ -124,11 +121,12 @@ public static function resolvePeriod( $period = null ): string {
return self::PERIODS[ $period ] ?? 'Unknown';
}


/**
* Constructor
* @param Grapher $grapher
* @param VlanInterfaceEntity $vli
*
* @param Grapher $grapher
* @param VlanInterfaceEntity $vli
*
*/
public function __construct( Grapher $grapher, VlanInterfaceEntity $vli ) {
parent::__construct( $grapher );
Expand Down Expand Up @@ -218,13 +216,16 @@ public function getParamsAsArray(): array {
*
* Does a abort(404) if invalid
*
* @param int $vliid The user input value
* @return VlanInterfaceEntity $vli VlanInterface object
* @param int $vliid The user input value
*
* @return VlanInterfaceEntity
*/
public static function processParameterVlanInterface( int $vliid ): VlanInterfaceEntity {
/** @var VlanInterfaceEntity $vli */
if( !$vliid || !( $vli = D2EM::getRepository( VlanInterfaceEntity::class )->find( $vliid ) ) ) {
abort(404);
}

return $vli;
}
}
2 changes: 1 addition & 1 deletion library/IXP/Form/Switch.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function init()
->setAttrib( 'class', 'span3' )
->addFilter( 'StringTrim' )
->addFilter( 'StringToLower' )
->addFilter( new Zend_Filter_PregReplace( [ 'match' => '/[^0-9a-f]*/', 'reaplce' => '' ] ) );
->addFilter( new Zend_Filter_PregReplace( [ 'match' => '/[^0-9a-f]*/', 'replace' => '' ] ) );
$this->addElement( $mgmt_mac_address );


Expand Down

0 comments on commit 784cb81

Please sign in to comment.