123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace ZteBundle\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 ZteBundle\SNMP\SNMP as SNMP;
- //use RedisBundle\Services\RedisService;
- class ZtePonScanCommand extends BaseCommand
- {
- protected function configure()
- {
- $this
- ->setName('zte:pon:scan')
- ->setDescription('Escanear OLT para obtener PON PORTs')
- ->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_pons_{$this->d_s}";
- $inicio = microtime(true);
-
- $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
- $library = "use".$this->oltSnmpLibrary;
- $this->apiSNMP = $SNMP->$library();
- $dataCached = $this->getData($key_olt_scan, true);
- $dataCached = array();
- $_ports = $this->getSNMP("oltPonDesc","ponScan");
- $_nexos = $this->getSNMP("oltPonNexo","ponScan");
- $gpons = array_values($_ports);
- $indexes = array_keys($_nexos);
- $countPons = 0;
- $aux = array();
- foreach($_ports as $index => $d) {
- if (preg_match("/gpon/i", $d)) {
- $s = str_replace(array("gpon","GPON","pon","PON"," ","_"),"",$d);
- $aux[$d] = $index;
- $s_p = explode("/",trim($s));
- if(count($s_p) == 3) {
- $countPons++;
- $b = $s_p[0];
- $s = $s_p[1];
- $p = $s_p[2];
-
- $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
- }
- }
- }
- foreach($gpons as $index => $d) {
- if (preg_match("/gpon/i", $d)) {
- if(isset($indexes[$index])) {
- $index = $indexes[$index];
- } else {
- continue;
- }
- $s = str_replace(array("gpon","GPON","pon","PON"," ","_"),"",$d);
- $s_p = explode("/",trim($s));
- if(count($s_p) == 3) {
- $countPons++;
- $b = $s_p[0];
- $s = $s_p[1];
- $p = $s_p[2];
-
- $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
- if(isset($aux[$d])) {
- $dataCached[$index]['nexo'] = $aux[$d];
- }
- }
- }
- }
- $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 / Cantidad Puertos: {$countPons}");
-
- }
- }
|