瀏覽代碼

Se crea la librería con todo lo requerido para las stats de ZTE que hoy
poseen las demás marcas.

Maximiliano Schvindt 7 年之前
父節點
當前提交
5a9cef3e8d

+ 78 - 0
Command/ZteOltScanCommand.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace ZteBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use ZteBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class ZteOltScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('zte:olt:scan')
+            ->setDescription('Escanear OLT para obtener ONUs')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $key_olt_scan = "olt_scan_card_{$this->d_s}";
+        $inicio = microtime(true);
+        
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
+
+        $dataCached = array();
+
+        $cpu = $this->getSNMP("oltCardCpu","cardCpu");
+        $memory = $this->getSNMP("oltCardMemory","cardMemory");
+
+        $_memory = $_cpu = array();
+        foreach($cpu as $index => $value) {
+            if($value == -1) continue;
+            $_cpu[$index] = $value;
+        }
+        
+        foreach($memory as $index => $value) {
+            if($value == -1) continue;
+            $_memory[$index] = $value;
+        }
+
+        if($_cpu) {$dataCached['cpu'] = $_cpu;}
+        
+        if($_memory) {$dataCached['memory'] = $_memory;}
+
+        $this->setData($key_olt_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 100 - 0
Command/ZteOnuScanCommand.php

@@ -0,0 +1,100 @@
+<?php
+
+namespace ZteBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use ZteBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class ZteOnuScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('zte:onu:scan')
+            ->setDescription('Escanear OLT para obtener ONUs')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $key_olt_pons = "olt_scan_pons_{$this->d_s}";
+        $inicio = microtime(true);
+
+        $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($this->flag);
+            return true;
+        }
+
+        $dataCached = array();
+
+        print_r($portCached);
+        
+        $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan");
+        // array [4194312192.1] => 485754430011D168
+        //        portIndex.onuIndex => serialNumber Hexa [48 57 54 43] 0011D168  => HWTC0011D168 (parecido al PonSerialNumber)
+
+        $countOnus = 0;
+        foreach($serialNumbers as $index => $hexSerialNumber) {
+            $vendoId = $this->hex2str(substr($hexSerialNumber,0,8));
+            $rest = substr($hexSerialNumber,8);
+            
+            $sn = strtolower($vendoId.$rest);
+            
+            $portOnu = explode(".",$index);
+            if(count($portOnu) != 2) continue;
+            $portIndex = $portOnu[0];
+            $onuId = $portOnu[1];
+            $countOnus++;
+            
+            if(isset($portCached[$portIndex])) {
+                $p = $portCached[$portIndex];
+                
+                $data = $p;
+                $data['onuId'] = $onuId;
+                $data['serialNumber'] = $sn;
+                $data['hexaSerialNumber'] = $hexSerialNumber;
+                $data['ponport'] = "{$p['ponPort']}/{$onuId}";
+                $dataCached[$index] = $data;
+            }
+        }
+
+        $this->setData($key_olt_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
+        
+    }
+
+}

+ 130 - 0
Command/ZteOnuStatsCommand.php

