فهرست منبع

FD3-231 Se agrego routing key al comando stats:crontab:remote

Guillermo Espinoza 7 سال پیش
والد
کامیت
f3b48f4062
1فایلهای تغییر یافته به همراه21 افزوده شده و 10 حذف شده
  1. 21 10
      src/StatsBundle/Command/GenerateRemoteCrontabCommand.php

+ 21 - 10
src/StatsBundle/Command/GenerateRemoteCrontabCommand.php

@@ -21,6 +21,7 @@ class GenerateRemoteCrontabCommand extends ContainerAwareCommand
                 new InputOption('path-app', false, InputOption::VALUE_OPTIONAL, "Path App"),
                 new InputOption('url', false, InputOption::VALUE_OPTIONAL, "Crontab webservice url"),
                 new InputOption('amqp', false, InputOption::VALUE_OPTIONAL, "Execute the commands via amqp", true),
+                new InputOption('routing_key', false, InputOption::VALUE_OPTIONAL, "AMQP Routing key"),
             ))
         ;
     }
@@ -64,10 +65,20 @@ class GenerateRemoteCrontabCommand extends ContainerAwareCommand
 
         $amqp = $input->getOption('amqp');
         $amqpRemote = '';
+        $routing_key = '';
         if ($amqp) {
             $amqpRemote = 'amqp:remote';
+            
+            // Verifico la routing key si se pasa como parametro o variable de entorno
+            // default routing_key = stats
+            $routing_key = $input->getOption('routing_key');
+            if (!$routing_key) {
+                $routing_key = getenv('AMQP_KEY') !== false ? getenv('AMQP_KEY') : 'stats';
+            }
+            $routing_key = "--route={$routing_key}";
         }
-        $content .= "*/5 * * * * {$pathConsole} {$amqpRemote} generate:crontab".PHP_EOL;
+        
+        $content .= "*/5 * * * * {$pathConsole} {$amqpRemote} {$routing_key} generate:crontab".PHP_EOL;
 
         foreach($serverDevices as $server) {
 
@@ -105,19 +116,19 @@ class GenerateRemoteCrontabCommand extends ContainerAwareCommand
                     $params = "--args=--olt-ip:{$deviceIp} --args=--olt-community:{$snmpCommunity} --args=--olt-snmp-library:{$library} --args=--olt-device-id:{$deviceId} --args=--olt-server-id:{$serverId}";
                 }
 
-                $commands[] = "*/{$timeScan} * * * * {$pathConsole} {$amqpRemote} {$mark}:pon:scan {$params}";
-                $commands[] = "*/{$timeScan} * * * * {$pathConsole} {$amqpRemote} {$mark}:onu:scan {$params}";
+                $commands[] = "*/{$timeScan} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:pon:scan {$params}";
+                $commands[] = "*/{$timeScan} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:onu:scan {$params}";
                 
-                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$mark}:onu:stats {$params}";
-                $commands[] = "*/{$timePonStats} * * * * {$pathConsole} {$amqpRemote} {$mark}:pon:stats {$params}";
-                $commands[] = "*/{$timeOltOctets} * * * * {$pathConsole} {$amqpRemote} {$mark}:pon:octets {$params}";
+                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:onu:stats {$params}";
+                $commands[] = "*/{$timePonStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:pon:stats {$params}";
+                $commands[] = "*/{$timeOltOctets} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:pon:octets {$params}";
                 
                 $params = '--olt-device-id={$deviceId} --olt-server-id={$serverId}';
                 if ($amqp) {
                     $params = '--args=--olt-device-id:{$deviceId} --args=--olt-server-id:{$serverId}';
                 }
-                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} stats:onu {$params}";
-                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} stats:ponport {$params}";
+                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:onu {$params}";
+                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:ponport {$params}";
                 
                 $content .= PHP_EOL."# OLT {$oltName} ({$deviceIp})".PHP_EOL;
                 
@@ -133,8 +144,8 @@ class GenerateRemoteCrontabCommand extends ContainerAwareCommand
                 }
                 
                 $commands = array();
-                $commands[] = "*/5 * * * * {$pathConsole} {$amqpRemote} stats:onu:geo {$params}";
-                $commands[] = "*/10 * * * * {$pathConsole} {$amqpRemote} stats:ponport:geo {$params}";
+                $commands[] = "*/5 * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:onu:geo {$params}";
+                $commands[] = "*/10 * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:ponport:geo {$params}";
                 
                 $content .= implode(PHP_EOL, $commands);
                 $content .= PHP_EOL;