FiberlinkOnuScanCommand.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace FiberlinkBundle\Command;
  3. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  4. use Symfony\Component\Console\Input\InputOption;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. use FiberlinkBundle\SNMP\SNMP as SNMP;
  8. //use RedisBundle\Services\RedisService;
  9. class FiberlinkOnuScanCommand extends BaseCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('fiberlink:onu:scan')
  15. ->setDescription('Escanear OLT para obtener ONUs')
  16. ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
  17. ->setDefinition(array(
  18. new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
  19. new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
  20. new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
  21. new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
  22. new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
  23. ))
  24. ;
  25. }
  26. /**
  27. * @param InputInterface $input
  28. * @param OutputInterface $output
  29. */
  30. protected function execute(InputInterface $input, OutputInterface $output)
  31. {
  32. parent::execute($input, $output);
  33. $this->output->writeln("INICIO");
  34. $inicio = microtime(true);
  35. $oltDeviceId = (int) $input->getOption('olt-device-id');
  36. $oltServerId = (int) $input->getOption('olt-server-id');
  37. $oltIp = $input->getOption('olt-ip');
  38. $oltCommunity = $input->getOption('olt-community');
  39. $oltSnmpLibrary = $input->getOption('olt-snmp-library');
  40. $flag = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}.lock";
  41. $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
  42. /* Control de bloqueo */
  43. if($this->lock($flag)) {return;}
  44. $SNMP = new SNMP($oltIp, $oltCommunity);
  45. $library = "use".$oltSnmpLibrary;
  46. //$dataCached = $this->getData($key_olt_scan, true);
  47. $dataCached = array();
  48. $serialNumbers = $SNMP->$library()->onuSerialNumber();
  49. $countOnus = 0;
  50. foreach($serialNumbers as $index => $serialNumber) {
  51. $ponPort = explode(".",$index);
  52. if(count($ponPort) != 3) continue;
  53. $s = $ponPort[0];
  54. $p = $ponPort[1];
  55. $o = $ponPort[2];
  56. //$index = $s.$p.$o;
  57. $sn = strtolower($serialNumber);
  58. $countOnus++;
  59. $data = array();
  60. $data['slot'] = $s;
  61. $data['port'] = $p;
  62. $data['onuId'] = $o;
  63. $data['serialNumber'] = $sn;
  64. $data['ponport'] = "{$s}/{$p}/{$o}";
  65. $dataCached[$index] = $data;
  66. }
  67. $this->setData($key_olt_scan, $dataCached, true);
  68. /* Fin de bloqueo */
  69. $this->removeLock($flag);
  70. $fin = microtime(true);
  71. $time = $fin - $inicio;
  72. $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
  73. }
  74. }