@@ -0,0 +1,130 @@
+<?php
+
+namespace ZteBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use ZteBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class ZteOnuStatsCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('zte:onu:stats')
+            ->setDescription('Stats de ONUs de OLT')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP"),
+                new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $key_olt_scan = "olt_scan_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
+        $inicio = microtime(true);
+
+        $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($this->flag);
+            return true;
+        }
+
+        $txPower = $this->getSNMP("onuPonTxOpticalPower","onuTxPower");
+        $rxPower = $this->getSNMP("onuPonRxOpticalPower","onuRxPower");
+        $temperature = $this->getSNMP("onuPonOpticalTemperature","onuTemperature");
+        $voltage = $this->getSNMP("onuPonOpticalVltage","onuVoltage");
+        $status = $this->getSNMP("onuStatus","onuStatus");
+
+        $stats = $sendData = array();
+
+        $metrics = array("txPower" => "onu_tx_", "rxPower" => "onu_rx_", "temperature" => "onu_temperature_", "voltage" => "onu_voltage_", "status" => "onu_status_");
+
+        foreach($metrics as $m => $metric) {
+            $stats[$metric] = array();
+        }
+
+        foreach($dataCached as $index => $onu) {
+            $statusIndex = $index;
+            $index = $index.".1";
+            $sn = strtolower($onu['serialNumber']);
+            
+            foreach($metrics as $data => $metric) {
+
+                $m = "{$metric}{$sn}";
+                if(isset($$data[$index]) && !empty($$data[$index])) {
+
+                    if($data == 'txPower') {
+                        $v = $$data[$index] * 0.002 - 30;
+                    } elseif($data == "rxPower") {
+                        $v = $$data[$index] * 0.002 - 30;
+                    } elseif($data == "voltage") {
+                        $v = ($$data[$index] * 20) / 1000;
+                    } elseif ($data == "temperature") {
+                        $v = $$data[$index] / 256;
+                    } else {
+                        continue;
+                    }
+
+                    $sendData[$m] = "{$v}|g";
+
+                    $stats[$metric][$sn] = $v;
+                } elseif($data == "status") {
+                    $v = 0;
+                    if(isset($$data[$statusIndex]) && $$data[$statusIndex] == 3) $v = 1;
+                    
+                    $sendData[$m] = "{$v}|g";
+                    $stats[$metric][$sn] = $v;
+                }
+            }
+        }
+
+        foreach($stats as $metric => $data) {
+            $key_onu_stats = "{$metric}{$this->d_s}";
+
+            $this->setData($key_onu_stats, $data, true);
+        }
+        
+        if($sendData && $saveHistoric) {
+            $t_start_script = microtime(true); 
+            $statsdService = $this->getContainer()->get('statsd');
+            $statsdService->send($sendData);
+            $t_end_script = microtime(true); 
+            $time = $t_end_script - $t_start_script;
+            print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
+        }
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 155 - 0
Command/ZtePonOctetsCommand.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace ZteBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use ZteBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class ZtePonOctetsCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('zte:pon:octets')
+            ->setDescription('Bandwidth PON PORTs de OLT')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP"),
+                new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $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);
+
+        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
+        $library = "use".$this->oltSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
+        
+        $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($this->flag);
+            return true;
+        }
+
+        //counter64
+        $inOctets = $this->getSNMP("ifHCInOctets","portInOctets");
+        $outOctets = $this->getSNMP("ifHCOutOctets","portOutOctets");
+
+        $sendData = array();
+
+        $subId = $this->d_s;
+        
+        $t1 = time();
+        $totalConsOut = $totalConsIn = $totalIn = $totalOut = 0;
+        foreach($dataCached as $index => $pon) {
+
+            if(isset($pon['nexo'])) continue;
+
+            $ponPort = str_replace("/",".",$pon['ponPort']);
+            
+            //foreach($metrics as $data => $metric) {
+            //if(isset($$data[$index]) && !empty($$data[$index])) {
+            
+            (isset($inOctets[$index]))? $in1 = $inOctets[$index] : $in1 = 0;
+            (isset($outOctets[$index]))? $out1 = $outOctets[$index] : $out1 = 0;
+
+            if(isset($bandwidthCached[$index])) {
+                $t0 = $bandwidthCached[$index]['t'];
+                $in0 = $bandwidthCached[$index]['inOct'];
+                $out0 = $bandwidthCached[$index]['outOct'];
+                $inAcc = $bandwidthCached[$index]['inAcc'];
+                $outAcc = $bandwidthCached[$index]['outAcc'];
+
+                $inBandwidth = $outBandwidth = 0; 
+                 
+                if(($in1 >= $in0) && ($t1 > $t0)) {
+                    $diff = $in1 - $in0;
+                    $inAcc += $diff;
+                    $inBandwidth = ($diff / ($t1 - $t0)) * 8;
+                }
+
+                if(($out1 >= $out0) && ($t1 > $t0)) {
+                    $diff = $out1 - $out0;
+                    $outAcc += $diff;
+                    $outBandwidth = ($diff / ($t1 - $t0)) * 8;
+                }
+
+                $totalIn += $inBandwidth;
+                $totalOut += $outBandwidth;
+
+                $sendData["{$subId}_inbandwidth_pon_{$ponPort}"] = "{$inBandwidth}|g";
+                $sendData["{$subId}_outbandwidth_pon_{$ponPort}"] = "{$outBandwidth}|g";
+
+                if(date("d",$t0) != date("d",$t1)) {
+                    $inAcc = $outAcc = 0;
+                }
+
+                $totalConsOut += $outAcc;
+                $totalConsIn += $inAcc;
+                
+                $bandwidthCached[$index] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => $inAcc, 'outAcc' => $outAcc, 'inBand' => $inBandwidth, 'outBand' => $outBandwidth);
+            } else {
+                $bandwidthCached[$index] = array('t' => $t1, 'inOct' => $in1, 'outOct' => $out1, 'inAcc' => 0, 'outAcc' => 0, 'inBand' => 0, 'outBand' => 0);
+            }
+        }
+
+        $this->setData($key_olt_pon_bandwidth, $bandwidthCached, true);
+
+        $oltBandwidth = array();
+        $oltBandwidth["{$subId}_inbandwidth_olt"] = "{$totalIn}|g";
+        $oltBandwidth["{$subId}_outbandwidth_olt"] = "{$totalOut}|g";
+
+        $div = 1073741824; //bytes => giga
+        $consIn = number_format(($totalConsIn / $div),3);
+        $consOut = number_format(($totalConsOut / $div),3);
+        $oltConsumption = array();
+        $oltConsumption["{$subId}_inconsumption_olt"] = "{$consIn}|g";
+        $oltConsumption["{$subId}_outconsumption_olt"] = "{$consOut}|g";
+
+        $statsdService = $this->getContainer()->get('statsd');
+        $statsdService->send($oltBandwidth);
+        $statsdService->send($oltConsumption);
+
+        if($sendData && $saveHistoric) {
+            $t_start_script = microtime(true); 
+            $statsdService->send($sendData);
+            $t_end_script = microtime(true); 
+            $time = $t_end_script - $t_start_script;
+            print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
+        }
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 110 - 0
Command/ZtePonScanCommand.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace ZteBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use ZteBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class ZtePonScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('zte:pon:scan')
+            ->setDescription('Escanear OLT para obtener PON PORTs')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $key_olt_scan = "olt_scan_pons_{$this->d_s}";
+        $inicio = microtime(true);
+        
+        $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 = $this->getSNMP("oltPonDesc","ponScan");
+        $_nexos = $this->getSNMP("oltPonNexo","ponScan");
+
+        $gpons = array_values($_ports);
+        $indexes = array_keys($_nexos);
+
+        $countPons = 0;
+
+        $aux = array();
+
+        foreach($_ports as $index => $d) {
+            if (preg_match("/gpon/i", $d)) {
+                $s = str_replace(array("gpon","GPON","pon","PON"," ","_"),"",$d);
+                $aux[$d] = $index;
+                $s_p = explode("/",trim($s));
+                if(count($s_p) == 3) {
+                    $countPons++;
+                    $b = $s_p[0];
+                    $s = $s_p[1];
+                    $p = $s_p[2];
+                    
+                    $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
+                }
+            }
+        }
+
+        foreach($gpons as $index => $d) {
+            if (preg_match("/gpon/i", $d)) {
+                if(isset($indexes[$index])) {
+                    $index = $indexes[$index];
+                } else {
+                    continue;
+                }
+                $s = str_replace(array("gpon","GPON","pon","PON"," ","_"),"",$d);
+                $s_p = explode("/",trim($s));
+                if(count($s_p) == 3) {
+                    $countPons++;
+                    $b = $s_p[0];
+                    $s = $s_p[1];
+                    $p = $s_p[2];
+                    
+                    $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
+                    if(isset($aux[$d])) {
+                        $dataCached[$index]['nexo'] = $aux[$d];
+                    }
+                }
+            } 
+        }
+
+        $this->setData($key_olt_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos / Cantidad Puertos: {$countPons}");
+        
+    }
+
+}

