setName('huawei:onu:tx') ->setDescription('TX 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_tx = "onu_tx_{$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 = $txCached = array(); if(empty($dataCached)) { $this->output->writeln("Se requiere {$key_olt_scan}."); $this->removeLock($this->flag); return true; } $txPower = $this->getSNMP("onuPonTxOpticalPower","onuTxPower"); $metric = "onu_tx_"; $line = 0; foreach($txPower as $index => $tx) { if($tx == 2147483647) continue; if(isset($dataCached[$index])) { $value = 0.01 * $tx; $sn = strtolower($dataCached[$index]['serialNumber']); $k = $metric.$sn; $sendData[$k] = "{$value}|g"; $line++; $txCached[$sn] = $value; } } $this->setData($key_onu_tx, $txCached, 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); } }