HuaweiPonScanCommand.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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("gpon","GPON","pon","PON"," "),"",$d);
  54. $s_p = explode("/",trim($s));
  55. if(count($s_p) == 3) {
  56. $countPons++;
  57. $b = $s_p[0];
  58. $s = $s_p[1];
  59. $p = $s_p[2];
  60. $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
  61. }
  62. }
  63. }
  64. $this->setData($key_olt_scan, $dataCached, true);
  65. /* Fin de bloqueo */
  66. $this->removeLock($flag);
  67. $fin = microtime(true);
  68. $time = $fin - $inicio;
  69. $this->output->writeln("Tiempo: $time segundos / Cantidad Puertos: {$countPons}");
  70. }
  71. }