+ 162 - 0
Command/ZtePonStatsCommand.php

@@ -0,0 +1,162 @@
+<?php
+
+namespace ZteBundle\Command;
+
+use BaseStatsBundle\Command\BaseCommand;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use ZteBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class ZtePonStatsCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('zte:pon:stats')
+            ->setDescription('Stats de PON PORTs de OLT')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
+                new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
+                new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
+                new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP"),
+                new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+        
+        $key_olt_scan = "olt_scan_pons_{$this->d_s}";
+        $saveHistoric = (int) $input->getOption('save-historic');
+        $inicio = microtime(true);
+        
+        $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($this->flag);
+            return true;
+        }
+
+        //return [PONINDEX.ONUID] => value
+        $rxPower = $this->getSNMP("oltPonRxOpticalPower","ponRxPower");
+        
+        //return [PONINDEX] => value
+        $txPower = $this->getSNMP("oltPonTxOpticalPower","ponTxPower");
+        $temperature = $this->getSNMP("oltPonOpticalTemperature","ponTemperature");
+        $voltage = $this->getSNMP("oltPonOpticalVltage","ponVoltage");
+        $biasCurrent = $this->getSNMP("oltPonOpticalCurrent","ponBiasCurrent");
+
+        /* print_r($rxPower);
+        print_r($txPower);
+        print_r($temperature);
+        print_r($voltage);
+        print_r($biasCurrent); */
+
+        $ponStatsCached = $sendData = array();
+
+        $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) {
+
+            $realIndex = $index;
+            if(isset($pon['nexo'])) {
+                $realIndex = $pon['nexo'];
+            }
+
+            $ponPort = str_replace ('/','.',$pon['ponPort']);
+            
+            $stats = array();
+            $stats['ponPort'] = $pon['ponPort'];
+            $stats['rxPower'] = array();
+            
+            foreach($metrics as $data => $metric) {
+                
+                if(isset($$data[$realIndex]) && !empty($$data[$realIndex])) {
+                    
+                    $m = "{$metric}{$ponPort}";
+                    
+                    $v = $$data[$realIndex] * 0.001;
+                    
+                    $stats[$data] = $v;
+                    
+                    $sendData[$m] = "{$v}|g";
+                }
+            }
+            
+            $ponStatsCached[$index] = $stats;
+        }
+
+        foreach($rxPower as $index => $rx) {
+            
+            $ponPortOnuId = explode(".",$index);
+            
+            if(count($ponPortOnuId) != 2) continue;
+            $indexPon = $ponPortOnuId[0];
+
+            if(isset($dataCached[$indexPon])) {
+
+                $onuId = $ponPortOnuId[1];
+                $ponPort = str_replace ('/','.',$dataCached[$indexPon]['ponPort']);
+                
+                $m = "{$subId}_pon_rx_{$ponPort}.{$onuId}";
+                
+                $v = $rx * 0.001;
+                
+                if(isset($ponStatsCached[$indexPon]['rxPower'])) {
+                    $ponStatsCached[$indexPon]['rxPower'][$onuId] = $v;
+                }
+                
+                if(isset($dataCached[$indexPon]['nexo'])) {
+                    $index = $dataCached[$indexPon]['nexo'];
+                    if(isset($ponStatsCached[$index]['rxPower'])) {
+                        $ponStatsCached[$index]['rxPower'][$onuId] = $v;
+                    }
+                }
+
+                $sendData[$m] = "{$v}|g";
+
+            }
+        }
+
+        if($ponStatsCached) {
+            $key_pon_stats = "olt_stats_pons_{$this->d_s}";
+            $this->setData($key_pon_stats, $ponStatsCached, true);
+        }
+
+        if($sendData && $saveHistoric) {
+            $t_start_script = microtime(true); 
+            $statsdService = $this->getContainer()->get('statsd');
+            $statsdService->send($sendData);
+            $t_end_script = microtime(true); 
+            $time = $t_end_script - $t_start_script;
+            print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
+        }
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 87 - 30
SNMP/MIBS/OIDSZteV1.php

