Преглед на файлове

Se agregan comandos para escanear onus, puertos y obtener stats de ONUs.

Maximiliano Schvindt преди 7 години
родител
ревизия
4a0f2eea8a
променени са 4 файла, в които са добавени 328 реда и са изтрити 24 реда
  1. 95 0
      Command/FiberlinkOnuScanCommand.php
  2. 128 0
      Command/FiberlinkOnuStatsCommand.php
  3. 86 0
      Command/FiberlinkPonScanCommand.php
  4. 19 24
      SNMP/MIBS/OIDSFiberLinkV1.php

+ 95 - 0
Command/FiberlinkOnuScanCommand.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace FiberlinkBundle\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;
+use FiberlinkBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class FiberlinkOnuScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('fiberlink: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);
+        
+        $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');
+        
+        $flag = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}.lock";
+        $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
+        
+        /* Control de bloqueo */
+        if($this->lock($flag)) {return;}
+
+        $SNMP = new SNMP($oltIp, $oltCommunity);
+        $library = "use".$oltSnmpLibrary;
+
+        //$dataCached = $this->getData($key_olt_scan, true);
+        $dataCached = array();
+
+        $serialNumbers = $SNMP->$library()->onuSerialNumber();
+
+        $countOnus = 0;
+        foreach($serialNumbers as $index => $serialNumber) {
+            $ponPort = explode(".",$index);
+            if(count($ponPort) != 3) continue;
+
+            $s = $ponPort[0];
+            $p = $ponPort[1];
+            $o = $ponPort[2];
+            //$index = $s.$p.$o;
+            $sn = strtolower($serialNumber);
+            
+            $countOnus++;
+            $data = array();
+            $data['slot'] = $s;
+            $data['port'] = $p;
+            $data['onuId'] = $o;
+            $data['serialNumber'] = $sn;
+            $data['ponport'] = "{$s}/{$p}/{$o}";
+            $dataCached[$index] = $data;
+        }
+
+        $this->setData($key_olt_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
+        
+    }
+
+}

+ 128 - 0
Command/FiberlinkOnuStatsCommand.php

