123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?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 HuaweiOnuScanCommand extends BaseCommand
- {
- protected function configure()
- {
- $this
- ->setName('huawei:onu:scan')
- ->setDescription('Escanear OLT para obtener 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);
- $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_scan_d_{$oltDeviceId}_s_{$oltServerId}.lock";
- $key_olt_scan = "olt_scan_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);
- $dataCached = array();
- /* $slots = $SNMP->$library()->onuSlot();
- $pons = $SNMP->$library()->onuPon();
- $onus = $SNMP->$library()->onuOnuid(); */
- $serialNumbers = $SNMP->$library()->onuSerialNumber();
- print_r($serialNumbers);
- die;
- $countOnus = 0;
- foreach($onus as $index => $onuId) {
- $countOnus++;
- if(isset($slots[$index]) && isset($pons[$index]) && isset($serialNumbers[$index])) {
- $slot = $slots[$index]; $pon = $pons[$index]; $sn = strtolower($serialNumbers[$index]);
- $data = array();
- $data['slot'] = $slot;
- $data['port'] = $pon;
- $data['onuId'] = $onuId;
- $data['serialNumber'] = $sn;
- $data['ponport'] = "{$slot}/{$pon}/{$onuId}";
- $dataCached[$index] = $data;
- }
- }
- $this->setData($key_olt_scan, $dataCached, true);
- /* Fin de bloqueo */
- $this->removeLock($flag);
- $fin = microtime(true);
- $time = $fin - $inicio;
- $this->output->writeln("Tiempo: $time segundos / Cantidad ONUs: {$countOnus}");
-
- }
- }
|