- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php
r863 r873 10 10 $Interfaces = array(); 11 11 $DbResult = $this->Database->select('NetworkInterface', '`Id`, `LocalIP` AS `IP`, `Online`, 0 AS `NewOnline`'); 12 while ($DbRow = $DbResult->fetch_assoc())12 while ($DbRow = $DbResult->fetch_assoc()) 13 13 $Interfaces[$DbRow['IP']] = $DbRow; 14 14 … … 16 16 $DbResult3 = $this->Database->query('SELECT `DHCP` FROM `NetworkSubnet` '. 17 17 'WHERE (`Configure` = 1) AND (`Member` IS NULL) GROUP BY `DHCP`'); 18 while ($Subnet = $DbResult3->fetch_assoc())18 while ($Subnet = $DbResult3->fetch_assoc()) 19 19 { 20 20 echo('router '.$Subnet['DHCP']."\n"); … … 22 22 $Routerboard->Connect($Subnet['DHCP'], $this->System->Config['API']['UserName'], 23 23 $this->System->Config['API']['Password']); 24 if (!$Routerboard->Connected) continue;24 if (!$Routerboard->Connected) continue; 25 25 $Routerboard->Write('/tool/netwatch/getall', false); 26 26 $Routerboard->Write('=.proplist=host,status'); 27 27 $Read = $Routerboard->Read(false); 28 28 $List = $Routerboard->ParseResponse($Read); 29 foreach ($List as $Properties)29 foreach ($List as $Properties) 30 30 { 31 31 $IP = $Properties['host']; 32 if ($Properties['status'] == 'up') $Online = 1;32 if ($Properties['status'] == 'up') $Online = 1; 33 33 else $Online = 0; 34 34 35 if ($Online)35 if ($Online) 36 36 { 37 if (array_key_exists($IP, $Interfaces))37 if (array_key_exists($IP, $Interfaces)) 38 38 $Interfaces[$IP]['NewOnline'] = 1; 39 39 else echo('IP '.$IP.' not found.'."\n"); … … 44 44 $Queries = array(); 45 45 $QueriesInsert = array(); 46 foreach ($Interfaces as $Index => $Interface)46 foreach ($Interfaces as $Index => $Interface) 47 47 { 48 48 // Update last online time if still online 49 if ($Interface['NewOnline'])49 if ($Interface['NewOnline']) 50 50 $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = '.$Interface['Id'], 51 51 array('LastOnline' => TimeToMysqlDateTime($StartTime))); 52 52 53 if ($Interface['Online'] != $Interface['NewOnline'])53 if ($Interface['Online'] != $Interface['NewOnline']) 54 54 { 55 55 // Online state changed … … 78 78 $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 1) AND '. 79 79 '(`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'")'); 80 while ($DbRow = $DbResult->fetch_assoc())80 while ($DbRow = $DbResult->fetch_assoc()) 81 81 { 82 82 echo('IP '.$DbRow['LocalIP'].' online but time not updated.'."\n"); … … 84 84 $DbResult = $this->Database->select('NetworkInterface', '*', '(`Online` = 0) AND '. 85 85 '(`LastOnline` >= "'.TimeToMysqlDateTime($StartTime).'")'); 86 while ($DbRow = $DbResult->fetch_assoc())86 while ($DbRow = $DbResult->fetch_assoc()) 87 87 { 88 88 echo('IP '.$DbRow['LocalIP'].' not online but time updated.'."\n"); … … 92 92 // Update device online state 93 93 $DbResult = $this->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`'); 94 while ($Device = $DbResult->fetch_assoc())94 while ($Device = $DbResult->fetch_assoc()) 95 95 { 96 if ($Device['SumOnline'] > 0)96 if ($Device['SumOnline'] > 0) 97 97 $Queries[] = $this->Database->GetUpdate('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1)); 98 98 }
Note:
See TracChangeset
for help on using the changeset viewer.