Changeset 167 for www/system/netwatch_import.php
- Timestamp:
- Mar 24, 2009, 11:44:03 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
www/system/netwatch_import.php
r161 r167 1 1 <?php 2 include_once('/a/www/centrala/global.php'); 2 $SessionDisable = true; 3 include_once('../global.php'); 3 4 5 $UserName = 'admin-ssh'; 4 6 $Config['Web']['ShowErrors'] = 1; 5 7 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); 8 $DbResult3 = $Database->query('SELECT DISTINCT (`DHCP`) FROM `NetworkSubnet`'); 9 while($Router = $DbResult3->fetch_assoc()) 10 { 11 $Commands = array(); 12 $Commands[] = '/tool netwatch print terse'; 13 $Commands = implode(';', $Commands); 14 $Command = '/usr/bin/ssh -l '.$UserName.' -i generators/id_dsa '.$Router['DHCP'].' "'.$Commands.'"'; 15 //echo($Command."\n"); 16 $Output = ''; 17 exec($Command, $Output); 18 array_pop($Output); 19 //print_r($Output); 20 foreach($Output as $Row) 21 { 22 $Row = substr($Row, 6); 23 $RowParts = explode(' ', $Row); 24 $Properties = array(); 25 foreach($RowParts as $Index => $Item) 26 { 27 if(strpos($Item, '=') !== false) 28 { 29 $ItemParts = explode('=', $Item); 30 $Properties[$ItemParts[0]] = $ItemParts[1]; 31 } 32 } 33 if($Properties['status'] == 'up') 34 { 35 $Online = 1; 36 $Values = array('online' => $Online, 'last_online' => 'NOW()'); 37 } else 38 { 39 $Online = 0; 40 $Values = array('online' => $Online); 41 } 15 42 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) 43 $DbResult = $Database->update('hosts', 'IP="'.$Properties['host'].'"', $Values); 44 if($Online == 1) 24 45 { 25 $ItemParts = explode('=', $Item); 26 $Properties[$ItemParts[0]] = $ItemParts[1]; 46 $DbResult = $Database->select('hosts', 'id', 'IP="'.$Properties['host'].'"'); 47 $DbRow = $DbResult->fetch_array(); 48 $HostId = $DbRow['id']; 49 $DbResult2 = $Database->select('stat_hosts', '*', '(host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 50 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"))'); 51 $Database->query('UPDATE stat_hosts SET count = count + 1 WHERE (host_id="'.$HostId.'") AND (time = DATE_FORMAT(NOW(), "%Y-%m-%d %H:00:00"))'); 27 52 } 28 }29 if($Properties['status'] == 'up')30 {31 $Online = 1;32 $Values = array('online' => $Online, 'last_online' => 'NOW()');33 } else34 {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"))');48 53 } 49 54 }
Note:
See TracChangeset
for help on using the changeset viewer.