ソースを参照

Actualización de los comandos.

Maximiliano Schvindt 7 年 前
コミット
c60d8aa83e

+ 0 - 187
Command/BaseCommand.php

@@ -1,187 +0,0 @@
-<?php
-
-namespace HuaweiBundle\Command;
-
-use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
-use Symfony\Component\Console\Input\InputOption;
-use Symfony\Component\Console\Input\InputInterface;
-use Symfony\Component\Console\Output\OutputInterface;
-
-abstract class BaseCommand extends ContainerAwareCommand
-{
-    /**
-     * @var CollectorInterface
-     */
-    protected $collector;
-
-    /**
-     * @var string
-     */
-    protected $pathLock = "/var/run/flowdat3/stats";
-
-    protected function execute(InputInterface $input, OutputInterface $output)
-    {
-        $this->output = $output;
-        $this->setCollector();
-        
-        return;
-    }
-
-    protected function setCollector()
-    {
-        $this->collector = $this->getContainer()->get("redis");
-    }
-    
-    /**
-     * @param string $key
-     * @return array
-     */
-    protected function getData($key, $output = false)
-    {   
-        return $this->collector->get($key, $output);
-    }
-    
-    /**
-     * @param string $key
-     * @param array $data
-     */
-    protected function setData($key, $data, $output = false)
-    {
-        $this->collector->set($key, $data, $output);
-    }
-    
-    /**
-     * @param string $key
-     * @param string $data
-     */
-    protected function getString($key, $output = false)
-    {
-        return $this->collector->getString($key, $output);
-    }
-
-    /**
-     * @param array $queries
-     * @return 
-     */
-    protected function executeQueries($queries)
-    {
-        $result = null;
-        $conn = $this->getContainer()->get('database_connection');
-        foreach ($queries as $query)
-        {
-            $result = $conn->query($query);
-        }
-        $conn->close();
-        
-        return $result;
-    }
-    
-    /**
-     * 
-     * @param string $flag
-     * @return boolean
-     * 
-     * Description: Retorna true si existe el bloqueo. False si no existe bloqueo o no puede determinar la existencia.
-     */
-    
-    protected function lock($flag) {
-
-        $mypid = getmypid();
-        $file = $this->pathLock. "/" . $flag;
-        
-        if (!is_dir($this->pathLock)) {mkdir($this->pathLock, 0777, true);}
-        
-        if (is_null($flag)) return false;
-
-        if (file_exists($file)) {
-
-            $handle = fopen($file, "r");
-            $contenido = fread($handle, filesize($file));
-            fclose($handle);
-            $data = explode("\n", $contenido);
-            
-            if(count($data) == 2) {
-                if (isset($data[0]) && isset($data[1])) {
-                    
-                    $pid = explode("=",$data[0]);
-                    $time = explode("=",$data[1]);
-                    
-                    $pid_flag = (int) $pid[1];
-                    $time_flag = (int) $time[1];
-                    
-                    if (posix_kill($pid_flag, 0)) {
-                        $now = time();
-                        $lapse = $now - $time_flag;
-                        
-                        $limit_time = 60 * 15;
-                        if($lapse > $limit_time) {
-                            print_r("Superado 15 min de ejecución, finalizamos proceso anterior(pid: {$pid_flag}).".PHP_EOL);
-                            if (posix_kill($pid_flag, 9)) {
-                                print_r("Finalizado con éxito".PHP_EOL);
-                            } else {
-                                print_r("Ocurrió un problema, no pudo finalizarse el proceso".PHP_EOL);
-                            }
-                        } else {
-                            print_r("Esperamos el proceso anterior(pid: {$pid_flag}) a que finalice. Tiempo actual de ejecución: {$lapse} segundos.".PHP_EOL);
-                            return true;
-                        }
-                    }
-                }
-            }
-            @unlink($file);
-        }
-
-        $time = time();
-        $data = "pid={$mypid}\ntime={$time}";
-        $handle = fopen($file, "w+");
-        fwrite($handle, $data);
-        fclose($handle);
-
-        return false;
-    }
-    
-    /**
-     * 
-     * @param string $flag
-     * @return boolean
-     * 
-     * Description: Retorna true si pudo borrarse el archivo de bloqueo. False en cualquier otro caso.
-     */
-    
-    protected function removeLock($flag) {
-        
-        if (is_null($flag)) return false;
-
-        $file = $this->pathLock . "/" . $flag;
-        unlink($file);
-        
-        if(!file_exists($file)) return true;
-        
-        return false;
-    }
-    
-    /**
-     * 
-     * @param string $v
-     * @return array
-     * 
-     * Description: Retorna el tipo de valor y el valor mismo de una respuesta SNMP para Octets
-     */
-    protected function parseSnmpOctetsValue($v) {
-        
-        if( $v == '""' || $v == '' ) return array();
-
-        $type = substr( $v, 0, strpos( $v, ':' ) );
-        $value = trim( substr( $v, strpos( $v, ':' ) + 1 ) );
-        
-        return array(0=>$type,1=>(int)$value);
-    }
-
-    function hex2str($hex) {
-        $str = "";
-        for($i=0;$i<strlen($hex);$i+=2)
-           $str .= chr(hexdec(substr($hex,$i,2)));
-    
-        return $str;
-    }
-}

