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}"); } }