Ignore:
Timestamp:
Oct 2, 2013, 8:26:20 PM (11 years ago)
Author:
chronos
Message:
  • Opraveno: Nastavení online stavu rozhraní a zařízení na nedostupné pokud čas LastOnline je starší než perioda. Pokud se neprováděla aktualizace, tak zařízení se tvářila falešně jako online.
File:
1 edited

Legend:

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

    r548 r575  
    1212  $StartTime = time();
    1313
     14  // Load netwatch status from all DHCP routers
    1415  $DbResult3 = $System->Database->query('SELECT DHCP, AddressRange, Mask FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY DHCP');
    15   //echo($DbResult3->num_rows);
    1616  while($Subnet = $DbResult3->fetch_assoc())
    1717  {
     
    2424    foreach($List as $Properties)
    2525    {
    26       //echo($Properties['host'].', ');
    2726      if($Properties['status'] == 'up')
    2827      {
    29         $Online = 1;
    30         $Values = array('Online' => $Online, 'LastOnline' => 'NOW()');
    31         //echo($Properties['host']." up\n");
    32       } else
    33       {
    34         $Online = 0;
    35         $Values = array('Online' => $Online);
    36         //echo($Properties['host']." down\n");
    37       }
    38 
    39       $DbResult = $System->Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', $Values);
     28        $DbResult = $System->Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"',
     29          array('Online' => $Online, 'LastOnline' => TimeToMysqlDateTime($StartTime)));
     30      }
    4031    }
    41   }
     32  }
     33  $DbResult = $System->Database->update('NetworkInterface', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0));
    4234
    4335  // Update device online state
    44   $DbResult = $System->Database->select('NetworkDevice', 'Id', '`Used`=1');
     36  $DbResult = $System->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`');
    4537  while($Device = $DbResult->fetch_assoc())
    4638  {
    47     $DbResult2 = $System->Database->select('NetworkInterface', 'SUM(`Online`) AS `SumOnline`', '`Device`='.$Device['Id']);
    48     $DbRow = $DbResult2->fetch_array();
    49     if($DbRow['SumOnline'] > 0) $Online = 1;
    50       else $Online = 0; 
    51     $Values = array('Online' => $Online);
    52     if($Online == 1) $Values['LastOnline'] = 'NOW()';
    53     $System->Database->update('NetworkDevice', 'Id='.$Device['Id'], $Values);
     39    if($Device['SumOnline'] > 0)
     40      $System->Database->update('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime)));
    5441  }
     42  $DbResult = $System->Database->update('NetworkDevice', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0));
    5543
    5644  // Update interface online statistics
Note: See TracChangeset for help on using the changeset viewer.