123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- # bin/console cmts:cm:stats --cmts-device-id=14 --cmts-server-id=1 --cm-ip=10.42.0.27 --cm-mac=00237406d524 --cm-community=public
- # http://200.50.168.115/Provisioning/admin/cablemodem/00237406d524
- # bin/console cmts:cm:stats --cmts-device-id=14 --cmts-server-id=1 --cm-ip=10.50.2.3 --cm-mac=001a6663dcde --cm-community=public
- namespace CmtsBundle\Command;
- use BaseStatsBundle\Command\BaseCmCommand;
- use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Output\OutputInterface;
- use CmtsBundle\SNMP\SNMP as SNMP;
- use Symfony\Bundle\FrameworkBundle\Console\Application;
- use Symfony\Component\Console\Input\ArgvInput;
- use Symfony\Component\Console\Output\BufferedOutput;
- use Symfony\Component\Process\Process;
- use Symfony\Component\Process\Exception\ProcessFailedException;
- use Graze\ParallelProcess\Pool;
- class ForkCmtsCmStatsCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this
- ->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);
-
-
- }
- }
|