Ignore:
Timestamp:
Mar 24, 2009, 7:52:02 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Poopravené konfigurační skripty ve starém umístění.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • system/netwatch_import.php

    r113 r172  
    11<?php
    2 include_once('/a/www/centrala/global.php');
     2$SessionDisable = true;
     3chdir('/a/www/centrala');
     4include_once('global.php');
    35
     6$UserName = 'admin-ssh';
    47$Config['Web']['ShowErrors'] = 1;
    58
    6 $Commands = array();
    7 //$MaxSubnet = 1;
    8 $Commands[] = '/tool netwatch print terse';
    9 $Commands = implode(';', $Commands);
    10 $Command = '/usr/bin/ssh -l admin-ssh -i /root/.ssh/id_dsa rt-hajda-0 "'.$Commands.'"';
    11 //echo($Command."\n");
    12 exec($Command, $Output);
    13 array_pop($Output);
    14 //print_r($Output);
     9$DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`');
     10while($Router = $DbResult3->fetch_assoc())
     11{
     12  $Commands = array();
     13  $Commands[] = '/tool netwatch print terse';
     14  $Commands = implode(';', $Commands);
     15  $Command = '/usr/bin/ssh -l '.$UserName.' -i /root/.ssh/id_dsa '.$Router['DHCP'].' "'.$Commands.'"';
     16  //echo($Command."\n");
     17  $Output = '';
     18  exec($Command, $Output);
     19  array_pop($Output);
     20  //print_r($Output);
     21  foreach($Output as $Row)
     22  {
     23    $Row = substr($Row, 6);
     24    $RowParts = explode(' ', $Row);
     25    $Properties = array();
     26    foreach($RowParts as $Index => $Item)
     27    {
     28      if(strpos($Item, '=') !== false)
     29      {
     30        $ItemParts = explode('=', $Item);
     31        $Properties[$ItemParts[0]] = $ItemParts[1];
     32      }
     33    }
     34    if($Properties['status'] == 'up')
     35    {
     36      $Online = 1;
     37      $Values = array('online' => $Online,  'last_online' => 'NOW()');
     38    } else
     39    {
     40      $Online = 0;
     41      $Values = array('online' => $Online);
     42    }
    1543
    16 foreach($Output as $Row)
    17 {
    18   $Row = substr($Row, 6);
    19   $RowParts = explode(' ', $Row);
    20   $Properties = array();
    21   foreach($RowParts as $Index => $Item)
    22   {
    23     if(strpos($Item, '=') !== false)
     44    $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values);
     45    if($Online == 1)
    2446    {
    25       $ItemParts = explode('=', $Item);
    26       $Properties[$ItemParts[0]] = $ItemParts[1];
     47      $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');
     48      $DbRow = $DbResult->fetch_array();
     49      $HostId = $DbRow['id'];
     50      $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
     51      if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');         
     52      $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    2753    }
    28   }
    29   if($Properties['status'] == 'up')
    30   {
    31     $Online = 1;
    32     $Values = array('online' => $Online,  'last_online' => 'NOW()');
    33   } else
    34   {
    35     $Online = 0;
    36     $Values = array('online' => $Online);
    37   }
    38 
    39   $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values);
    40   if($Online == 1)
    41   {
    42     $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"');
    43     $DbRow = $DbResult->fetch_array();
    44     $HostId = $DbRow['id'];
    45     $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    46     if($DbResult2->num_rows == 0) $Database->query('REPLACE INTO stat_hosts (host_id, time) VALUES ("'.$HostId.'", DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');         
    47     $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))');
    4854  }
    4955}
Note: See TracChangeset for help on using the changeset viewer.