setName('fork:cmts:cm:stats') ->setDescription('Obtener estadísticas de un CM') ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.') ->setDefinition(array( new InputOption('cm', null, InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY, "List of CM: --cm=ip1,mac1 --cm=ip2,mac2"), new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1), new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1), new InputOption('cm-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS",'public'), new InputOption('cm-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP",'OIDSBase'), 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) { $this->inicio = microtime(true); $pool = new Pool(); $exception = function(Process $process, $duration) {throw new ProcessFailedException($process);}; $pool->setOnFailure($exception); $cablemodems = $input->getOption('cm'); $cmtsDeviceId = (int) $input->getOption('cmts-device-id'); $cmtsServerId = (int) $input->getOption('cmts-server-id'); $cmCommunity = $input->getOption('cm-community'); $cmSnmpLibrary = $input->getOption('cm-snmp-library'); $saveHistoric = (int) $input->getOption('save-historic'); if(is_null($cablemodems) || empty($cablemodems)) exit(); $path = "/opt/stats/bin/console"; $cmd = "cmts:cm:stats"; $args = "--cmts-device-id={$cmtsDeviceId} --cmts-server-id={$cmtsServerId} --cm-community={$cmCommunity} --cm-snmp-library={$cmSnmpLibrary} --save-historic={$saveHistoric}"; $total = 0; foreach($cablemodems as $dupla) { list($ip, $mac) = explode(",",$dupla); if(is_null($ip) || is_null($mac)) continue; $process = "{$path} {$cmd} {$args} --cm-ip={$ip} --cm-mac={$mac}"; $pool->add(new Process($process)); $total++; } try { $pool->run(); // blocking that will run till it finishes } catch(\ProcessFailedException $e) { print_r($e); print_r(PHP_EOL); } $this->fin = microtime(true); print_r("Fin"); print_r(PHP_EOL); exit(0); } }