FurukawaOltScanCommand.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace FurukawaBundle\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 FurukawaBundle\SNMP\SNMP as SNMP;
  9. //use RedisBundle\Services\RedisService;
  10. class FurukawaOltScanCommand extends BaseCommand
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('furukawa:olt:scan')
  16. ->setDescription('Escanear OLT para obtener ONUs')
  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_card_{$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 = array();
  40. $cpu = $this->getSNMP("oltCardCpu","cardCpu");
  41. $memory = $this->getSNMP("oltCardMemory","cardMemory");
  42. $_memory = $_cpu = array();
  43. foreach($cpu as $index => $value) {
  44. if($value == -1) continue;
  45. $_cpu[$index] = $value;
  46. }
  47. foreach($memory as $index => $value) {
  48. if($value == -1) continue;
  49. $_memory[$index] = $value;
  50. }
  51. if($_cpu) {$dataCached['cpu'] = $_cpu;}
  52. if($_memory) {$dataCached['memory'] = $_memory;}
  53. $this->setData($key_olt_scan, $dataCached, true);
  54. /* Fin de bloqueo */
  55. $this->removeLock($this->flag);
  56. $fin = microtime(true);
  57. $time = $fin - $inicio;
  58. $this->output->writeln("Tiempo: $time segundos");
  59. }
  60. }