FiberhomeOnuScanCommand.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace FiberhomeBundle\Command;
  3. use BaseStatsBundle\Command\BaseCommand;
  4. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use FiberhomeBundle\SNMP\SNMP as SNMP;
  9. //use RedisBundle\Services\RedisService;
  10. class FiberhomeOnuScanCommand extends BaseCommand
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('fiberhome:onu:scan')
  16. ->setDescription('Escanear OLT para obtener ONUs')
  17. ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
  18. ->setDefinition(array(
  19. new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1),
  20. new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1),
  21. new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"),
  22. new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"),
  23. new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
  24. ))
  25. ;
  26. }
  27. /**
  28. * @param InputInterface $input
  29. * @param OutputInterface $output
  30. */
  31. protected function execute(InputInterface $input, OutputInterface $output)
  32. {
  33. parent::execute($input, $output);
  34. $key_olt_scan = "olt_scan_{$this->d_s}";
  35. $inicio = microtime(true);
  36. $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
  37. $library = "use".$this->oltSnmpLibrary;
  38. $this->apiSNMP = $SNMP->$library();
  39. $dataCached = array();
  40. $slots = $this->getSNMP("onuSlot","onuSlot");
  41. $pons = $this->getSNMP("onuPon","onuPon");
  42. $onus = $this->getSNMP("onuOnuid","onuOnuid");
  43. $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan");
  44. $countOnus = 0;
  45. foreach($onus as $index => $onuId) {
  46. $countOnus++;
  47. if(isset($slots[$index]) && isset($pons[$index]) && isset($serialNumbers[$index])) {
  48. $slot = $slots[$index]; $pon = $pons[$index]; $sn = strtolower($serialNumbers[$index]);
  49. $data = array();
  50. $data['slot'] = $slot;
  51. $data['port'] = $pon;
  52. $data['onuId'] = $onuId;
  53. $data['serialNumber'] = $sn;
  54. $data['ponport'] = "{$slot}/{$pon}/{$onuId}";
  55. $dataCached[$index] = $data;
  56. }
  57. }
  58. $this->setData($key_olt_scan, $dataCached, true);
  59. /* Fin de bloqueo */
  60. $this->removeLock($this->flag);
  61. $fin = microtime(true);
  62. $time = $fin - $inicio;
  63. $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
  64. }
  65. }