1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace CmtsBundle\Command;
- use BaseStatsBundle\Command\BaseCmtsCommand;
- 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 CmtsBundle\SNMP\SNMP as SNMP;
- class CmtsCmScanCommand extends BaseCmtsCommand
- {
- protected function configure()
- {
- $this
- ->setName('cmts:cm:scan')
- ->setDescription('Escanear CMTS para obtener CMs')
- ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
- ->setDefinition(array(
- 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('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
- new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
- new InputOption('cmts-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);
-
- $key_cmts_scan = "cmts_scan_{$this->d_s}";
- $key_cmts_desc = "cmts_desc_{$this->d_s}";
- $inicio = microtime(true);
-
- $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
- $library = "use".$this->cmtsSnmpLibrary;
- $this->apiSNMP = $SNMP->$library();
- $dataCached = array();
- $countCms = 0;
-
- $macs = $this->getSNMP("docsIfCmtsCmStatusMacAddress","cmMac");
- $ips = $this->getSNMP("docsIfCmtsCmStatusIpAddress","cmIp");
- $status = $this->getSNMP("docsIfCmtsCmStatusValue","cmStatus");
-
- $up = $this->getSNMP("docsIfCmtsCmStatusUpChannelIfIndex","cmUpIf");
- $down = $this->getSNMP("docsIfCmtsCmStatusDownChannelIfIndex","cmDownIf");
-
- $signal = $this->getSNMP("docsIfCmtsCmStatusSignalNoise","cmtsSignal");
- $rx = $this->getSNMP("docsIfCmtsCmStatusRxPower","cmtsRx");
- $microreflection = $this->getSNMP("docsIfCmtsCmStatusMicroreflections","cmtsMicroreflection");
-
- $description = $this->getSNMP("systemDescription","cmtsDescription");
- if(isset($description[0])) {
- $this->setData($key_cmts_desc, $description, false);
- }
- foreach($macs as $index => $mac) {
- $countCms++; $data = array();
- $data['mac'] = strtolower($mac);
- (isset($ips[$index]))? $data['ip'] = $ips[$index] : $data['ip'] = null;
-
- /* $values = array(1 => 'other', 2 => 'ranging',
- 3 => 'rangingAborted', 4 => 'rangingComplete',
- 5 => 'ipComplete', 6 => 'registrationComplete', 7 => 'accessDenied'); */
- (isset($status[$index]) && ($status[$index] == 6))? $data['status'] = 1 : $data['status'] = 0;
- (isset($up[$index]))? $data['upInterface'] = $up[$index] : $data['upInterface'] = null;
- (isset($down[$index]))? $data['downInterface'] = $down[$index] : $data['downInterface'] = null;
-
- (isset($signal[$index]))? $data['signal'] = $signal[$index] * 0.1 : $data['signal'] = null;
- (isset($rx[$index]))? $data['rxPower'] = $rx[$index] * 0.1 : $data['rxPower'] = null;
- (isset($microreflection[$index]))? $data['microreflection'] = $microreflection[$index] : $data['microreflection'] = null;
- $dataCached[$index] = $data;
- }
- $this->setData($key_cmts_scan, $dataCached, true);
- /* Fin de bloqueo */
- $this->removeLock($this->flag);
- $fin = microtime(true);
- $time = $fin - $inicio;
- $this->output->writeln("Tiempo: $time segundos / Cantidad CMs: {$countCms}");
-
- }
- }
|