+ 11 - 25
Command/HuaweiOnuCatvRxCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,40 +38,27 @@ class HuaweiOnuCatvRxCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_onu_rx = "onu_catvrx_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
         $time = time();
 
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
-        
-        $flag = "olt_onus_catvrx_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_onu_rx = "onu_catvrx_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
-        $rxCached = array(); //$this->getData($key_onu_rx, true);
+        $sendData = $rxCached = array();
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $rxPower = $SNMP->$library()->onuCatvRxOpticalPower();
+        $rxPower = $this->getSNMP("onuCatvRxOpticalPower","onuCatvRxPower");
         
-        $sendData = array();
         $metric = "onu_catvrx_";
         $line = 0;
         foreach($rxPower as $index => $rx) {
@@ -98,10 +86,8 @@ class HuaweiOnuCatvRxCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
         }
 
-        //$this->collector->set($key,$dataCached,true);
-
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
         
     }
 

+ 11 - 25
Command/HuaweiOnuRxCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,40 +38,27 @@ class HuaweiOnuRxCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_onu_rx = "onu_rx_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
         $time = time();
 
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
-        
-        $flag = "olt_onus_rx_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_onu_rx = "onu_rx_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
-        $rxCached = array(); //$this->getData($key_onu_rx, true);
+        $sendData = $rxCached = array();
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $rxPower = $SNMP->$library()->onuPonRxOpticalPower();
+        $rxPower = $this->getSNMP("onuPonRxOpticalPower","onuRxPower");
         
-        $sendData = array();
         $metric = "onu_rx_";
         $line = 0;
         foreach($rxPower as $index => $rx) {
@@ -98,10 +86,8 @@ class HuaweiOnuRxCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
         }
 
-        //$this->collector->set($key,$dataCached,true);
-
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
         
     }
 

