CmtsCmScanCommand.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace CmtsBundle\Command;
  3. use BaseStatsBundle\Command\BaseCmtsCommand;
  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 CmtsBundle\SNMP\SNMP as SNMP;
  9. class CmtsCmScanCommand extends BaseCmtsCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('cmts:cm:scan')
  15. ->setDescription('Escanear CMTS para obtener CMs')
  16. ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
  17. ->setDefinition(array(
  18. new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1),
  19. new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1),
  20. new InputOption('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
  21. new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
  22. new InputOption('cmts-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. $key_cmts_scan = "cmts_scan_{$this->d_s}";
  34. $inicio = microtime(true);
  35. $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
  36. $library = "use".$this->cmtsSnmpLibrary;
  37. $this->apiSNMP = $SNMP->$library();
  38. $dataCached = array();
  39. $countCms = 0;
  40. /*
  41. $slots = $this->getSNMP("onuSlot","onuSlot");
  42. $pons = $this->getSNMP("onuPon","onuPon");
  43. $onus = $this->getSNMP("onuOnuid","onuOnuid");
  44. $serialNumbers = $this->getSNMP("onuSerialNumber","onuScan");
  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. */
  59. $this->setData($key_cmts_scan, $dataCached, true);
  60. /* Fin de bloqueo */
  61. $this->removeLock($this->flag);
  62. $fin = microtime(true);
  63. $time = $fin - $inicio;
  64. $this->output->writeln("Tiempo: $time segundos / Cantidad CMs: {$countCms}");
  65. }
  66. }