HuaweiOnuScanCommand.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Flowdat\Stats\Command\Huawei;
  3. use Flowdat\Stats\App\Service\Huawei\HuaweiService;
  4. use Flowdat\Stats\App\Service\Stats\StatsService;
  5. use Flowdat\Stats\Command\Base\BaseCommand;
  6. use Flowdat\Stats\SNMP\Huawei\SNMP as SNMP;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Input\InputOption;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. class HuaweiOnuScanCommand extends BaseCommand
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('huawei:onu:scan')
  16. ->setDescription('Scan de ONUs de OLT')
  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. new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD", 1)
  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. $saveHistoric = (int)$input->getOption('save-historic');
  35. /*Definir o SNMP*/
  36. $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
  37. $library = "use".$this->oltSnmpLibrary;
  38. /*Definição das KEYS*/
  39. $keyOltScan = "olt_scan_{$this->d_s}";
  40. $keyOltScanPon = "olt_scan_pons_{$this->d_s}";
  41. $keyOltBandwidthOnu = "olt_bandwidth_onu_{$this->d_s}";
  42. $huaweiService = new HuaweiService($SNMP->$library(), $output, $this->flag);
  43. $huaweiService
  44. ->searchPonAndSaveCache($keyOltScanPon)
  45. ->searchNumberSerialAndSaveCache($keyOltScan, $keyOltScanPon)
  46. ->searchInformationsAboutOnuAndSave($keyOltScan, $keyOltBandwidthOnu, $this->oltServerId, $this->oltDeviceId, $this->d_s, $saveHistoric);
  47. $statsService = new StatsService();
  48. $statsService->updateStatsOnu($this->oltDeviceId, $this->oltServerId);
  49. }
  50. }