+ 9 - 23
Command/HuaweiOnuScanCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -36,43 +37,28 @@ class HuaweiOnuScanCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_olt_pons = "olt_scan_pons_{$this->d_s}";
         $inicio = microtime(true);
 
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        
-        $flag = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_olt_pons = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $portCached = $this->getData($key_olt_pons, true);
 
         if(empty($portCached)) {
             $this->output->writeln("Se requiere {$key_olt_pons}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
         $dataCached = array();
 
-        $serialNumbers = $SNMP->$library()->onuSerialNumber();
+        $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan");
         // array [4194312192.1] => 485754430011D168
         //        portIndex.onuIndex => serialNumber Hexa [48 57 54 43] 0011D168  => HWTC0011D168 (parecido al PonSerialNumber)
         
-        //print_r($portCached);
-        //print_r($serialNumbers);
-
         $countOnus = 0;
         foreach($serialNumbers as $index => $hexSerialNumber) {
             $vendoId = $this->hex2str(substr($hexSerialNumber,0,8));
@@ -101,7 +87,7 @@ class HuaweiOnuScanCommand extends BaseCommand
         $this->setData($key_olt_scan, $dataCached, true);
 
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
 
         $fin = microtime(true);
         $time = $fin - $inicio;

+ 15 - 27
Command/HuaweiOnuStatsCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,46 +38,33 @@ class HuaweiOnuStatsCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
-        $inicio = microtime(true);
-
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
+        $key_olt_scan = "olt_scan_{$this->d_s}";
         $saveHistoric = (int) $input->getOption('save-historic');
-        
-        $flag = "olt_onu_stats_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
+        $inicio = microtime(true);
 
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
         
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $txPower = $SNMP->$library()->onuPonTxOpticalPower();
-        $rxPower = $SNMP->$library()->onuPonRxOpticalPower();
-        $temperature = $SNMP->$library()->onuPonOpticalTemperature();
-        $voltage = $SNMP->$library()->onuPonOpticalVltage();
-        $catvRxPower = $SNMP->$library()->onuCatvRxOpticalPower();
+        $txPower = $this->getSNMP("onuPonTxOpticalPower","onuTxPower");
+        $rxPower = $this->getSNMP("onuPonRxOpticalPower","onuRxPower");
+        $temperature = $this->getSNMP("onuPonOpticalTemperature","onuTemperature");
+        $voltage = $this->getSNMP("onuPonOpticalVltage","onuVoltage");
+        $catvRxPower = $this->getSNMP("onuCatvRxOpticalPower","onuCatvRxPower");
         $status = $txPower;
 
-        $sendData = array();
+        $stats = $sendData = array();
 
         $metrics = array("txPower" => "onu_tx_", "rxPower" => "onu_rx_", "temperature" => "onu_temperature_", "voltage" => "onu_voltage_", "status" => "onu_status_", "catvRxPower" => "onu_catvrx_");
 
-        $stats = array();
         foreach($metrics as $m => $metric) {
             $stats[$metric] = array();
         }
@@ -109,7 +97,7 @@ class HuaweiOnuStatsCommand extends BaseCommand
         }
 
         foreach($stats as $metric => $data) {
-            $key_onu_stats = "{$metric}d_{$oltDeviceId}_s_{$oltServerId}";
+            $key_onu_stats = "{$metric}{$this->d_s}";
 
             $this->setData($key_onu_stats, $data, true);
         }
@@ -124,7 +112,7 @@ class HuaweiOnuStatsCommand extends BaseCommand
         }
 
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
 
         $fin = microtime(true);
         $time = $fin - $inicio;

+ 11 - 25
Command/HuaweiOnuStatusCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,40 +38,27 @@ class HuaweiOnuStatusCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_onu_status = "onu_status_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
         $time = time();
-
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
         
-        $flag = "olt_onus_status_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_onu_status = "onu_status_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
-        $statusCached = array(); //$this->getData($key_onu_status, true);
+        $sendData = $statusCached = array();
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $status = $SNMP->$library()->onuPonRxOpticalPower(); //buscamos distinto a 2147483647
+        $status = $this->getSNMP("onuPonRxOpticalPower","onuRxPower"); //buscamos distinto a 2147483647
 
-        $sendData = array();
         $metric = "onu_status_";
         $line = 0;
         foreach($status as $index => $s) {
@@ -98,10 +86,8 @@ class HuaweiOnuStatusCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
         }
 
-        //$this->collector->set($key,$dataCached,true);
-
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
         
     }
 

+ 11 - 25
Command/HuaweiOnuTemperatureCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,40 +38,27 @@ class HuaweiOnuTemperatureCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_onu_temperature = "onu_temperature_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
         $time = time();
 
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
-        
-        $flag = "olt_onus_temperature_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_onu_temperature = "onu_temperature_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
-        $temperatureCached = array(); //$this->getData($key_onu_temperature, true);
+        $sendData = $temperatureCached = array();
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $temperature = $SNMP->$library()->onuPonOpticalTemperature();
+        $temperature = $this->getSNMP("onuPonOpticalTemperature","onuTemperature");
 
