Преглед изворни кода

Se agrega comando para obtener CPU y RAM de Card OLT u OLT en su defecto
o lo que se consiguió.

Maximiliano Schvindt пре 7 година
родитељ
комит
1ee065bd7a
2 измењених фајлова са 97 додато и 0 уклоњено
  1. 81 0
      Command/FiberlinkOltScanCommand.php
  2. 16 0
      SNMP/MIBS/OIDSFiberLinkV1.php

+ 81 - 0
Command/FiberlinkOltScanCommand.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace FiberlinkBundle\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 FiberlinkBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class FiberlinkOltScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('fiberlink: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");  //over 100
+        $memoryTotal = $this->getSNMP("oltCardMemory","cardMemory");  //over 100
+        $memoryFree = $this->getSNMP("oltCardFreeMemory","cardMemory");  //over 100
+
+        $_memory = $_cpu = array();
+        foreach($cpu as $index => $value) {$_cpu[$index] = $value;}
+        
+        foreach($memoryTotal as $index => $value) {
+            if(isset($memoryFree[$index]) && $value > 0) {
+                $used = (($value - $memoryFree[$index]) / $value) * 100;
+                $_memory[$index] = number_format($used, 2, ".", "");
+            } else {
+                $_memory[$index] = 0;
+            }
+
+        }
+
+        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");
+        
+    }
+
+}

+ 16 - 0
SNMP/MIBS/OIDSFiberLinkV1.php

@@ -35,6 +35,10 @@ 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_cardCpu                   = "1.3.6.1.4.1.13464.1.2.1.1.2.11";
+    const OID_cardMemory                = "1.3.6.1.4.1.13464.1.2.1.1.2.12";
+    const OID_cardFreeMemory            = "1.3.6.1.4.1.13464.1.2.1.1.2.13";
+
     function convertIndex($index, $values) {
         $data = array();
         foreach($values as $i => $v) {
@@ -149,4 +153,16 @@ class OIDSFiberLinkV1 extends \FiberlinkBundle\SNMP\MIB {
     public function ifDescr() {
         return $this->getSNMP()->lastOidWalk(self::OID_ifDescr,11);
     }
+
+    public function oltCardCpu($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_cardCpu,14);
+    }
+    
+    public function oltCardMemory($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_cardMemory,14);
+    }
+
+    public function oltCardFreeMemory($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_cardFreeMemory,14);
+    }
 }