@@ -0,0 +1,128 @@
+<?php
+
+namespace FiberlinkBundle\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;
+use FiberlinkBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class FiberlinkOnuStatsCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('fiberlink: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);
+        
+        $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');
+        $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;}
+
+        $SNMP = new SNMP($oltIp, $oltCommunity);
+        $library = "use".$oltSnmpLibrary;
+
+        $dataCached = $this->getData($key_olt_scan, true);
+        
+        if(empty($dataCached)) {
+            $this->output->writeln("Se requiere {$key_olt_scan}.");
+            $this->removeLock($flag);
+            return true;
+        }
+
+        $txPower = $SNMP->$library()->onuPonTxOpticalPower();
+        $rxPower = $SNMP->$library()->onuPonRxOpticalPower();
+        $temperature = $SNMP->$library()->onuPonOpticalTemperature();
+        $voltage = $SNMP->$library()->onuPonOpticalVltage();
+        $status = $SNMP->$library()->onuStatus();
+        $uptime = $SNMP->$library()->onuUptime();
+
+        /* print_r($txPower);
+        print_r($rxPower);
+        print_r($temperature);
+        print_r($voltage);
+        print_r($status); */
+        
+        $sendData = array();
+
+        $metrics = array("txPower" => "onu_tx_", "rxPower" => "onu_rx_", "temperature" => "onu_temperature_", "voltage" => "onu_voltage_", "status" => "onu_status_", "uptime" => "onu_uptime");
+
+        $stats = array();
+        foreach($metrics as $m => $metric) {
+            $stats[$metric] = array();
+        }
+
+        foreach($dataCached as $index => $onu) {
+            $sn = strtolower($onu['serialNumber']);
+            
+            foreach($metrics as $data => $metric) {
+
+                if(isset($$data[$index]) && !empty($$data[$index])) {
+                    $m = "{$metric}{$sn}";
+                    $v = $$data[$index];
+                    $sendData[$m] = "{$v}|g";
+                    $stats[$metric][$sn] = $v;
+                }
+            }
+        }
+
+        foreach($stats as $metric => $data) {
+            $key_onu_stats = "{$metric}d_{$oltDeviceId}_s_{$oltServerId}";
+
+            $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($flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 86 - 0
Command/FiberlinkPonScanCommand.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace FiberlinkBundle\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;
+use FiberlinkBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class FiberlinkPonScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('fiberlink: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);
+        
+        $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');
+        
+        $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;
+
+        $dataCached = $this->getData($key_olt_scan, true);
+        $dataCached = array();
+
+        $ports = $SNMP->$library()->oltPonDesc();
+        $countPons = 0;
+        
+        foreach($ports as $index => $d) {
+            $s_p = explode(".",$index);
+            if(count($s_p) == 2) {
+                $countPons++;
+                $s = $s_p[0];
+                $p = $s_p[1];
+                //$index = $s.$p;               
+                $dataCached[$index] = array("ponPort"=>"{$s}/{$p}",'slot'=>$s,'port'=>$p);
+            }
+        }
+        
+        $this->setData($key_olt_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos / Cantidad Puertos: {$countPons}");
+        
+    }
+
+}

+ 19 - 24
SNMP/MIBS/OIDSFiberLinkV1.php

@@ -33,6 +33,7 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
     const OID_ontUplinkPONports         = "1.3.6.1.4.1.13464.1.11.4.1.1.33";
     const OID_ontIPconfiguration        = "1.3.6.1.4.1.13464.1.11.4.1.1.41";
     
+    /*
     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";
@@ -50,15 +51,16 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
     const OID_oltPonOpticalVltage                 = "1.3.6.1.4.1.5875.800.3.9.3.4.1.9";
     const OID_oltPonOpticalCurrent                = "1.3.6.1.4.1.5875.800.3.9.3.4.1.10";
     const OID_oltPonOpticalTemperature            = "1.3.6.1.4.1.5875.800.3.9.3.4.1.11";
-    
+    */
     
     //Genericos
+    /*
     const OID_ifHCInOctets                        = "1.3.6.1.2.1.31.1.1.1.6";
     const OID_ifHCOutOctets                       = "1.3.6.1.2.1.31.1.1.1.10";
     const OID_ifInOctets                          = "1.3.6.1.2.1.2.2.1.10";
     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";
-    
+    */
 
     function convertIndex($index, $values) {
         $data = array();
@@ -72,64 +74,57 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
         return $values;
     }
     
-    public function onuSlot() {
-        return $this->getSNMP()->lastOidWalk(self::OID_authOnuListSlot,14);
-    }
-
-    public function onuPon() {
-        return $this->getSNMP()->lastOidWalk(self::OID_authOnuListPon,14);
-    }
-    
-    public function onuOnuid() {
-        return $this->getSNMP()->lastOidWalk(self::OID_authOnuListOnuid,14);
-    }
-
     public function onuSerialNumber($index = null) {
         if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,14);
+            return $this->getSNMP()->lastOidWalk(self::OID_ontSN,14);
         } 
         
-        $values = $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,14);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontSN,14);
         return $this->convertIndex($index, $values);
     }
     
     public function onuPonRxOpticalPower($index = null) {
         if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_onuPonRxOpticalPower,15);
+            return $this->getSNMP()->lastOidWalk(self::OID_ontReceivedOpticalPower,14);
         } 
         
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonRxOpticalPower,15);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontReceivedOpticalPower,14);
         return $this->convertIndex($index, $values);
        
     }
     
     public function onuPonTxOpticalPower($index = null) {
         if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_onuPonTxOpticalPower,15);
+            return $this->getSNMP()->lastOidWalk(self::OID_ontMeanOpticalLaunchPower,14);
         } 
 
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonTxOpticalPower,15);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontMeanOpticalLaunchPower,14);
         return $this->convertIndex($index, $values);
     }
     
     public function onuPonOpticalVltage($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalVltage,15);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontPowerfeeedVoltage,14);
         return $this->convertIndex($index, $values);
     }
     
     public function onuPonOpticalTemperature($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalTemperature,15);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontTemperature,14);
         return $this->convertIndex($index, $values);
     }
     
     public function onuStatus($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuStatus,14);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontStatus,14);
+        return $this->convertIndex($index, $values);
+    }
+    
+    public function onuUptime($index = null) {
+        $values = $this->getSNMP()->lastOidWalk(self::OID_ontUpTime,14);
         return $this->convertIndex($index, $values);
     }
     
     /* OLT PON */
     public function oltPonDesc($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonDesc,15);
+        return $this->getSNMP()->lastOidWalk(self::OID_ponIndex,14);
     }
 
     public function oltPonEnableStatus($index = null) {