Browse Source

Se agrega comando para octetos por nas.

Maxi Schvindt 7 năm trước cách đây
mục cha
commit
516b436604
2 tập tin đã thay đổi với 98 bổ sung154 xóa
  1. 87 8
      Command/NasOnuOctetsCommand.php
  2. 11 146
      SNMP/MIBS/OIDSBase.php

+ 87 - 8
Command/NasOnuOctetsCommand.php

@@ -13,6 +13,16 @@ use NasBundle\SNMP\SNMP as SNMP;
 class NasOnuOctetsCommand extends BaseCommand
 {
 
+    protected $nasDeviceId;
+    protected $nasServerId;
+    protected $nasIp;
+    protected $nasCommunity;
+    protected $nasSnmpLibrary;
+    protected $flag;
+    protected $apiSNMP;
+    protected $inicio;
+    protected $fin;
+
     protected function configure()
     {
         $this
@@ -36,30 +46,56 @@ class NasOnuOctetsCommand extends BaseCommand
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        parent::execute($input, $output);
+
+        $this->inicio = microtime(true);
+        $this->output = $output;
+        $this->setCollector();
+        
+        $msg = PHP_EOL."################################################# (".date("Y-m-d H:i:s").")";
+        $this->output->writeln($msg);
+        
+        $this->nasDeviceId = (int) $input->getOption('nas-device-id');
+        $this->nasServerId = (int) $input->getOption('nas-server-id');
+        $this->nasIp = $input->getOption('nas-ip');
+        $this->nasCommunity = $input->getOption('nas-community');
+        $this->nasSnmpLibrary = $input->getOption('nas-snmp-library');
+        $this->d_s = "d_{$this->nasDeviceId}_s_{$this->nasServerId}";
+        
+        $cmd = str_replace(":","_",$this->getName());
+        $this->output->writeln("INICIO COMANDO {$cmd} | {$this->d_s}");
+        
+        $this->flag = "{$this->d_s}_cmd_$cmd";
+        
+        if($this->lock($this->flag)) {exit(1);}
         
-        $key_olt_scan = "olt_scan_{$this->d_s}";
-        $key_olt_onu_bandwidth = "olt_bandwidth_onu_{$this->d_s}";
+        $key_nas_scan = "nas_scan_{$this->d_s}";
+        $key_nas_onu_bandwidth = "nas_bandwidth_onu_{$this->d_s}";
         $saveHistoric = (int) $input->getOption('save-historic');
         $inicio = microtime(true);
 
-        $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
-        $library = "use".$this->oltSnmpLibrary;
+        $SNMP = new SNMP($this->nasIp, $this->nasCommunity);
+        $library = "use".$this->nasSnmpLibrary;
         $this->apiSNMP = $SNMP->$library();
         
-        $dataCached = $this->getData($key_olt_scan, true);
-        $bandwidthCached = $this->getData($key_olt_onu_bandwidth, true);
+        $dataCached = $this->getData($key_nas_scan, true);
+        $bandwidthCached = $this->getData($key_nas_onu_bandwidth, true);
 
         if(empty($dataCached)) {
-            $this->output->writeln("Se requiere {$key_olt_scan}.");
+            $this->output->writeln("Se requiere {$key_nas_scan}.");
             $this->removeLock($this->flag);
             return true;
         }
 
+        $onus = $this->getSNMP("onuSerialNumber","onuSerialNumber");
+        
         //counter64
         $inOctets = $this->getSNMP("onuInOctets","onuInOctets");
         $outOctets = $this->getSNMP("onuOutOctets","onuOutOctets");
 
+
+        print_r($onus);
+
+        /*
         $sendData = array();
 
         $subId = $this->d_s;
@@ -124,6 +160,8 @@ class NasOnuOctetsCommand extends BaseCommand
             print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: ".count($sendData).PHP_EOL);
         }
 
+        */
+
         /* Fin de bloqueo */
         $this->removeLock($this->flag);
 
@@ -133,4 +171,45 @@ class NasOnuOctetsCommand extends BaseCommand
         
     }
 
+    /**
+     * 
+     * @param string $function
+     * @param string $log
+     * @return array
+     * 
+     * Description: Ejecuta SNMP mientras se mide tiempo y errores
+     */
+    protected function getSNMP($function, $log) {
+        
+        $inicio = microtime(true);
+        $error = array();
+        try {
+            $data = $this->apiSNMP->$function();   
+        }  catch (\Exception $e) {
+            $error['msg'] = $e->getMessage();
+            $data = array();
+            //LOG REPORT ERROR
+        }
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        
+        $statsdService = $this->getContainer()->get('statsd');
+        $m = "{$this->d_s}_snmp_$log";
+        $statsdService->send(array($m => "{$time}|g"));
+        
+        $this->output->writeln("Tiempo {$function} / {$log}: $time segundos");
+
+        if($error) {
+            $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
+            $device = $doctrine->getRepository('\StatsBundle\Entity\Device')->findOneBy(array('deviceServer' => $this->nasServerId, 'deviceType' => 'RadiusBundle\Entity\NAS', 'deviceId' => $this->nasDeviceId));
+            if($device) {
+                $reportManager = $this->getContainer()->get('stats.report.manager');
+                $reportManager->create("RadiusBundle\Entity\NAS", "SNMP_ERROR", $this->nasDeviceId, $this->nasServerId, $device->getTenancyId(), $error);
+            }
+            
+        }
+        return $data;
+
+    }
+
 }

