FiberhomeOnuScanCommand.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace FiberhomeBundle\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 FiberhomeBundle\SNMP\SNMP as SNMP;
  8. //use RedisBundle\Services\RedisService;
  9. class FiberhomeOnuScanCommand extends BaseCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('fiberhome: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-device-tenancy-id', null, InputOption::VALUE_OPTIONAL, "TenancyId 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. $time = time();
  36. $oltDeviceId = (int) $input->getOption('olt-device-id');
  37. $oltDeviceTenancyId = (int) $input->getOption('olt-device-tenancy-id');
  38. $oltIp = $input->getOption('olt-ip');
  39. $oltCommunity = $input->getOption('olt-community');
  40. $oltSnmpLibrary = $input->getOption('olt-snmp-library');
  41. /* Control de bloqueo */
  42. $flag = "olt_{$oltDeviceId}_{$oltDeviceTenancyId}.lock";
  43. if($this->lock($flag)) {return;}
  44. //$aux = snmp2_real_walk("190.110.248.2", "LoLtawah", "1.3.6.1.4.1.5875.800.3.10.1.1.10", 100000000, 5);
  45. //print_r($aux);
  46. $SNMP = new SNMP($oltIp, $oltCommunity);
  47. $library = "use".$oltSnmpLibrary;
  48. $interfaces = $SNMP->$library()->ifDescr();
  49. //$parameters = ['tcp://127.0.0.1:6379'];
  50. //$redis->setOptions($options);
  51. //$redis->setConnection($parameters);
  52. $value = $this->collector->getString('clave',true);
  53. $output->writeln($value);
  54. $this->removeLock($flag);
  55. }
  56. }