CmtsCmScanCommand.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $key_cmts_desc = "cmts_desc_{$this->d_s}";
  35. $inicio = microtime(true);
  36. $SNMP = new SNMP($this->cmtsIp, $this->cmtsCommunity);
  37. $library = "use".$this->cmtsSnmpLibrary;
  38. $this->apiSNMP = $SNMP->$library();
  39. $dataCached = array();
  40. $countCms = 0;
  41. $macs = $this->getSNMP("docsIfCmtsCmStatusMacAddress","cmMac");
  42. $ips = $this->getSNMP("docsIfCmtsCmStatusIpAddress","cmIp");
  43. $status = $this->getSNMP("docsIfCmtsCmStatusValue","cmStatus");
  44. $up = $this->getSNMP("docsIfCmtsCmStatusUpChannelIfIndex","cmUpIf");
  45. $down = $this->getSNMP("docsIfCmtsCmStatusDownChannelIfIndex","cmDownIf");
  46. $signal = $this->getSNMP("docsIfCmtsCmStatusSignalNoise","cmtsSignal");
  47. $rx = $this->getSNMP("docsIfCmtsCmStatusRxPower","cmtsRx");
  48. $microreflection = $this->getSNMP("docsIfCmtsCmStatusMicroreflections","cmtsMicroreflection");
  49. $description = $this->getSNMP("systemDescription","cmtsDescription");
  50. if(isset($description[0])) {
  51. $this->setData($key_cmts_desc, $description, false);
  52. }
  53. foreach($macs as $index => $mac) {
  54. $countCms++; $data = array();
  55. $data['mac'] = strtolower($mac);
  56. (isset($ips[$index]))? $data['ip'] = $ips[$index] : $data['ip'] = null;
  57. /* $values = array(1 => 'other', 2 => 'ranging',
  58. 3 => 'rangingAborted', 4 => 'rangingComplete',
  59. 5 => 'ipComplete', 6 => 'registrationComplete', 7 => 'accessDenied'); */
  60. (isset($status[$index]) && ($status[$index] == 6))? $data['status'] = 1 : $data['status'] = 0;
  61. (isset($up[$index]))? $data['upInterface'] = $up[$index] : $data['upInterface'] = null;
  62. (isset($down[$index]))? $data['downInterface'] = $down[$index] : $data['downInterface'] = null;
  63. (isset($signal[$index]))? $data['signal'] = $signal[$index] * 0.1 : $data['signal'] = null;
  64. (isset($rx[$index]))? $data['rxPower'] = $rx[$index] * 0.1 : $data['rxPower'] = null;
  65. (isset($microreflection[$index]))? $data['microreflection'] = $microreflection[$index] : $data['microreflection'] = null;
  66. $dataCached[$index] = $data;
  67. }
  68. $this->setData($key_cmts_scan, $dataCached, true);
  69. /* Fin de bloqueo */
  70. $this->removeLock($this->flag);
  71. $fin = microtime(true);
  72. $time = $fin - $inicio;
  73. $this->output->writeln("Tiempo: $time segundos / Cantidad CMs: {$countCms}");
  74. }
  75. }