@@ -7,29 +7,82 @@ namespace ZteBundle\SNMP\MIBS;
 // https://translate.google.com/translate?hl=en&sl=auto&tl=en&u=https%3A%2F%2Fixnfo.com%2Foid-i-mib-dlya-huawei-olt-i-onu.html
 // https://github.com/chinnurtb/xiaoli/tree/master/node/monitd/include/mib
 
-class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
+class OIDSZTEV1 extends \ZteBundle\SNMP\MIB {
     
     const OID_authOnuListSlot               = "1.3.6.1.4.1.5875.800.3.10.1.1.2";
     const OID_authOnuListPon                = "1.3.6.1.4.1.5875.800.3.10.1.1.3";
     const OID_authOnuListOnuid              = "1.3.6.1.4.1.5875.800.3.10.1.1.4";
     
-    const OID_authOnuListMac                = "1.3.6.1.4.1.2011.6.128.1.1.2.43.1.3";
-    const OID_onuPonRxOpticalPower          = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.4";
-    const OID_onuPonTxOpticalPower          = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.3";
-    const OID_onuPonOpticalVltage           = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.5";
-    const OID_onuPonOpticalTemperature      = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.1";
-    const OID_onuPonOpticalCurrent          = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.2";
+    const OID_authOnuListMac                = "1.3.6.1.4.1.3902.1012.3.28.1.1.5";
+    
+    const OID_onuPonRxOpticalPower          = "1.3.6.1.4.1.3902.1012.3.50.12.1.1.10"; //value * 0.002 - 30
+    const OID_onuPonTxOpticalPower          = "1.3.6.1.4.1.3902.1012.3.50.12.1.1.14"; //value * 0.002 - 30
+
+    const OID_onuPonOpticalVltage           = "1.3.6.1.4.1.3902.1012.3.50.12.1.1.17";  //(value * 20) / 1000    mV to V
+    const OID_onuPonOpticalTemperature      = "1.3.6.1.4.1.3902.1012.3.50.12.1.1.19";  //(value / 256)   C
+    const OID_onuPonOpticalCurrent          = "1.3.6.1.4.1.3902.1012.3.50.12.1.1.18";
     const OID_onuCatvRxOpticalPower               = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.7";
+
+    /* zxGponPonPowerFeedVoltage OBJECT-TYPE  1.3.6.1.4.1.3902.1012.3.50.12.1.1.17
+        SYNTAX      INTEGER
+        MAX-ACCESS  read-only
+        STATUS      current
+        DESCRIPTION
+            "DC voltage, 2s complement, 20 mV resolution.(2 byte)"
+        REFERENCE
+            "G.984.4 Section 11.1.10 Test result enumeration"
+        ::= { zxGponPonEntry 17}
+
+    zxGponPonLaserBiasCurrent OBJECT-TYPE   1.3.6.1.4.1.3902.1012.3.50.12.1.1.18
+        SYNTAX      INTEGER
+        MAX-ACCESS  read-only
+        STATUS      current
+        DESCRIPTION
+            "2s complement, 2 uA resolution.(2 byte)"
+        REFERENCE
+            "G.984.4 Section 11.1.10 Test result enumeration"
+        ::= { zxGponPonEntry 18}
+
+    zxGponPonTemperature OBJECT-TYPE    1.3.6.1.4.1.3902.1012.3.50.12.1.1.19
+        SYNTAX      INTEGER
+        MAX-ACCESS  read-only
+        STATUS      current
+        DESCRIPTION
+            "2s complement, 1/256 degree C resolution.(2 byte)"
+        REFERENCE
+            "G.984.4 Section 11.1.10 Test result enumeration"
+        ::= { zxGponPonEntry 19} 
+        
+    ONU O1O7 State	O6:Operation-state
+	    6 - O6, 0 - other
+    
+    ONU Operational State	Online
+	    1 - LOS, 2 - syncMib, 3 - working, 4 - DyingGasp, x - AuthFail, 6 - OffLine, x - Logging
+    ONU Last Online Time	2017-02-06 00:14:32
+    ONU Last Offline Time	0000-00-00 00:00:00
+    ONU Offline Reason	Unknown
+	1 - Unknown, 2 - LOS, 3 - LOSi, 7 - LOAMi, 9 - DyingGasp
+
+    .1.3.6.1.4.1.3902.1012.3.28.2.1.3.268501248.1=6
+    .1.3.6.1.4.1.3902.1012.3.28.2.1.4.268501248.1=3
+    .1.3.6.1.4.1.3902.1012.3.28.2.1.5.268501248.1="2017-02-06 00:14:32" .1.3.6.1.4.1.3902.1012.3.28.2.1.6.268501248.1="0000-00-0000:00:00"
+    .1.3.6.1.4.1.3902.1012.3.28.2.1.7.268501248.1=1    
+        
+        
+        
+        */
     
-    const OID_onuStatus                           = "1.3.6.1.4.1.5875.800.3.10.1.1.11";
+    const OID_onuStatus                           = "1.3.6.1.4.1.3902.1012.3.28.2.1.4";
     const OID_oltPonDesc                          = "1.3.6.1.2.1.31.1.1.1.1";
+    const OID_oltPonNexo                          = "1.3.6.1.4.1.3902.1012.3.13.1.1.1";
     const OID_oltPonEnableStatus                  = "1.3.6.1.4.1.5875.800.3.9.3.4.1.4";
     
-    const OID_oltPonRxOpticalPower                = "1.3.6.1.4.1.2011.6.128.1.1.2.51.1.6"; // (value - 10000) * 0.01
-    const OID_oltPonTxOpticalPower                = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.4";
-    const OID_oltPonOpticalVltage                 = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.2";
-    const OID_oltPonOpticalCurrent                = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.3";
-    const OID_oltPonOpticalTemperature            = "1.3.6.1.4.1.2011.6.128.1.1.2.23.1.1";
+    const OID_oltPonRxOpticalPower                = "1.3.6.1.4.1.3902.1015.1010.11.2.1.2"; // value  * 0.001
+    const OID_oltPonTxOpticalPower                = "1.3.6.1.4.1.3902.1015.3.1.13.1.4"; //value * 0.001
+    
+    const OID_oltPonOpticalVltage                 = "1.3.6.1.4.1.3902.1015.3.1.13.1.10";  // value * 0.001
+    const OID_oltPonOpticalCurrent                = "1.3.6.1.4.1.3902.1015.3.1.13.1.9";  // value * 0.001
+    const OID_oltPonOpticalTemperature            = "1.3.6.1.4.1.3902.1015.3.1.13.1.12"; // value * 0.001
     
     
     //Genericos
@@ -39,8 +92,8 @@ class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
     const OID_ifOutOctets                         = "1.3.6.1.2.1.2.2.1.16";
     const OID_ifDescr                             = "1.3.6.1.2.1.2.2.1.2";
      
-    const OID_cardCpu                   = "1.3.6.1.4.1.2011.2.6.7.1.1.2.1.5";
-    const OID_cardMemory                = "1.3.6.1.4.1.2011.2.6.7.1.1.2.1.6";
+    const OID_cardCpu                   = "1.3.6.1.4.1.3902.1015.2.1.1.3.1.9";
+    const OID_cardMemory                = "1.3.6.1.4.1.3902.1015.2.1.1.3.1.11";
 
     function convertIndex($index, $values) {
         $data = array();
@@ -68,10 +121,10 @@ class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
 
     public function onuSerialNumber($index = null) {
         if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,16);
+            return $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,14);
         } 
         
