|
@@ -0,0 +1,106 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace HuaweiBundle\Command;
|
|
|
+
|
|
|
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
+use Symfony\Component\Console\Input\InputOption;
|
|
|
+use Symfony\Component\Console\Input\InputInterface;
|
|
|
+use Symfony\Component\Console\Output\OutputInterface;
|
|
|
+use HuaweiBundle\SNMP\SNMP as SNMP;
|
|
|
+//use RedisBundle\Services\RedisService;
|
|
|
+
|
|
|
+class HuaweiOnuCatvRxCommand extends BaseCommand
|
|
|
+{
|
|
|
+
|
|
|
+ protected function configure()
|
|
|
+ {
|
|
|
+ $this
|
|
|
+ ->setName('huawei:onu:catvrx')
|
|
|
+ ->setDescription('CATV 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")
|
|
|
+ ))
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param InputInterface $input
|
|
|
+ * @param OutputInterface $output
|
|
|
+ */
|
|
|
+ protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
+ {
|
|
|
+ parent::execute($input, $output);
|
|
|
+
|
|
|
+ $this->output->writeln("INICIO");
|
|
|
+
|
|
|
+ $inicio = microtime(true);
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ $oltDeviceId = (int) $input->getOption('olt-device-id');
|
|
|
+ $oltServerId = (int) $input->getOption('olt-server-id');
|
|
|
+ $oltIp = $input->getOption('olt-ip');
|
|
|
+ $oltCommunity = $input->getOption('olt-community');
|
|
|
+ $oltSnmpLibrary = $input->getOption('olt-snmp-library');
|
|
|
+
|
|
|
+ $flag = "olt_onus_catvrx_d_{$oltDeviceId}_s_{$oltServerId}.lock";
|
|
|
+ $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
+ $key_onu_rx = "onu_catvrx_d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
+
|
|
|
+ /* Control de bloqueo */
|
|
|
+ if($this->lock($flag)) {return;}
|
|
|
+
|
|
|
+ $SNMP = new SNMP($oltIp, $oltCommunity);
|
|
|
+ $library = "use".$oltSnmpLibrary;
|
|
|
+
|
|
|
+ $dataCached = $this->getData($key_olt_scan, true);
|
|
|
+ $rxCached = array(); //$this->getData($key_onu_rx, true);
|
|
|
+
|
|
|
+ if(empty($dataCached)) {
|
|
|
+ $this->output->writeln("Se requiere {$key_olt_scan}.");
|
|
|
+ $this->removeLock($flag);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $rxPower = $SNMP->$library()->onuCatvRxOpticalPower();
|
|
|
+
|
|
|
+ $sendData = array();
|
|
|
+ $metric = "onu_catvrx_";
|
|
|
+ $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);
|
|
|
+ //print_r("$line - $index - $k - $value".PHP_EOL);
|
|
|
+ $sendData[$k] = "{$value}|g";
|
|
|
+ $line++;
|
|
|
+
|
|
|
+ $rxCached[$sn] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->setData($key_onu_rx, $rxCached, true);
|
|
|
+
|
|
|
+ if($sendData) {
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //$this->collector->set($key,$dataCached,true);
|
|
|
+
|
|
|
+ /* Fin de bloqueo */
|
|
|
+ $this->removeLock($flag);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|