FurukawaOnuVoltageCommand.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 FurukawaOnuVoltageCommand extends BaseCommand
  11. {
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('furukawa:onu:voltage')
  16. ->setDescription('Voltage de 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. new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1)
  25. ))
  26. ;
  27. }
  28. /**
  29. * @param InputInterface $input
  30. * @param OutputInterface $output
  31. */
  32. protected function execute(InputInterface $input, OutputInterface $output)
  33. {
  34. parent::execute($input, $output);
  35. $key_olt_scan = "olt_scan_{$this->d_s}";
  36. $key_onu_voltage = "onu_voltage_{$this->d_s}";
  37. $saveHistoric = (int) $input->getOption('save-historic');
  38. $inicio = microtime(true);
  39. $time = time();
  40. $SNMP = new SNMP($this->oltIp, $this->oltCommunity);
  41. $library = "use".$this->oltSnmpLibrary;
  42. $this->apiSNMP = $SNMP->$library();
  43. $dataCached = $this->getData($key_olt_scan, true);
  44. $sendData = $voltageCached = array();
  45. if(empty($dataCached)) {
  46. $this->output->writeln("Se requiere {$key_olt_scan}.");
  47. $this->removeLock($this->flag);
  48. return true;
  49. }
  50. $voltage = $this->getSNMP("onuPonOpticalVltage","onuVoltage");
  51. $metric = "onu_voltage_";
  52. $line = 0;
  53. foreach($voltage as $index => $volt) {
  54. if($volt == 2147483647) continue;
  55. if(isset($dataCached[$index])) {
  56. $value = 0.001 * $volt;
  57. $sn = strtolower($dataCached[$index]['serialNumber']);
  58. $k = $metric.strtolower($sn);
  59. $sendData[$k] = "{$value}|g";
  60. $line++;
  61. $voltageCached[$sn] = $value;
  62. }
  63. }
  64. $this->setData($key_onu_voltage, $voltageCached, true);
  65. if($sendData && $saveHistoric) {
  66. $t_start_script = microtime(true);
  67. $statsdService = $this->getContainer()->get('statsd');
  68. $statsdService->send($sendData);
  69. $t_end_script = microtime(true);
  70. $time = $t_end_script - $t_start_script;
  71. print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL);
  72. }
  73. /* Fin de bloqueo */
  74. $this->removeLock($this->flag);
  75. }
  76. }