Просмотр исходного кода

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

Maximiliano Schvindt 7 лет назад
Родитель
Сommit
774cba9b5c
2 измененных файлов с 83 добавлено и 0 удалено
  1. 72 0
      Command/FiberhomeOltScanCommand.php
  2. 11 0
      SNMP/MIBS/OIDSFiberHomeV1.php

+ 72 - 0
Command/FiberhomeOltScanCommand.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace FiberhomeBundle\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 FiberhomeBundle\SNMP\SNMP as SNMP;
+//use RedisBundle\Services\RedisService;
+
+class FiberhomeOltScanCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('fiberhome: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
+        $memory = $this->getSNMP("oltCardMemory","cardMemory");  //over 100
+
+        $_memory = $_cpu = array();
+        foreach($cpu as $index => $value) {$_cpu[$index] = number_format(($value/100), 2, '.', '');}
+        
+        foreach($memory as $index => $value) {$_memory[$index] = number_format(($value/100), 2, '.', '');}
+
+        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");
+        
+    }
+
+}

+ 11 - 0
SNMP/MIBS/OIDSFiberHomeV1.php

@@ -29,6 +29,9 @@ class OIDSFiberHomeV1 extends \FiberhomeBundle\SNMP\MIB {
     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";
+
+    const OID_cardCpu                             = "1.3.6.1.4.1.5875.800.3.9.8.1.1.5";
+    const OID_cardMemory                          = "1.3.6.1.4.1.5875.800.3.9.8.1.1.6";
     
 
     function convertIndex($index, $values) {
@@ -152,4 +155,12 @@ class OIDSFiberHomeV1 extends \FiberhomeBundle\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,15);
+    }
+    
+    public function oltCardMemory($index = null) {
+        return $this->getSNMP()->lastOidWalk(self::OID_cardMemory,15);
+    }
 }