-        $sendData = array();
         $metric = "onu_temperature_";
         $line = 0;
         foreach($temperature as $index => $temp) {
@@ -98,10 +86,8 @@ class HuaweiOnuTemperatureCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
         }
 
-        //$this->collector->set($key,$dataCached,true);
-
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
         
     }
 

+ 11 - 25
Command/HuaweiOnuTxCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,40 +38,27 @@ class HuaweiOnuTxCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_onu_tx = "onu_tx_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
         $time = time();
 
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
-        
-        $flag = "olt_onus_tx_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_onu_tx = "onu_tx_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
-        $txCached = array();
+        $sendData = $txCached = array();
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $txPower = $SNMP->$library()->onuPonTxOpticalPower();
+        $txPower = $this->getSNMP("onuPonTxOpticalPower","onuTxPower");
 
-        $sendData = array();
         $metric = "onu_tx_";
         $line = 0;
         foreach($txPower as $index => $tx) {
@@ -98,10 +86,8 @@ class HuaweiOnuTxCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
         }
 
-        //$this->collector->set($key,$dataCached,true);
-
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
         
     }
 

+ 11 - 25
Command/HuaweiOnuVoltageCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,40 +38,27 @@ class HuaweiOnuVoltageCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_onu_voltage = "onu_voltage_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
         $time = time();
-
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
         
-        $flag = "olt_onus_voltage_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_onu_voltage = "onu_voltage_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
-        $voltageCached = array();//$this->getData($key_onu_voltage, true);
+        $sendData = $voltageCached = array();
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
-        $voltage = $SNMP->$library()->onuPonOpticalVltage();
+        $voltage = $this->getSNMP("onuPonOpticalVltage","onuVoltage");
 
-        $sendData = array();
         $metric = "onu_voltage_";
         $line = 0;
         foreach($voltage as $index => $volt) {
@@ -98,10 +86,8 @@ class HuaweiOnuVoltageCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
         }
 
-        //$this->collector->set($key,$dataCached,true);
-
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
         
     }
 

+ 12 - 26
Command/HuaweiPonOctetsCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,43 +38,31 @@ class HuaweiPonOctetsCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_pons_{$this->d_s}";
+        $key_olt_pon_bandwidth = "olt_bandwidth_pons_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
 
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
-        $saveHistoric = (int) $input->getOption('save-historic');
-        
-        $flag = "olt_pon_octets_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}";
-        $key_olt_pon_bandwidth = "olt_bandwidth_pons_d_{$oltDeviceId}_s_{$oltServerId}";
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
         
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
-
         $dataCached = $this->getData($key_olt_scan, true);
         $bandwidthCached = $this->getData($key_olt_pon_bandwidth, true);
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
         //counter32
-        $inOctets = $SNMP->$library()->ifInOctets();
-        $outOctets = $SNMP->$library()->ifOutOctets();
+        $inOctets = $this->getSNMP("ifInOctets","portInOctets");
+        $outOctets = $this->getSNMP("ifOutOctets","portOutOctets");
 
         $sendData = array();
 
-        $subId = "d_{$oltDeviceId}_s_{$oltServerId}";
+        $subId = $this->d_s;
         
         $t1 = time();
         foreach($dataCached as $index => $pon) {
@@ -115,9 +104,6 @@ class HuaweiPonOctetsCommand extends BaseCommand
             }
         }
 
-        //print_r($bandwidthCached);
-        //$bandwidthCached = array();
-
         $this->setData($key_olt_pon_bandwidth, $bandwidthCached, true);
 
         if($sendData && $saveHistoric) {
@@ -130,7 +116,7 @@ class HuaweiPonOctetsCommand extends BaseCommand
         }
 
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
 
         $fin = microtime(true);
         $time = $fin - $inicio;

+ 7 - 18
Command/HuaweiPonScanCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -36,29 +37,17 @@ class HuaweiPonScanCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
+        $key_olt_scan = "olt_scan_pons_{$this->d_s}";
         $inicio = microtime(true);
-
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
         
-        $flag = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
         $dataCached = array();
 
-        $ports = $SNMP->$library()->oltPonDesc();
+        $ports = $this->getSNMP("oltPonDesc","ponScan");
 
         $countPons = 0;
 