+ 11 - 146
SNMP/MIBS/OIDSBase.php

@@ -1,166 +1,31 @@
 <?php
 
+// MikroTik - http://www.oidview.com/mibs/14988/MIKROTIK-MIB.html
 namespace NasBundle\SNMP\MIBS;
 
-class OIDSFiberHomeV1 extends \NasBundle\SNMP\MIB {
+class OIDSBase extends \NasBundle\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.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_mtxrQueueSimpleIndex      = "1.3.6.1.4.1.14988.1.1.2.1.1.1";
     
-    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";
+    const OID_mtxrQueueSimpleBytesIn    = "1.3.6.1.4.1.14988.1.1.2.1.1.8";
+    const OID_mtxrQueueSimpleBytesOut   = "1.3.6.1.4.1.14988.1.1.2.1.1.9";
     
-    
-    //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";
-
-    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) {
-        $data = array();
-        foreach($values as $i => $v) {
-            if(isset($index[$i])) {
-                $data[$index[$i]] = $v;
-            }
-        }
-        if(!empty($index)) return $data;
-        
-        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);
-        } 
-        
-        $values = $this->getSNMP()->lastOidWalk(self::OID_authOnuListMac,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_mtxrQueueSimpleIndex,14);
         } 
         
-        $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,15);
-        } 
-
-        $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,15);
-        return $this->convertIndex($index, $values);
-    }
-    
-    public function onuPonOpticalTemperature($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuPonOpticalTemperature,15);
+        $values = $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleIndex,14);
         return $this->convertIndex($index, $values);
     }
     
-    public function onuStatus($index = null) {
-        $values = $this->getSNMP()->lastOidWalk(self::OID_onuStatus,14);
-        return $this->convertIndex($index, $values);
-    }
-    
-    /* OLT PON */
-    public function oltPonDesc($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonDesc,15);
-    }
-
-    public function oltPonEnableStatus($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonEnableStatus,15);
-//        return $this->convertIndex($index, $values);
-    }
-    
-    public function oltPonRxOpticalPower($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonRxOpticalPower,15);
-//        return $this->convertIndex($index, $values);
-    }
-    
-    public function oltPonTxOpticalPower($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonTxOpticalPower,15);
-//        return $this->convertIndex($index, $values);
-    }
-    
-    public function oltPonOpticalVltage($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalVltage,15);
-//        return $this->convertIndex($index, $values);
-    }
-    
-    public function oltPonOpticalCurrent($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalCurrent,15);
-//        return $this->convertIndex($index, $values);
-    }
-    
-    public function oltPonOpticalTemperature($index = null) {
-        return $this->getSNMP()->lastOidWalk(self::OID_oltPonOpticalTemperature,15);
-//        return $this->convertIndex($index, $values);
-    }
-    
-    public function ifInOctets() {
-        return $this->getSNMP()->lastOidWalk(self::OID_ifInOctets,11);
-    }
-    
-    public function ifOutOctets() {
-        return $this->getSNMP()->lastOidWalk(self::OID_ifOutOctets,11);
+    public function onuInOctets() {
+        return $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleBytesIn,14);
     }
     
-    public function ifHCInOctets() {
-        return $this->getSNMP()->lastOidWalk(self::OID_ifHCInOctets,12);
+    public function onuOutOctets() {
+        return $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleBytesOut,14);
     }
     
-    public function ifHCOutOctets() {
-        return $this->getSNMP()->lastOidWalk(self::OID_ifHCOutOctets,12);
-    }
-    
-    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);
-    }
 }