HuaweiPonScanCommand.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 HuaweiPonScanCommand extends BaseCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('huawei:pon:scan')
  15. ->setDescription('Escanear OLT para obtener PON PORTs')
  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_pons_d_{$oltDeviceId}_s_{$oltServerId}.lock";
  41. $key_olt_scan = "olt_scan_pons_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. $ports = $SNMP->$library()->oltPonDesc();
  49. $countPons = 0;
  50. foreach($ports as $index => $d) {
  51. //PON s/p
  52. if (preg_match("/pon/i", $d)) {
  53. $s = str_replace(array("pon","PON"," "),"",$d);
  54. $s_p = explode("/",trim($s));
  55. if(count($s_p) == 2) {
  56. $countPons++;
  57. $s = $s_p[0];
  58. $p = $s_p[1];
  59. $dataCached[$index] = array("ponPort"=>"{$s}/{$p}",'slot'=>$s,'port'=>$p);
  60. }
  61. }
  62. }
  63. $this->setData($key_olt_scan, $dataCached, true);
  64. /* Fin de bloqueo */
  65. $this->removeLock($flag);
  66. $fin = microtime(true);
  67. $time = $fin - $inicio;
  68. $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countPons}");
  69. }
  70. }