Jelajahi Sumber

Se añade nuevo comando para obtener stats de interfaces, se actualizan las OIDs.

Maxi Schvindt 7 tahun lalu
induk
melakukan
f057944c8d
3 mengubah file dengan 262 tambahan dan 5 penghapusan
  1. 84 0
      Command/CmtsCmStatsCommand.php
  2. 161 0
      Command/CmtsInterfaceStatsCommand.php
  3. 17 5
      SNMP/MIBS/OIDSBase.php

+ 84 - 0
Command/CmtsCmStatsCommand.php

@@ -0,0 +1,84 @@
+<?php
+
+namespace CmtsBundle\Command;
+
+use BaseStatsBundle\Command\BaseCmtsCommand;
+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 CmtsBundle\SNMP\SNMP as SNMP;
+
+class CmtsCmStatsCommand extends BaseCmtsCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('cmts:cm:stats')
+            ->setDescription('Escanear CMTS para obtener CMs')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1),
+                new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1),
+                new InputOption('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
+                new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
+                new InputOption('cmts-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_cmts_scan = "cmts_scan_{$this->d_s}";
+        $inicio = microtime(true);
+        
+        $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
+        $library = "use".$this->cmtsSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
+
+        $dataCached = array();
+        $countCms = 0;
+
+        $macs = $this->getSNMP("docsIfCmtsCmStatusMacAddress","cmMac");
+        $ips = $this->getSNMP("docsIfCmtsCmStatusIpAddress","cmIp");
+        $status = $this->getSNMP("docsIfCmtsCmStatusValue","cmStatus");
+
+        $up = $this->getSNMP("docsIfCmtsCmStatusUpChannelIfIndex","cmUpIf");
+        $down = $this->getSNMP("docsIfCmtsCmStatusDownChannelIfIndex","cmDownIf");
+
+
+        foreach($macs as $index => $mac) {
+            $countCms++; $data = array();
+            $data['mac'] = strtolower($mac);
+            (isset($ips[$index]))? $data['ip'] = $ips[$index] : $data['ip'] = null;
+            
+            /* $values = array(1 => 'other', 2 => 'ranging', 
+                            3 => 'rangingAborted', 4 => 'rangingComplete', 
+                            5 => 'ipComplete', 6 => 'registrationComplete', 7 => 'accessDenied'); */
+            (isset($status[$index]) && ($status[$index] == 6))? $data['status'] = 1 : $data['status'] = 0;
+
+            (isset($up[$index]))? $data['upInterface'] = $up[$index] : $data['upInterface'] = null;
+            (isset($down[$index]))? $data['downInterface'] = $down[$index] : $data['downInterface'] = null;
+
+            $dataCached[$index] = $data;
+        }
+
+        $this->setData($key_cmts_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos / Cantidad CMs: {$countCms}");
+        
+    }
+
+}

+ 161 - 0
Command/CmtsInterfaceStatsCommand.php

@@ -0,0 +1,161 @@
+<?php
+
+namespace CmtsBundle\Command;
+
+use BaseStatsBundle\Command\BaseCmtsCommand;
+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 CmtsBundle\SNMP\SNMP as SNMP;
+use Symfony\Component\Yaml\Parser;
+
+class CmtsInterfaceStatsCommand extends BaseCmtsCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('cmts:interface:stats')
+            ->setDescription('Obtener Stats de Interfaces')
+            ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
+            ->setDefinition(array(
+                new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1),
+                new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1),
+                new InputOption('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
+                new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
+                new InputOption('cmts-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_cmts_scan = "cmts_scan_ifs_{$this->d_s}";
+        $key_cm_scan = "cmts_scan_{$this->d_s}";
+        $inicio = microtime(true);
+        
+        $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
+        $library = "use".$this->cmtsSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
+
+        $dataCached = $this->getData($key_cmts_scan, true);
+        
+        if(empty($dataCached)) {
+            $this->output->writeln("Se requiere {$key_cmts_scan}.");
+            $this->removeLock($this->flag);
+            return true;
+        }
+        
+        
+        $_utilization = $this->getSNMP("docsIfCmtsChannelUtilization","cmtsIfUtilization");
+        $utilization = array();
+
+        foreach($_utilization as $compIndex => $value) {
+            $params = explode(".",$compIndex);
+            if($params > 1) {
+                $index = $params[0];
+                $aux = implode(".", array_slice($params,1));
+            } else {
+                $index = $compIndex;
+                $aux = 0;
+            }
+
+            $utilization[$index] = array($aux => $value);
+        }
+
+        $microreflection = $this->getSNMP("docsIfSigQMicroreflections","cmtsIfMicroreflection");
+        $signal = $this->getSNMP("docsIfSigQSignalNoise","cmtsIfSignal");
+
+        
+        print_r($utilization);
+        print_r($microreflection);
+        print_r($signal);
+
+
+        $cmCached = $this->getData($key_cm_scan, true);
+        $states = array();
+        if(empty($cmCached)) {
+            $this->output->writeln("Se requiere {$key_cm_scan} para obtener cantidad de CM por Interface.");
+        } else {
+            foreach($cmCached as $index => $value) {
+                $up = $value['upInterface'];
+                $down = $value['downInterface'];
+                $state = $value['status'];
+
+                if(!isset($states[$up])) $states[$up] = array(0 => 0, 1 => 0);
+                if(!isset($states[$down])) $states[$down] = array(0 => 0, 1 => 0);
+
+                $states[$up][$state]++;
+                $states[$down][$state]++;
+            }
+        }
+
+        $ifStatsCached = $sendData = array();
+
+        $subId = $this->d_s;
+        $metrics = array("utilization" => "{$subId}_if_utilization_", "microreflection" => "{$subId}_if_microreflection_", "signal" => "{$subId}_if_signal_", "states" => "{$subId}_if_state_");
+
+        foreach($dataCached as $index => $interface) {
+            
+            $stats = array();
+            
+            foreach($metrics as $data => $metric) {
+
+                if(!isset($$data[$index])) continue;
+
+                $m = "{$metric}{$index}";
+
+                if($data == "signal") {
+                    $v = $$data[$index] * 0.1;
+                    $sendData[$m] = "{$v}|g";
+                } elseif($data == "utilization") {
+                    foreach($$data[$index] as $aux => $v) {
+                        $sendData["{$m}.{$aux}"] = "{$v}|g";
+                    }
+                    $v = $$data[$index];
+                } elseif($data == "states") {
+                    $v = $$data[$index];
+                    $on = "{$subId}_if_state_on_{$index}";
+                    $off = "{$subId}_if_state_off_{$index}";
+                    
+                    $sendData[$on] = "{$v[1]}|g";
+                    $sendData[$off] = "{$v[0]}|g";
+                } else {
+                    $v = $$data[$index];
+                }
+                
+                $stats[$data] = $v;
+            }
+            $ifStatsCached[$index] = $stats;
+        }
+
+        print_r($ifStatsCached);
+        print_r($sendData);
+
+        die;
+
+        $dataCached = array();
+        $countIfs = 0;
+
+        $interfaces = $this->getSNMP("docsIfDescription","cmtsIf");
+        
+        
+
+        $this->setData($key_cmts_scan, $dataCached, true);
+
+        /* Fin de bloqueo */
+        $this->removeLock($this->flag);
+
+        $fin = microtime(true);
+        $time = $fin - $inicio;
+        $this->output->writeln("Tiempo: $time segundos / Cantidad Interfaces: {$countIfs}");
+    }
+
+}

+ 17 - 5
SNMP/MIBS/OIDSBase.php

@@ -14,11 +14,14 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
 
     
     const OID_docsIfCmtsCmStatusSignalNoise 	= "1.3.6.1.2.1.10.127.1.3.3.1.13";  //cm_index > snr en interface
-
-
+    
+    
     const OID_if_desc = "1.3.6.1.2.1.2.2.1.2";  //if_index > description
     const OID_system_description = '1.3.6.1.2.1.1.1.0';  //HOST SNMP DESCRIPTION
-
+    
+    const OID_docsIfCmtsChannelUtilization          = "1.3.6.1.2.1.10.127.1.3.9.1.3";
+    const OID_docsIfSigQMicroreflections            = "1.3.6.1.2.1.10.127.1.1.4.1.6";
+    const OID_docsIfSigQSignalNoise		            = "1.3.6.1.2.1.10.127.1.1.4.1.5";
 
 
     const OID_docsQosCmtsIfIndex                = "1.3.6.1.2.1.10.127.7.1.11.1.3";
@@ -30,8 +33,6 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
     const OID_docsIfCmStatusRxPower		= "1.3.6.1.2.1.10.127.1.1.1.1.6";
     const OID_docsIfCmtsCmStatusRxPower		= "1.3.6.1.2.1.10.127.1.3.3.1.6";
     const OID_docsQos3ServiceFlowOctets         = "1.3.6.1.4.1.4491.2.1.21.1.4.1.2";
-    const OID_docsIfSigQSignalNoise		= "1.3.6.1.2.1.10.127.1.1.4.1.5";
-    const OID_docsIfSigQMicroreflections        = "1.3.6.1.2.1.10.127.1.1.4.1.6";
     const docsIfCmtsChannelUtilization          = "1.3.6.1.2.1.10.127.1.3.9.1.3";
     const OID_ipNetToMediaPhysAddress 		= "1.3.6.1.2.1.4.22.1.2";
     const OID_docsIfCmtsCmPtr  			= "1.3.6.1.2.1.10.127.1.3.7.1.2";
@@ -72,6 +73,17 @@ class OIDSBase extends \CmtsBundle\SNMP\MIB {
         return $this->getSNMP()->lastOidWalk(self::OID_system_description,9);
     }
     
+    public function docsIfCmtsChannelUtilization() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsChannelUtilization,14);
+    }
+    
+    public function docsIfSigQMicroreflections() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQMicroreflections,14);
+    }
+    
+    public function docsIfSigQSignalNoise() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfSigQSignalNoise,14);
+    }