Переглянути джерело

Se actualiza los métodos con sus OIDs y se agrega el comando para
obtener datos de los puertos pon.

Maximiliano Schvindt 7 роки тому
батько
коміт
77174454e2
2 змінених файлів з 135 додано та 34 видалено
  1. 128 0
      Command/FiberlinkPonStatsCommand.php
  2. 7 34
      SNMP/MIBS/OIDSFiberLinkV1.php

+ 128 - 0
Command/FiberlinkPonStatsCommand.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 FiberlinkPonStatsCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('fiberlink: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);
+        
+        $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_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;
+
+        $dataCached = $this->getData($key_olt_scan, true);
+
+        if(empty($dataCached)) {
+            $this->output->writeln("Se requiere {$key_olt_scan}.");
+            $this->removeLock($flag);
+            return true;
+        }
+
+        //return [PONINDEX] => value
+        $rxPower = $SNMP->$library()->oltPonRxOpticalPower();
+        $txPower = $SNMP->$library()->oltPonTxOpticalPower();
+        $temperature = $SNMP->$library()->oltPonOpticalTemperature();
+        $voltage = $SNMP->$library()->oltPonOpticalVltage();
+        $biasCurrent = $SNMP->$library()->oltPonOpticalCurrent();
+
+        $ponStatsCached = $sendData = array();
+
+        $subId = "d_{$oltDeviceId}_s_{$oltServerId}";
+        $metrics = array("rxPower" => "{$subId}_pon_rx_", "txPower" => "{$subId}_pon_tx_", "temperature" => "{$subId}_pon_temperature_", "voltage" => "{$subId}_pon_voltage_", "biasCurrent" => "{$subId}_pon_biascurrent_");
+
+        foreach($dataCached as $index => $pon) {
+            $ponPort = $index;
+            
+            $stats = array();
+            $stats['ponPort'] = "{$pon['slot']}/{$pon['port']}";
+            
+            foreach($metrics as $data => $metric) {
+                
+                if(isset($$data[$index]) && !empty($$data[$index])) {
+                    
+                    $m = "{$metric}{$ponPort}";
+                    $v = $$data[$index];
+                    if($data == "rxPower") {
+                        $stats[$data] = array(0 => $v);
+                    } else {
+                        $stats[$data] = $v;
+                    }
+                    
+                    $sendData[$m] = "{$v}|g";
+                }
+            }
+            
+            $ponStatsCached[$index] = $stats;
+        }
+
+        if($ponStatsCached) {
+            $key_pon_stats = "olt_stats_pons_d_{$oltDeviceId}_s_{$oltServerId}";
+            $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($flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos");
+        
+    }
+
+}

+ 7 - 34
SNMP/MIBS/OIDSFiberLinkV1.php

@@ -14,9 +14,11 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
     const OID_ponBiasCurrent            = "1.3.6.1.4.1.13464.1.11.3.1.1.21";
     const OID_ponRXPower                = "1.3.6.1.4.1.13464.1.11.3.1.1.24";
     const OID_ponTXPower                = "1.3.6.1.4.1.13464.1.11.3.1.1.27";
+    
     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_ifDescr                   = "1.3.6.1.2.1.2.2.1.2";
+
     const OID_ontSN                     = "1.3.6.1.4.1.13464.1.11.4.1.1.2";
     const OID_ontStatus                 = "1.3.6.1.4.1.13464.1.11.4.1.1.3";
     const OID_ontReason                 = "1.3.6.1.4.1.13464.1.11.4.1.1.7";
@@ -32,35 +34,6 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
     const OID_ontDistance               = "1.3.6.1.4.1.13464.1.11.4.1.1.32";
     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";
-    const OID_authOnuListMac                = "1.3.6.1.4.1.5875.800.3.10.1.1.10";
-    const OID_onuPonRxOpticalPower                = "1.3.6.1.4.1.5875.800.3.9.3.3.1.6";
-    const OID_onuPonTxOpticalPower                = "1.3.6.1.4.1.5875.800.3.9.3.3.1.7";
-    const OID_onuPonOpticalVltage                 = "1.3.6.1.4.1.5875.800.3.9.3.3.1.8";
-    const OID_onuPonOpticalTemperature            = "1.3.6.1.4.1.5875.800.3.9.3.3.1.10";
-    const OID_onuStatus                           = "1.3.6.1.4.1.5875.800.3.10.1.1.11";
-    const OID_oltPonDesc                          = "1.3.6.1.4.1.5875.800.3.9.3.4.1.3";
-    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.5875.800.3.9.3.7.1.2";
-    const OID_oltPonTxOpticalPower                = "1.3.6.1.4.1.5875.800.3.9.3.4.1.8";
-    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();
@@ -133,27 +106,27 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
     }
     
     public function oltPonRxOpticalPower($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonRxOpticalPower,15);
+        return $this->getSNMP()->lastOidWalk(self::OID_ponRXPower,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonTxOpticalPower($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonTxOpticalPower,15);
+        return $this->getSNMP()->lastOidWalk(self::OID_ponTXPower,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonOpticalVltage($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalVltage,15);
+        return $this->getSNMP()->lastOidWalk(self::OID_ponVoltage,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonOpticalCurrent($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalCurrent,15);
+        return $this->getSNMP()->lastOidWalk(self::OID_ponBiasCurrent,14);
 //        return $this->convertIndex($index, $values);
     }
     
     public function oltPonOpticalTemperature($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalTemperature,15);
+        return $this->getSNMP()->lastOidWalk(self::OID_ponTemperature,14);
 //        return $this->convertIndex($index, $values);
     }