浏览代码

Se agrega comando para escanear interfaces del CMTS.

Maxi Schvindt 7 年之前
父节点
当前提交
901aa71609
共有 4 个文件被更改,包括 255 次插入34 次删除
  1. 22 19
      Command/CmtsCmScanCommand.php
  2. 101 0
      Command/CmtsInterfaceScanCommand.php
  3. 70 0
      Resources/config/cmts.yml
  4. 62 15
      SNMP/MIBS/OIDSBase.php

+ 22 - 19
Command/CmtsCmScanCommand.php

@@ -46,26 +46,29 @@ class CmtsCmScanCommand extends BaseCmtsCommand
         $dataCached = array();
         $countCms = 0;
 
-        /*
-        $slots = $this->getSNMP("onuSlot","onuSlot");
-        $pons = $this->getSNMP("onuPon","onuPon");
-        $onus = $this->getSNMP("onuOnuid","onuOnuid");
-        $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan");
-
-        foreach($onus as $index => $onuId) {
-            $countOnus++;
-            if(isset($slots[$index]) && isset($pons[$index]) && isset($serialNumbers[$index])) {
-                $slot = $slots[$index]; $pon = $pons[$index]; $sn = strtolower($serialNumbers[$index]);
-                $data = array();
-                $data['slot'] = $slot;
-                $data['port'] = $pon;
-                $data['onuId'] = $onuId;
-                $data['serialNumber'] = $sn;
-                $data['ponport'] = "{$slot}/{$pon}/{$onuId}";
-                $dataCached[$index] = $data;
-            }
+        $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);
 

+ 101 - 0
Command/CmtsInterfaceScanCommand.php

@@ -0,0 +1,101 @@
+<?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 CmtsInterfaceScanCommand extends BaseCmtsCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('cmts:interface:scan')
+            ->setDescription('Escanear CMTS para obtener 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}";
+        $inicio = microtime(true);
+        
+        $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
+        $library = "use".$this->cmtsSnmpLibrary;
+        $this->apiSNMP = $SNMP->$library();
+
+        $dataCached = array();
+        $countIfs = 0;
+
+        $interfaces = $this->getSNMP("docsIfDescription","cmtsIf");
+        $sysDesc = $this->getSNMP("systemDescription","cmtsDescription");
+        
+        $yaml = new Parser();
+	    $value = $yaml->parse(file_get_contents($cfg_file = dirname(__FILE__).'/../Resources/config/cmts.yml'));
+        $search = false;
+        if(isset($sysDesc[0])) {
+            $sysDesc = $sysDesc[0];
+
+	        foreach($value['interfaces'] as $key => $ifSearch){
+		        if(preg_match("|$key|", $sysDesc)){
+		        	$search = $ifSearch;
+		        	break;
+		        }
+            }
+
+            if(!$search) $this->output->writeln("Can't find any rule on $cfg_file matching the CMTS sysDesc : $sysDesc");
+        } else {
+            $this->output->writeln("Can't read OID_system_description of CMTS");
+        }
+
+        foreach($interfaces as $index => $name) {
+            $countIfs++;
+
+            $data = array('name' => $name, 'if_index' => $index, 'tr' => false,'rf' => false, 'cm' => false, 'upstream' => false, 'downstream' => false);
+            $match = false;
+            if($search) {
+                foreach($search as $skey => $values){
+                    if(preg_match("|$skey|", $name)){
+                        foreach($values as $k){ $data[$k] = true; }
+                        $match = true;
+                        break;
+                    }
+                }
+            }
+            
+            if(!$match) $data['tr'] = true;
+            
+            $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 Interfaces: {$countIfs}");
+    }
+
+}

+ 70 - 0
Resources/config/cmts.yml

@@ -0,0 +1,70 @@
+interfaces:
+   'Motorola DCM 2000': 
+     'Receiver' : ['cm','rf','tr']
+     'Transmitter' : ['cm','rf','tr'] 
+   'BSR 1000R\(tm\)':
+     'Downstream' : ['cm','tr','downstream'] 
+     'Upstream' :   ['cm','rf','tr','upstream']
+   'Cadant C3 CMTS' :
+     'DS' : ['tr','downstream']
+     'US CH' : ['cm','rf','tr','upstream']
+     'US IF' : ['tr','upstream']
+   'Cornerstone DOCSIS CMTS:1500' :
+     'ether0\d$' : ['tr']
+     'cable\d$' :  ['tr']
+     'cabledown$' : ['cm','tr']
+     'cableup\d$' : ['cm','rf','tr','upstream']
+   'CMTS_V0' :
+     'downstream' : ['cm','tr','downstream']
+     '^\d+.\d+ upstream \s\d+.*$' : ['cm','rf','tr','upstream']
+     '^upstream \s\d+$' : ['tr','upstream']
+     '^upstream \s\d+.\d+$' : ['tr','upstream']
+     '^upstream \s+\d+/\d+.\d+' : ['cm','rf','tr']
+     '^upstream \s\d+' : ['tr','upstream']
+     '^cable-upstream\s+\d+/\d+$' : ['tr', 'upstream']
+     '^cable-upstream\s+\d+/\d+\.\d+$' : ['cm','rf','tr','upstream']
+     'Ethernet' : ['tr']
+   'BSR 2000\(tm\)' :
+     'Downstream' : ['cm','tr','downstream']
+     'Cable Upstream - ' : ['tr']
+     'Logical Channel -' : ['cm','rf','tr','upstream']
+   'BW3500'  : 
+     'Downstream' : ['cm','tr','downstream']
+     'Upstream Channel' : ['cm','tr','rf','upstream']
+     'Upstream Inter' : ['tr','upstream']
+     'MAC' : ['tr']
+     'Backbone FastEthernet' : ['tr']
+   'UBR7100' :
+     'downstream' : ['cm','tr','downstream']
+     'upstream' : ['cm','rf','tr','upstream']
+   'UBR7200' :
+     'downstream' : ['cm','tr','downstream']
+     'upstream' : ['cm','rf','tr','upstream']
+   'CASA' :
+     'Downstream' : ['cm','tr','downstream']
+     'Upstream Physical' : ['tr','upstream']
+     'Logical Upstream' : ['cm','rf','tr','upstream']
+   'Linux CMC3' :
+     'Docsis' : ['tr']
+     'Downstream Total' : ['tr']
+     'Upstream Total' : ['cm','tr']
+     'Upstream \d+$' : ['cm','tr','rf','upstream']
+     'Downstream \d+$' : ['cm','tr','downstream']
+     'eth' : ['tr']
+     'sfp' : ['tr']
+   'JingHong CMTS Systems' :
+     'dmac0' : ['tr']
+     'us\d+$' : ['cm','tr','rf','upstream']
+     'ds\d+$' : ['cm','tr','downstream']
+   'UBR10K' :
+     'downstream\d+$' : ['cm','tr','downstream']
+     'upstream\d+$' : ['cm','tr','rf','upstream']
+     'Integrated-Cable\d+/\d+/\d+:\d+$' : ['tr']
+     'Cable\d+/\d+/\d+$' : ['tr']
+   'BSR 64000\(tm\)' :
+     'Downstream' : ['cm','tr','downstream']
+     'Cable Upstream - ' : ['tr']
+     'Logical Channel -' : ['cm','rf','tr','upstream']
+   'CC8800D-E' :
+     'US \d+$' : ['cm','tr','rf','upstream']
+     'DS \d+$' : ['cm','tr','downstream']

+ 62 - 15
SNMP/MIBS/OIDSBase.php

@@ -5,27 +5,74 @@ namespace CmtsBundle\SNMP\MIBS;
 
 class OIDSBase extends \CmtsBundle\SNMP\MIB {
     
-    const OID_mtxrQueueSimpleName      = "1.3.6.1.4.1.14988.1.1.2.1.1.2";
-    
-    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";
+    const OID_docsIfCmtsCmStatusMacAddress	= "1.3.6.1.2.1.10.127.1.3.3.1.2";  //cm_index > mac
+    const OID_docsIfCmtsCmStatusIpAddress	= "1.3.6.1.2.1.10.127.1.3.3.1.3";  //cm_index > ip
+    const OID_docsIfCmtsCmStatusValue		= "1.3.6.1.2.1.10.127.1.3.3.1.9";  //cm_index > state
+
+    const OID_docsIfCmtsCmStatusUpChannelIfIndex =  "1.3.6.1.2.1.10.127.1.3.3.1.5";  //cm_index > up interface
+    const OID_docsIfCmtsCmStatusDownChannelIfIndex = "1.3.6.1.2.1.10.127.1.3.3.1.4";  //cm_index > down interface
+
     
+    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
+
 
-    public function onuSerialNumber($index = null) {
-        if(is_null($index)) {
-            return $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleName,14);
-        } 
-        
-        $values = $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleName,14);
-        return $this->convertIndex($index, $values);
+
+    const OID_docsQosCmtsIfIndex                = "1.3.6.1.2.1.10.127.7.1.11.1.3";
+
+    const OID_docsQos3CmtsIfIndex		= "1.3.6.1.4.1.4491.2.1.21.1.11.1.3";
+    const OID_docsQosServiceFlowOctets		= "1.3.6.1.2.1.10.127.7.1.4.1.2";
+    const OID_docsQosServiceFlowDirection	= "1.3.6.1.2.1.10.127.7.1.3.1.7";
+    const OID_docsQos3ServiceFlowDirection	= "1.3.6.1.4.1.4491.2.1.21.1.3.1.7";
+    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";
+    const OID_docsIfCmStatusTxPower 		= "1.3.6.1.2.1.10.127.1.2.2.1.3";
+    const OID_docsIfDownChannelFrequency	= "1.3.6.1.2.1.10.127.1.1.1.1.2";
+    const OID_docsIfDownChannelModulation       = "1.3.6.1.2.1.10.127.1.1.1.1.4";
+    const OID_docsIfDownChannelPower		= "1.3.6.1.2.1.10.127.1.1.1.1.6";
+    const OID_docsIfUpChannelFrequency		= "1.3.6.1.2.1.10.127.1.1.2.1.2";
+    const OID_docsIfUpChannelWidth 		= "1.3.6.1.2.1.10.127.1.1.2.1.3";
+    
+    
+    
+    public function docsIfCmtsCmStatusMacAddress() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsCmStatusMacAddress,14);
     }
     
-    public function onuInOctets() {
-        return $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleBytesIn,14);
+    public function docsIfCmtsCmStatusValue() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsCmStatusValue,14);
     }
     
-    public function onuOutOctets() {
-        return $this->getSNMP()->lastOidWalk(self::OID_mtxrQueueSimpleBytesOut,14);
+    public function docsIfCmtsCmStatusIpAddress() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsCmStatusIpAddress,14);
     }
     
+    public function docsIfCmtsCmStatusUpChannelIfIndex() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsCmStatusUpChannelIfIndex,14);
+    }
+    
+    public function docsIfCmtsCmStatusDownChannelIfIndex() {
+        return $this->getSNMP()->lastOidWalk(self::OID_docsIfCmtsCmStatusDownChannelIfIndex,14);
+    }
+    
+    public function docsIfDescription() {
+        return $this->getSNMP()->lastOidWalk(self::OID_if_desc,11);
+    }
+    
+    public function systemDescription() {
+        return $this->getSNMP()->lastOidWalk(self::OID_system_description,9);
+    }
+    
+
+    
+    
 }