@@ -81,7 +70,7 @@ class HuaweiPonScanCommand extends BaseCommand
         $this->setData($key_olt_scan, $dataCached, true);
 
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
 
         $fin = microtime(true);
         $time = $fin - $inicio;

+ 16 - 27
Command/HuaweiPonStatsCommand.php

@@ -2,6 +2,7 @@
 
 namespace HuaweiBundle\Command;
 
+use BaseStatsBundle\Command\BaseCommand;
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
@@ -37,46 +38,34 @@ class HuaweiPonStatsCommand extends BaseCommand
     {
         parent::execute($input, $output);
         
-        $this->output->writeln("INICIO");
-        
-        $inicio = microtime(true);
-
-        $oltDeviceId = (int) $input->getOption('olt-device-id');
-        $oltServerId = (int) $input->getOption('olt-server-id');
-        $oltIp = $input->getOption('olt-ip');
-        $oltCommunity = $input->getOption('olt-community');
-        $oltSnmpLibrary = $input->getOption('olt-snmp-library');
+        $key_olt_scan = "olt_scan_pons_{$this->d_s}";
         $saveHistoric = (int) $input->getOption('save-historic');
+        $inicio = microtime(true);
         
-        $flag = "olt_pon_stats_d_{$oltDeviceId}_s_{$oltServerId}.lock";
-        $key_olt_scan = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}";
-        
-        /* Control de bloqueo */
-        if($this->lock($flag)) {return;}
-
-        $SNMP = new SNMP($oltIp, $oltCommunity);
-        $library = "use".$oltSnmpLibrary;
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
 
         $dataCached = $this->getData($key_olt_scan, true);
 
         if(empty($dataCached)) {
             $this->output->writeln("Se requiere {$key_olt_scan}.");
-            $this->removeLock($flag);
+            $this->removeLock($this->flag);
             return true;
         }
 
         //return [PONINDEX.ONUID] => value
-        $rxPower = $SNMP->$library()->oltPonRxOpticalPower();
-
+        $rxPower = $this->getSNMP("oltPonRxOpticalPower","ponRxPower");
+        
         //return [PONINDEX] => value
-        $txPower = $SNMP->$library()->oltPonTxOpticalPower();
-        $temperature = $SNMP->$library()->oltPonOpticalTemperature();
-        $voltage = $SNMP->$library()->oltPonOpticalVltage();
-        $biasCurrent = $SNMP->$library()->oltPonOpticalCurrent();
+        $txPower = $this->getSNMP("oltPonTxOpticalPower","ponTxPower");
+        $temperature = $this->getSNMP("oltPonOpticalTemperature","ponTemperature");
+        $voltage = $this->getSNMP("oltPonOpticalVltage","ponVoltage");
+        $biasCurrent = $this->getSNMP("oltPonOpticalCurrent","ponBiasCurrent");
 
         $ponStatsCached = $sendData = array();
 
-        $subId = "d_{$oltDeviceId}_s_{$oltServerId}";
+        $subId = $this->d_s;
         $metrics = array("txPower" => "{$subId}_pon_tx_", "temperature" => "{$subId}_pon_temperature_", "voltage" => "{$subId}_pon_voltage_", "biasCurrent" => "{$subId}_pon_biascurrent_");
 
         foreach($dataCached as $index => $pon) {
@@ -134,7 +123,7 @@ class HuaweiPonStatsCommand extends BaseCommand
         }
 
         if($ponStatsCached) {
-            $key_pon_stats = "olt_stats_pons_d_{$oltDeviceId}_s_{$oltServerId}";
+            $key_pon_stats = "olt_stats_pons_{$this->d_s}";
             $this->setData($key_pon_stats, $ponStatsCached, true);
         }
 
@@ -148,7 +137,7 @@ class HuaweiPonStatsCommand extends BaseCommand
         }
 
         /* Fin de bloqueo */
-        $this->removeLock($flag);
+        $this->removeLock($this->flag);
 
         $fin = microtime(true);
         $time = $fin - $inicio;