git-svn-id: http://www.observium.org/svn/observer/trunk@118 61d68cd4-352d-0410-923a-c4978735b2b8

This commit is contained in:
Adam Amstrong
2007-11-23 11:37:28 +00:00
parent 9a6d196f32
commit 89b6a9bf1a
28 changed files with 1275 additions and 1379 deletions
+16 -9
View File
@@ -3,7 +3,7 @@
include("config.php");
include("includes/functions.php");
$device_query = mysql_query("SELECT * FROM `devices` WHERE os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' AND status = '1'");
$device_query = mysql_query("SELECT * FROM `devices` WHERE status = '1' AND os = 'Linux' OR os = 'FreeBSD' OR os = 'NetBSD' OR os = 'OpenBSD' OR os = 'DragonFly' ORDER BY `device_id` DESC");
while ($device = mysql_fetch_array($device_query)) {
$id = $device['device_id'];
$hostname = $device['hostname'];
@@ -19,18 +19,26 @@ while ($device = mysql_fetch_array($device_query)) {
list($descr, $units, $size, $type) = explode("\n", $temp);
list($units) = explode(" ", $units);
if(strstr($type, "FixedDisk") && $size > '0') {
echo("$oid,$descr,$units,$size\n");
if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"),0) == '0') {
$query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) values ('$id', '$hrStorageIndex', '$descr', '$size', '$units')";
echo("$query \n");
$query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) ";
$query .= "values ('$id', '$hrStorageIndex', '$descr', '$size', '$units')";
mysql_query($query);
echo("Adding $descr\n");
} else {
$data = mysql_fetch_array(mysql_query("SELECT * FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'"));
if($data['hrStorageDescr'] != $descr || $data['hrStorageSize'] != $size || $data['hrStorageAllocationUnits'] != $units ) {
$query = "UPDATE storage SET `hrStorageDescr` = '$descr', `hrStorageSize` = '$size', `hrStorageAllocationUnits` = '$units' ";
$query .= "WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '$id'";
echo("Updating $descr\n");
mysql_query($query);
}
}
$storage_exists[] = "$id $hrStorageIndex";
}
}
}
$sql = "SELECT * FROM storage";
$sql = "SELECT * FROM storage AS S, devices AS D where S.host_id = D.device_id AND D.status = '1'";
$query = mysql_query($sql);
while ($store = mysql_fetch_array($query)) {
@@ -40,14 +48,13 @@ while ($store = mysql_fetch_array($query)) {
$i = 0;
while ($i < count($storage_exists) && !$exists) {
$thisstore = $store['host_id'] . " " . $store['hrStorageIndex'];
if ($storage_exists[$i] == $thisstore) { $exists = 1; echo("Match!"); }
if ($storage_exists[$i] == $thisstore) { $exists = 1; }
$i++;
echo("$storage_exists[$i] == $thisstore \n");
}
if(!$exists) {
echo("Deleting...\n");
# mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
echo("Deleting " . $store['hrStorageDescr'] . " from " . $store['hostname'] . "\n");
mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
}