HuaweiOnuScanCommand.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace HuaweiBundle\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 HuaweiBundle\SNMP\SNMP as SNMP;
  8. //use RedisBundle\Services\RedisService;
  9. class HuaweiOnuScanCommand extends BaseCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('huawei: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. /* $slots = $SNMP->$library()->onuSlot();
  49. $pons = $SNMP->$library()->onuPon();
  50. $onus = $SNMP->$library()->onuOnuid(); */
  51. $serialNumbers = $SNMP->$library()->onuSerialNumber();
  52. print_r($serialNumbers);
  53. die;
  54. $countOnus = 0;
  55. foreach($onus as $index => $onuId) {
  56. $countOnus++;
  57. if(isset($slots[$index]) && isset($pons[$index]) && isset($serialNumbers[$index])) {
  58. $slot = $slots[$index]; $pon = $pons[$index]; $sn = strtolower($serialNumbers[$index]);
  59. $data = array();
  60. $data['slot'] = $slot;
  61. $data['port'] = $pon;
  62. $data['onuId'] = $onuId;
  63. $data['serialNumber'] = $sn;
  64. $data['ponport'] = "{$slot}/{$pon}/{$onuId}";
  65. $dataCached[$index] = $data;
  66. }
  67. }
  68. $this->setData($key_olt_scan, $dataCached, true);
  69. /* Fin de bloqueo */
  70. $this->removeLock($flag);
  71. $fin = microtime(true);
  72. $time = $fin - $inicio;
  73. $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
  74. }
  75. }