Ignore:
Timestamp:
Jun 3, 2014, 10:36:43 PM (11 years ago)
Author:
chronos
Message:
  • Fixed: NetworkImport was not recorded online to offline changes correctly.
File:
1 edited

Legend:

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

    r658 r663  
    3030        else $Online = 0;
    3131
    32       $DbResult = $System->Database->select('NetworkInterface', '`Id`,`Online`', '`LocalIP` = "'.$Properties['host'].'";');
    33       while($DbRow = $DbResult->fetch_assoc())
    34       {
    35         $LastOnline = $DbRow['Online'];
    36         $Interface = $DbRow['Id'];
    37 
    38         // Record state changes
    39         if($Online != $LastOnline)
    40         {
    41           $System->Database->insert('NetworkInterfaceUpDown', array(
    42                   'Interface' => $Interface, 'State' => $Online, 'Time' => TimeToMysqlDateTime($StartTime)));
    43         }
    44       }
    45 
    4632      if($Online)
    4733      {
     34        // Set only online state
     35        $DbResult = $System->Database->select('NetworkInterface', '`Id`, `Online`', '`LocalIP` = "'.$Properties['host'].'";');
     36        while($DbRow = $DbResult->fetch_assoc())
     37        {
     38          $LastOnline = $DbRow['Online'];
     39          $Interface = $DbRow['Id'];
     40
     41          // Record state changes
     42          if($Online != $LastOnline)
     43          {
     44            $System->Database->insert('NetworkInterfaceUpDown', array(
     45              'Interface' => $Interface, 'State' => $Online, 'Time' => TimeToMysqlDateTime($StartTime)));
     46          }
     47        }
     48
    4849        $DbResult = $System->Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"',
    4950          array('Online' => 1, 'LastOnline' => TimeToMysqlDateTime($StartTime)));
    5051      }
    5152    }
     53  }
     54
     55  // Set offline state for not updated interfaces
     56  $DbResult = $System->Database->select('NetworkInterface', 'Id', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"');
     57  while($DbRow = $DbResult->fetch_assoc())
     58  {
     59    $System->Database->insert('NetworkInterfaceUpDown', array(
     60      'Interface' => $DbRow['Id'], 'State' => 0, 'Time' => TimeToMysqlDateTime($StartTime)));
    5261  }
    5362  $DbResult = $System->Database->update('NetworkInterface', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0));
Note: See TracChangeset for help on using the changeset viewer.