From 784cb817a5cbba32aeaccfe67585d565078f2b98 Mon Sep 17 00:00:00 2001 From: Yann Robin Date: Tue, 27 Mar 2018 16:58:48 +0100 Subject: [PATCH] [REVIEW] - [ZF] Migrate remaining statistics / smokeping controllers - closes islandbridgenetworks/IXP-Manager#119 --- .env.docker | 10 +++---- .idea/IXP-Manager.iml | 20 ------------- .idea/modules.xml | 1 + app/Providers/GrapherServiceProvider.php | 5 ++-- app/Services/Grapher/Backend/Dummy.php | 5 +++- app/Services/Grapher/Backend/Mrtg.php | 13 +++++++-- app/Services/Grapher/Backend/Sflow.php | 34 ++++++++++++++++++---- app/Services/Grapher/Backend/Smokeping.php | 6 ++++ app/Services/Grapher/Graph/Smokeping.php | 17 ++++++----- library/IXP/Form/Switch.php | 2 +- 10 files changed, 67 insertions(+), 46 deletions(-) diff --git a/.env.docker b/.env.docker index e56b6f00f..b80f5d189 100644 --- a/.env.docker +++ b/.env.docker @@ -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 @@ -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" diff --git a/.idea/IXP-Manager.iml b/.idea/IXP-Manager.iml index 025767a7c..c956989b2 100644 --- a/.idea/IXP-Manager.iml +++ b/.idea/IXP-Manager.iml @@ -4,25 +4,5 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 39f0eb235..2a47dee85 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/app/Providers/GrapherServiceProvider.php b/app/Providers/GrapherServiceProvider.php index 3304ce529..794a427e5 100644 --- a/app/Providers/GrapherServiceProvider.php +++ b/app/Providers/GrapherServiceProvider.php @@ -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; @@ -91,7 +92,7 @@ public function boot() /** * Register the application services. * - * @return void|\IXP\Services\Grapher + * @return void|Grapher * @throws */ public function register() @@ -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 ); diff --git a/app/Services/Grapher/Backend/Dummy.php b/app/Services/Grapher/Backend/Dummy.php index 1558a70c7..02d104999 100644 --- a/app/Services/Grapher/Backend/Dummy.php +++ b/app/Services/Grapher/Backend/Dummy.php @@ -32,7 +32,7 @@ use Entities\IXP; /** - * Grapher Backend -> Mrtg + * Grapher Backend -> Dummy * * @author Barry O'Donovan * @category Grapher @@ -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' ) ); diff --git a/app/Services/Grapher/Backend/Mrtg.php b/app/Services/Grapher/Backend/Mrtg.php index 42c52df9d..c14c22a39 100644 --- a/app/Services/Grapher/Backend/Mrtg.php +++ b/app/Services/Grapher/Backend/Mrtg.php @@ -323,7 +323,9 @@ public static function supports(): array { * {inheritDoc} * * @param Graph $graph + * * @return array + * * @throws */ public function data( Graph $graph ): array { @@ -347,7 +349,9 @@ public function data( Graph $graph ): array { * {inheritDoc} * * @param Graph $graph + * * @return string + * * @throws */ public function png( Graph $graph ): string { @@ -376,7 +380,9 @@ public function png( Graph $graph ): string { * {inheritDoc} * * @param Graph $graph + * * @return string + * * @throws */ public function rrd( Graph $graph ): string { @@ -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 { @@ -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 { @@ -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()}" ); } } - - - } diff --git a/app/Services/Grapher/Backend/Sflow.php b/app/Services/Grapher/Backend/Sflow.php index 7647fb149..ba12bd0be 100644 --- a/app/Services/Grapher/Backend/Sflow.php +++ b/app/Services/Grapher/Backend/Sflow.php @@ -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; @@ -37,7 +38,7 @@ use Log; /** - * Grapher Backend -> Mrtg + * Grapher Backend -> Sflow * * @author Barry O'Donovan * @category Grapher @@ -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 @@ -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 { @@ -159,7 +164,10 @@ public function data( Graph $graph ): array { * {inheritDoc} * * @param Graph $graph + * * @return string + * + * @throws */ public function png( Graph $graph ): string { try { @@ -177,7 +185,10 @@ public function png( Graph $graph ): string { * {inheritDoc} * * @param Graph $graph + * * @return string + * + * @throws */ public function rrd( Graph $graph ): string { try { @@ -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 ); @@ -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 ) ); diff --git a/app/Services/Grapher/Backend/Smokeping.php b/app/Services/Grapher/Backend/Smokeping.php index 94b8e503d..76e775d4b 100644 --- a/app/Services/Grapher/Backend/Smokeping.php +++ b/app/Services/Grapher/Backend/Smokeping.php @@ -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 ) ); @@ -148,6 +151,7 @@ public function png( Graph $graph ): string { * {inheritDoc} * * @param Graph $graph + * * @return string */ public function rrd( Graph $graph ): string { @@ -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 { diff --git a/app/Services/Grapher/Graph/Smokeping.php b/app/Services/Grapher/Graph/Smokeping.php index e4d59e50b..12013485d 100644 --- a/app/Services/Grapher/Graph/Smokeping.php +++ b/app/Services/Grapher/Graph/Smokeping.php @@ -81,7 +81,6 @@ class Smokeping extends Graph { */ const PERIOD_DEFAULT = self::PERIOD_3HOURS; - /** * Array of valid periods for drill down graphs */ @@ -92,8 +91,6 @@ class Smokeping extends Graph { self::PERIOD_1YEAR => "1year" ]; - - /** * Set the period we should use * @param int $v @@ -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 ); @@ -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; } } diff --git a/library/IXP/Form/Switch.php b/library/IXP/Form/Switch.php index 42ac6dc56..913fb24ee 100644 --- a/library/IXP/Form/Switch.php +++ b/library/IXP/Form/Switch.php @@ -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 );