123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace StatsBundle\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 StatsBundle\Services\DeviceManager;
- class StatsPonPortCommand extends BaseCommand
- {
- protected function configure()
- {
- $this
- ->setName('stats:ponport')
- ->setDescription('Update PonPort Stats')
- ->setHelp('Actualiza la tabla PonPort con los datos obtenidos del OLT definido')
- ->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)
- ))
- ;
- }
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- parent::execute($input, $output);
- $oltDeviceId = (int) $input->getOption('olt-device-id');
- $oltServerId = (int) $input->getOption('olt-server-id');
- $now = date("d-m-Y H:i:s");
- $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
-
- $deviceOlt = $doctrine->getRepository('\StatsBundle\Entity\Device')->findOneBy(array('deviceId' => $oltDeviceId, 'deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\OLT'));
-
- $tenancyId = $deviceOlt->getTenancyId();
- $deviceServerId = $oltServerId;
-
- $key_pon_stats = "olt_stats_pons_d_{$oltDeviceId}_s_{$oltServerId}";
-
- $ponsCached = $this->getData($key_pon_stats, true);
- if(empty($ponsCached)) {
- $this->output->writeln("Se requiere {$key_pon_stats}.");
- return true;
- }
- $ponPorts = $doctrine->getRepository('\StatsBundle\Entity\PonPort')->findBy(array('oltDeviceId' => $oltDeviceId, 'deviceServer' => $oltServerId));
- $_ponPorts = array();
- foreach($ponPorts as $k => $pp) {
- $_ponPorts[$pp->getPonPort()] = $pp->getId();
- }
-
- foreach($ponsCached as $index => $stats) {
-
- $row = array();
- $ponPort = $stats['ponPort'];
- if(isset($_ponPorts[$ponPort])) {
- $row['id'] = $_ponPorts[$ponPort];
- } else {
- $row['id'] = "NULL";
- }
- $row['deviceServer'] = $deviceServerId;
- $row['ponPort'] = "'{$ponPort}'";
- $row['oltDeviceId'] = $oltDeviceId;
- $row['tenancyId'] = $tenancyId;
- $row['update'] = "'".date("Y-m-d H:i:s")."'";
-
-
- (isset($stats['txPower']))? $row['txPower'] = $stats['txPower'] : $row['txPower'] = "NULL";
- (empty($stats['rxPower']))? $row['rxPower'] = "NULL" : $row['rxPower'] = "'".str_replace('"','\"',json_encode($stats['rxPower']))."'";
- (isset($stats['voltage']))? $row['voltage'] = $stats['voltage'] : $row['voltage'] = "NULL";
- (isset($stats['temperature']))? $row['temperature'] = $stats['temperature'] : $row['temperature'] = "NULL";
- (isset($stats['biasCurrent']))? $row['biasCurrent'] = $stats['biasCurrent'] : $row['biasCurrent'] = "NULL";
-
- $data[] = "(".implode(",",$row).")".PHP_EOL;
- }
- $conn = $doctrine->getConnection();
- $sql = "DELETE FROM `pon_port` WHERE device_server_id = {$deviceServerId} AND olt_device_id = {$oltDeviceId};";
- $conn->query($sql);
- $conn->close();
- $conn = $doctrine->getConnection();
- $sql = "INSERT LOW_PRIORITY IGNORE INTO `pon_port` (`id`,`device_server_id`,`pon_port`,`olt_device_id`,`tenancy_id`,`updated`,`tx_power`,`rx_power`,`voltage`,`temperature`,`bias_current`) VALUES ". implode(",", $data).";";
-
- //print_r($sql);
- $conn->query($sql);
- $conn->close();
-
- }
- }
|