Changeset 317 for trunk/system/generators/netwatch_import.php
- Timestamp:
- Jul 15, 2011, 8:26:28 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/generators/netwatch_import.php
r313 r317 6 6 include('common.php'); 7 7 $Path = array('tool', 'netwatch'); 8 $Period = 60; // every 60 seconds 8 9 9 $DbResult3 = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` = 0'); 10 while(1) 11 { 12 $StartTime = time(); 13 14 $DbResult3 = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` IS NULL'); 15 //echo($DbResult3->num_rows); 10 16 while($Subnet = $DbResult3->fetch_assoc()) 11 17 { … … 39 45 } 40 46 41 $DbResult = $Database->update('NetworkInterface', ' LocalIP= "'.$Properties['host'].'"', $Values);47 $DbResult = $Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', $Values); 42 48 if($Online == 1) 43 49 { 44 $DbResult = $Database->select('NetworkInterface', 'Id', ' LocalIP= "'.$Properties['host'].'"');50 $DbResult = $Database->select('NetworkInterface', 'Id', '`LocalIP` = "'.$Properties['host'].'"'); 45 51 $DbRow = $DbResult->fetch_assoc(); 46 52 $InterfaceId = $DbRow['Id']; 47 $DbResult2 = $Database->select('NetworkInterfaceStat', '*', '( NetworkInterface="'.$InterfaceId.'") AND (Time= DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');48 if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO NetworkInterfaceStat (NetworkInterface, Time) VALUES ("'.$InterfaceId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');49 $Database->query('UPDATE NetworkInterfaceStat SET PingCount = PingCount + 1 WHERE (NetworkInterface="'.$InterfaceId.'") AND (Time= DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');53 $DbResult2 = $Database->select('NetworkInterfaceStat', '*', '(`NetworkInterface`="'.$InterfaceId.'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 54 if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO `NetworkInterfaceStat` (`NetworkInterface`, `Time`) VALUES ("'.$InterfaceId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 55 $Database->query('UPDATE `NetworkInterfaceStat` SET `PingCount` = `PingCount` + 1 WHERE (`NetworkInterface`="'.$InterfaceId.'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 50 56 51 57 } … … 55 61 56 62 // Update device online state 57 $DbResult = $Database->select('NetworkDevice', 'Id', ' Used=1');63 $DbResult = $Database->select('NetworkDevice', 'Id', '`Used`=1'); 58 64 while($Device = $DbResult->fetch_assoc()) 59 65 { 60 $DbResult2 = $Database->select('NetworkInterface', 'SUM( Online)', 'Device='.$Device['Id']);66 $DbResult2 = $Database->select('NetworkInterface', 'SUM(`Online`) AS `SumOnline`', '`Device`='.$Device['Id']); 61 67 $DbRow = $DbResult2->fetch_array(); 62 if($DbRow['S UM(Online)'] > 0) $Online = 1; else $Online = 0;68 if($DbRow['SumOnline'] > 0) $Online = 1; else $Online = 0; 63 69 $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('Online' => $Online)); 64 70 if($Online == 1) $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('LastOnline' => 'NOW()')); 65 71 } 66 72 73 $EndTime = time(); 74 $Delay = $Period - ($EndTime - $StartTime); 75 if($Delay < 0) $Delay = 0; 76 77 echo('Waiting '.$Delay.' seconds...'."\n"); 78 sleep($Delay); 79 } 80 67 81 ?>
Note:
See TracChangeset
for help on using the changeset viewer.