CmtsCmScanCommand.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace CmtsBundle\Command;
  3. use BaseStatsBundle\Command\BaseCmtsCommand;
  4. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use CmtsBundle\SNMP\SNMP as SNMP;
  9. class CmtsCmScanCommand extends BaseCmtsCommand
  10. {
  11. protected function configure()
  12. {
  13. $this
  14. ->setName('cmts:cm:scan')
  15. ->setDescription('Escanear CMTS para obtener CMs')
  16. ->setHelp('Se requieren parámetros para poder realizar la correcta consulta. El comando requiere Redis.')
  17. ->setDefinition(array(
  18. new InputOption('cmts-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId del CMTS",1),
  19. new InputOption('cmts-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice del CMTS",1),
  20. new InputOption('cmts-ip', false, InputOption::VALUE_OPTIONAL, "IP del CMTS"),
  21. new InputOption('cmts-community', false, InputOption::VALUE_OPTIONAL, "Community del CMTS"),
  22. new InputOption('cmts-snmp-library', false, InputOption::VALUE_OPTIONAL, "Versión de librería SNMP")
  23. ))
  24. ;
  25. }
  26. /**
  27. * @param InputInterface $input
  28. * @param OutputInterface $output
  29. */
  30. protected function execute(InputInterface $input, OutputInterface $output)
  31. {
  32. parent::execute($input, $output);
  33. $key_cmts_scan = "cmts_scan_{$this->d_s}";
  34. $inicio = microtime(true);
  35. $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
  36. $library = "use".$this->cmtsSnmpLibrary;
  37. $this->apiSNMP = $SNMP->$library();
  38. $dataCached = array();
  39. $countCms = 0;
  40. $macs = $this->getSNMP("docsIfCmtsCmStatusMacAddress","cmMac");
  41. $ips = $this->getSNMP("docsIfCmtsCmStatusIpAddress","cmIp");
  42. $status = $this->getSNMP("docsIfCmtsCmStatusValue","cmStatus");
  43. $up = $this->getSNMP("docsIfCmtsCmStatusUpChannelIfIndex","cmUpIf");
  44. $down = $this->getSNMP("docsIfCmtsCmStatusDownChannelIfIndex","cmDownIf");
  45. foreach($macs as $index => $mac) {
  46. $countCms++; $data = array();
  47. $data['mac'] = strtolower($mac);
  48. (isset($ips[$index]))? $data['ip'] = $ips[$index] : $data['ip'] = null;
  49. /* $values = array(1 => 'other', 2 => 'ranging',
  50. 3 => 'rangingAborted', 4 => 'rangingComplete',
  51. 5 => 'ipComplete', 6 => 'registrationComplete', 7 => 'accessDenied'); */
  52. (isset($status[$index]) && ($status[$index] == 6))? $data['status'] = 1 : $data['status'] = 0;
  53. (isset($up[$index]))? $data['upInterface'] = $up[$index] : $data['upInterface'] = null;
  54. (isset($down[$index]))? $data['downInterface'] = $down[$index] : $data['downInterface'] = null;
  55. $dataCached[$index] = $data;
  56. }
  57. $this->setData($key_cmts_scan, $dataCached, true);
  58. /* Fin de bloqueo */
  59. $this->removeLock($this->flag);
  60. $fin = microtime(true);
  61. $time = $fin - $inicio;
  62. $this->output->writeln("Tiempo: $time segundos / Cantidad CMs: {$countCms}");
  63. }
  64. }