Files
librenms-librenms/includes/discovery/storage.php
T

72 lines
2.7 KiB
PHP
Raw Normal View History

2007-04-03 14:10:23 +00:00
<?
2008-03-22 23:09:35 +00:00
unset( $storage_exists );
echo("Storage : ");
$oids = shell_exec($config['snmpwalk'] . " -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageIndex");
$oids = trim(str_replace("hrStorageIndex.","",$oids));
2007-04-03 14:10:23 +00:00
foreach(explode("\n", $oids) as $data) {
$data = trim($data);
2007-05-20 19:21:35 +00:00
list($oid,$hrStorageIndex) = explode(" ", $data);
2008-03-22 23:09:35 +00:00
$temp = shell_exec($config['snmpget'] . " -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'] . " hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid");
2007-04-03 14:10:23 +00:00
$temp = trim($temp);
list($descr, $units, $size, $type) = explode("\n", $temp);
list($units) = explode(" ", $units);
2008-03-23 21:32:54 +00:00
$allow = 1;
foreach($config['ignore_mount'] as $bi) {
# echo("$descr == $bi\n");
if($descr == $bi) {
$allow = 0;
}
}
if(strstr($type, "FixedDisk") && $size > '0' && $allow) {
2008-03-22 23:09:35 +00:00
if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'"),0) == '0') {
$query = "INSERT INTO storage (`host_id`, `hrStorageIndex`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) ";
2008-03-22 23:09:35 +00:00
$query .= "values ('".$device['device_id']."', '$hrStorageIndex', '$descr', '$size', '$units')";
2007-04-03 14:10:23 +00:00
mysql_query($query);
2008-03-22 23:09:35 +00:00
echo("+");
} else {
2008-03-22 23:09:35 +00:00
$data = mysql_fetch_array(mysql_query("SELECT * FROM `storage` WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'"));
if($data['hrStorageDescr'] != $descr || $data['hrStorageSize'] != $size || $data['hrStorageAllocationUnits'] != $units ) {
$query = "UPDATE storage SET `hrStorageDescr` = '$descr', `hrStorageSize` = '$size', `hrStorageAllocationUnits` = '$units' ";
2008-03-22 23:09:35 +00:00
$query .= "WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'";
echo("U");
mysql_query($query);
2008-03-22 23:09:35 +00:00
} else { echo("."); }
2007-04-03 14:10:23 +00:00
}
2008-03-22 23:09:35 +00:00
$storage_exists[] = $device[device_id]." $hrStorageIndex";
2008-03-23 21:32:54 +00:00
} else { echo("X"); };
2007-04-03 14:10:23 +00:00
}
2007-05-20 19:21:35 +00:00
2008-03-22 23:09:35 +00:00
$sql = "SELECT * FROM storage AS S, devices AS D where S.host_id = D.device_id AND D.device_id = '".$device['device_id']."'";
2007-05-20 19:21:35 +00:00
$query = mysql_query($sql);
while ($store = mysql_fetch_array($query)) {
unset($exists);
$i = 0;
while ($i < count($storage_exists) && !$exists) {
$thisstore = $store['host_id'] . " " . $store['hrStorageIndex'];
if ($storage_exists[$i] == $thisstore) { $exists = 1; }
2007-05-20 19:21:35 +00:00
$i++;
}
if(!$exists) {
2008-03-22 23:09:35 +00:00
echo("-");
mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
2007-05-20 19:21:35 +00:00
}
}
2008-03-22 23:09:35 +00:00
echo("\n");
2007-05-20 19:21:35 +00:00
2007-04-03 14:10:23 +00:00
?>