-        $values = $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,16);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,14);
         return $this->convertIndex($index, $values);
     }
     
@@ -87,30 +140,30 @@ class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
     
     public function onuPonRxOpticalPower($index = null) {
         if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_onuPonRxOpticalPower,16);
+            return $this->getSNMP()->lastOidWalk(self::OID_onuPonRxOpticalPower,15);
         } 
         
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonRxOpticalPower,16);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonRxOpticalPower,15);
         return $this->convertIndex($index, $values);
        
     }
     
     public function onuPonTxOpticalPower($index = null) {
         if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_onuPonTxOpticalPower,16);
+            return $this->getSNMP()->lastOidWalk(self::OID_onuPonTxOpticalPower,15);
         } 
 
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonTxOpticalPower,16);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonTxOpticalPower,15);
         return $this->convertIndex($index, $values);
     }
     
     public function onuPonOpticalVltage($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalVltage,16);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalVltage,15);
         return $this->convertIndex($index, $values);
     }
     
     public function onuPonOpticalTemperature($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalTemperature,16);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalTemperature,15);
         return $this->convertIndex($index, $values);
     }
     
@@ -123,6 +176,10 @@ class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
     public function oltPonDesc($index = null) {
         return $this->getSNMP()->lastOidWalk(self::OID_oltPonDesc,12);
     }
+    
+    public function oltPonNexo($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_oltPonNexo,14);
+    }
 
     public function oltPonEnableStatus($index = null) {
         return $this->getSNMP()->lastOidWalk(self::OID_oltPonEnableStatus,15);
@@ -130,27 +187,27 @@ class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
     }
     
     public function oltPonRxOpticalPower($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonRxOpticalPower,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_oltPonRxOpticalPower,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonTxOpticalPower($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonTxOpticalPower,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_oltPonTxOpticalPower,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonOpticalVltage($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalVltage,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalVltage,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonOpticalCurrent($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalCurrent,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalCurrent,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonOpticalTemperature($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalTemperature,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalTemperature,14);
 //        return $this->convertIndex($index, $values);
     }
     
@@ -175,10 +232,10 @@ class OIDSZteV1 extends \ZteBundle\SNMP\MIB {
     }
 
     public function oltCardCpu($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_cardCpu,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_cardCpu,15);
     }
     
     public function oltCardMemory($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_cardMemory,16);
+        return $this->getSNMP()->lastOidWalk(self::OID_cardMemory,15);
     }
 }