ZtePonScanCommand.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace ZteBundle\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 ZteBundle\SNMP\SNMP as SNMP;
  9. //use RedisBundle\Services\RedisService;
  10. class ZtePonScanCommand extends BaseCommand
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('zte:pon:scan')
  16. ->setDescription('Escanear OLT para obtener PON PORTs')
  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_pons_{$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 = $this->getData($key_olt_scan, true);
  40. $dataCached = array();
  41. $_ports = $this->getSNMP("oltPonDesc","ponScan");
  42. $_nexos = $this->getSNMP("oltPonNexo","ponScan");
  43. $gpons = array_values($_ports);
  44. $indexes = array_keys($_nexos);
  45. $countPons = 0;
  46. $aux = array();
  47. foreach($_ports as $index => $d) {
  48. if (preg_match("/gpon/i", $d)) {
  49. $s = str_replace(array("gpon","GPON","pon","PON"," ","_"),"",$d);
  50. $aux[$d] = $index;
  51. $s_p = explode("/",trim($s));
  52. if(count($s_p) == 3) {
  53. $countPons++;
  54. $b = $s_p[0];
  55. $s = $s_p[1];
  56. $p = $s_p[2];
  57. $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
  58. }
  59. }
  60. }
  61. foreach($gpons as $index => $d) {
  62. if (preg_match("/gpon/i", $d)) {
  63. if(isset($indexes[$index])) {
  64. $index = $indexes[$index];
  65. } else {
  66. continue;
  67. }
  68. $s = str_replace(array("gpon","GPON","pon","PON"," ","_"),"",$d);
  69. $s_p = explode("/",trim($s));
  70. if(count($s_p) == 3) {
  71. $countPons++;
  72. $b = $s_p[0];
  73. $s = $s_p[1];
  74. $p = $s_p[2];
  75. $dataCached[$index] = array("ponPort"=>"{$b}/{$s}/{$p}",'board'=>$b,'slot'=>$s,'port'=>$p);
  76. if(isset($aux[$d])) {
  77. $dataCached[$index]['nexo'] = $aux[$d];
  78. }
  79. }
  80. }
  81. }
  82. $this->setData($key_olt_scan, $dataCached, true);
  83. /* Fin de bloqueo */
  84. $this->removeLock($this->flag);
  85. $fin = microtime(true);
  86. $time = $fin - $inicio;
  87. $this->output->writeln("Tiempo: $time segundos / Cantidad Puertos: {$countPons}");
  88. }
  89. }