Changeset 335 for trunk/system


Ignore:
Timestamp:
Dec 30, 2011, 9:19:03 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Přepracován netwatch import k zamezení chybného zaznamenávání více než 100% dostupnosti při duplicitních položkách v netwatch.
  • Upraveno: Optimalizováno vyčítání údajů netwatch pokud je více podsítí na jednom směrovači, tak vyčítat seznam jenom jednou namísto samostatně pro každou podsíť.
  • Přidáno: Ve seznamu podsítí nyní lze nastavit příznak Configure pro určení zda má být daný směrovač nastavován a používán pro statistiky.
Location:
trunk/system/generators
Files:
2 edited

Legend:

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

    r317 r335  
    1111$Routerboard->Debug = true;
    1212
    13 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`'); // WHERE `Member` = 0');
     13$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet` WHERE `Configure` = 1'); // WHERE `Member` = 0');
    1414while($Router = $DbResult3->fetch_assoc())
    1515{
     
    1717  $Routerboard->HostName = $Router['DHCP'];
    1818  $Items = array();
    19   $DbResult = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `DHCP`="'.$Router['DHCP'].'"');
     19  $DbResult = $Database->query('SELECT * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`DHCP`="'.$Router['DHCP'].'")');
    2020  while($Subnet = $DbResult->fetch_assoc())
    2121  {
  • trunk/system/generators/netwatch_import.php

    r317 r335  
    1212  $StartTime = time();
    1313
    14 $DbResult3 = $Database->query('SELECT * FROM `NetworkSubnet` WHERE `Member` IS NULL');
     14$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`), * FROM `NetworkSubnet` WHERE (`Configure` = 1) AND (`Member` IS NULL)');
    1515//echo($DbResult3->num_rows);
    1616while($Subnet = $DbResult3->fetch_assoc())
     
    2424  foreach($List as $Properties)
    2525  {
    26     $SubnetAddress = new NetworkAddressIPv4();
    27     $SubnetAddress->AddressFromString($Subnet['AddressRange']);
    28     $SubnetAddress->Prefix = $Subnet['Mask'];
    29     $Address = new NetworkAddressIPv4();
    30     $Address->AddressFromString($Properties['host']);
    31     $Address->Prefix = 32;
    32     if($SubnetAddress->Contain($Address))
     26    //echo($Properties['host'].', ');
     27    if($Properties['status'] == 'up')
    3328    {
    34       //echo($Properties['host'].', ');
    35       if($Properties['status'] == 'up')
    36       {
    37         $Online = 1;
    38         $Values = array('Online' => $Online, 'LastOnline' => 'NOW()');
    39         //echo($Properties['host']." up\n");
    40       } else
    41       {
    42         $Online = 0;
    43         $Values = array('Online' => $Online);
    44         //echo($Properties['host']." down\n");
    45       }
     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    }
    4638
    47       $DbResult = $Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', $Values);
    48       if($Online == 1)
    49       {
    50         $DbResult = $Database->select('NetworkInterface', 'Id', '`LocalIP` = "'.$Properties['host'].'"');
    51         $DbRow = $DbResult->fetch_assoc();
    52         $InterfaceId = $DbRow['Id'];
    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"))');
    56        
    57       }
    58     }
     39    $DbResult = $Database->update('NetworkInterface', '`LocalIP` = "'.$Properties['host'].'"', $Values);
    5940  }
    6041}
     
    6647  $DbResult2 = $Database->select('NetworkInterface', 'SUM(`Online`) AS `SumOnline`', '`Device`='.$Device['Id']);
    6748  $DbRow = $DbResult2->fetch_array();
    68   if($DbRow['SumOnline'] > 0) $Online = 1; else $Online = 0; 
    69   $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('Online' => $Online));
    70   if($Online == 1) $Database->update('NetworkDevice', 'Id='.$Device['Id'], array('LastOnline' => 'NOW()'));
     49  if($DbRow['SumOnline'] > 0) $Online = 1;
     50    else $Online = 0; 
     51  $Values = array('Online' => $Online);
     52  if($Online == 1) $Values['LastOnline'] = 'NOW()';
     53  $Database->update('NetworkDevice', 'Id='.$Device['Id'], $Values);
    7154}
    7255
     
    7962}
    8063
     64// Update interface online statistics
     65$DbResult = $Database->select('NetworkInterface', 'Id', '`Online` = 1');
     66while($Interface = $DbResult->fetch_assoc())
     67{
     68  $DbResult2 = $Database->select('NetworkInterfaceStat', '*', '(`NetworkInterface`="'.$Interface['Id'].'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
     69  if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO `NetworkInterfaceStat` (`NetworkInterface`, `Time`, `PingCount`) VALUES ("'.$Interface['Id'].'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))', '1');         
     70    $Database->query('UPDATE `NetworkInterfaceStat` SET `PingCount` = `PingCount` + 1 WHERE (`NetworkInterface`="'.$Interface['Id'].'") AND (`Time` = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
     71}
     72
    8173?>
Note: See TracChangeset for help on using the changeset viewer.