setName('huawei:onu:rx') ->setDescription('RX Power de ONUs') ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.') ->setDefinition(array( new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT",1), new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT",1), new InputOption('olt-ip', false, InputOption::VALUE_OPTIONAL, "IP de la OLT"), new InputOption('olt-community', false, InputOption::VALUE_OPTIONAL, "COMMUNITY de la OLT"), new InputOption('olt-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP"), new InputOption('save-historic', null, InputOption::VALUE_OPTIONAL, "Send data to StatsD",1) )) ; } /** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $key_olt_scan = "olt_scan_{$this->d_s}"; $key_onu_rx = "onu_rx_{$this->d_s}"; $saveHistoric = (int) $input->getOption('save-historic'); $inicio = microtime(true); $time = time(); $SNMP = new SNMP($this->oltIp, $this->oltCommunity); $library = "use".$this->oltSnmpLibrary; $this->apiSNMP = $SNMP->$library(); $dataCached = $this->getData($key_olt_scan, true); $sendData = $rxCached = array(); if(empty($dataCached)) { $this->output->writeln("Se requiere {$key_olt_scan}."); $this->removeLock($this->flag); return true; } $rxPower = $this->getSNMP("onuPonRxOpticalPower","onuRxPower"); $metric = "onu_rx_"; $line = 0; foreach($rxPower as $index => $rx) { if($rx == 2147483647) continue; if(isset($dataCached[$index])) { $value = 0.01 * $rx; $sn = strtolower($dataCached[$index]['serialNumber']); $k = $metric.strtolower($sn); $sendData[$k] = "{$value}|g"; $line++; $rxCached[$sn] = $value; } } $this->setData($key_onu_rx, $rxCached, true); if($sendData && $saveHistoric) { $t_start_script = microtime(true); $statsdService = $this->getContainer()->get('statsd'); $statsdService->send($sendData); $t_end_script = microtime(true); $time = $t_end_script - $t_start_script; print_r("Tiempo de envío al StatsD: {$time} ms / Cantidad: {$line}".PHP_EOL); } /* Fin de bloqueo */ $this->removeLock($this->flag); } }