Changeset 851


Ignore:
Timestamp:
Oct 14, 2017, 12:18:10 AM (7 years ago)
Author:
chronos
Message:
  • Fixed: Insert new network interface signal lines in transaction.
  • Fixed: Correctly get wireless link speed even from new RouterOS versions.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/Generators/Signal.php

    r781 r851  
    66  {
    77    $Time = time();
     8    $Queries = array();
    89
    910    // Load netwatch status from all DHCP routers
     
    3132          $DbRow = $DbResult->fetch_assoc();
    3233          $Interface = $DbRow['Id'];
    33         } else $Interface = null;
     34        } else $Interface = 'NULL';
    3435
    3536        if(strpos($Properties['signal-strength'], '@') === false)
     
    4243            else $Strength = $Parts[0];
    4344        }
    44         $RateRx = substr($Properties['rx-rate'], 0, -3); // without MHz
    45         $RateTx = substr($Properties['tx-rate'], 0, -3); // without MHz
    46         $this->Database->insert('NetworkSignal', array('MAC' => $Properties['mac-address'],
    47             'Value' => $Strength, 'RateRx' => $RateRx, 'RateTx' => $RateTx,
    48             'Time' => TimeToMysqlDateTime($Time), 'Interface' => $Interface, 'Device' => $Device['Id']));
     45        $RateRx = $this->StripUnits($Properties['rx-rate']);
     46        $RateTx = $this->StripUnits($Properties['tx-rate']);
     47        $Queries[] = 'INSERT INTO `NetworkSignal` (`MAC`, `Value`, `RateRx`, `RateTx`, `Time`, `Interface`, `Device`) VALUES '.
     48          '("'.$Properties['mac-address'].'", '.$Strength.', '.$RateRx.', '.$RateTx.', "'.
     49          TimeToMysqlDateTime($Time).'", '.$Interface.', '.$Device['Id'].')';
    4950        /*
    5051         $DbResult = $this->Database->select('Measure', 'Id', '`Name` = "'.$Properties['mac-address'].'"');
     
    6364      }
    6465    }
     66    $this->Database->Transaction($Queries);
     67  }
     68 
     69  function StripUnits($Value)
     70  {
     71    if (strpos($Value, '-') !== false) $Value = substr($Value, 0, strpos($Value, '-') - 1); // without channel info
     72    if (substr($Value, -3, 3) == "MHz") $Value = substr($Value, 0, -3); // without MHz unit
     73    if (substr($Value, -4, 4) == "Mbps") $Value = substr($Value, 0, -4); // without Mbps unit   
     74    if (substr($Value, -3, 3) == "Mbp") $Value = substr($Value, 0, -3); // without Mbp unit   
     75    if (substr($Value, -1, 1) == "M") $Value = substr($Value, 0, -1); // without M unit
     76    return($Value);
    6577  }
    6678
  • trunk/Packages/Common/Database.php

    r841 r851  
    202202  {
    203203  }
     204 
     205  public function Transaction($Queries)
     206  {
     207      $this->PDO->beginTransaction();
     208      foreach ($Queries as $Query)
     209      {
     210        $Statement = $this->PDO->prepare($Query);
     211        $Statement->execute();
     212      }         
     213      $this->PDO->commit();
     214  }
    204215}
    205216
Note: See TracChangeset for help on using the changeset viewer.