Ignore:
Timestamp:
Jul 15, 2011, 8:26:28 AM (13 years ago)
Author:
george
Message:
  • Uvozovky v názvech v SQL dotazech.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/system/generators/netwatch_import.php

    r313 r317  
    66include('common.php');
    77$Path = array('tool', 'netwatch');
     8$Period = 60; // every 60 seconds
    89
    9 $DbResult3 = $Database->query('SELECT * FROM `NetworkSubnet`  WHERE `Member` = 0');
     10while(1)
     11{
     12  $StartTime = time();
     13
     14$DbResult3 = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` IS NULL');
     15//echo($DbResult3->num_rows);
    1016while($Subnet = $DbResult3->fetch_assoc())
    1117{
     
    3945      }
    4046
    41       $DbResult = $Database->update('NetworkInterface', 'LocalIP = "'.$Properties['host'].'"', $Values);
     47      $DbResult = $Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', $Values);
    4248      if($Online == 1)
    4349      {
    44         $DbResult = $Database->select('NetworkInterface', 'Id', 'LocalIP = "'.$Properties['host'].'"');
     50        $DbResult = $Database->select('NetworkInterface', 'Id', '`LocalIP` = "'.$Properties['host'].'"');
    4551        $DbRow = $DbResult->fetch_assoc();
    4652        $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"))');
    5056       
    5157      }
     
    5561
    5662// Update device online state
    57 $DbResult = $Database->select('NetworkDevice', 'Id', 'Used=1');
     63$DbResult = $Database->select('NetworkDevice', 'Id', '`Used`=1');
    5864while($Device = $DbResult->fetch_assoc())
    5965{
    60   $DbResult2 = $Database->select('NetworkInterface', 'SUM(Online)', 'Device='.$Device['Id']);
     66  $DbResult2 = $Database->select('NetworkInterface', 'SUM(`Online`) AS `SumOnline`', '`Device`='.$Device['Id']);
    6167  $DbRow = $DbResult2->fetch_array();
    62   if($DbRow['SUM(Online)'] > 0) $Online = 1; else $Online = 0; 
     68  if($DbRow['SumOnline'] > 0) $Online = 1; else $Online = 0; 
    6369  $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('Online' => $Online));
    6470  if($Online == 1) $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('LastOnline' => 'NOW()'));
    6571}
    6672
     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
    6781?>
Note: See TracChangeset for help on using the changeset viewer.