2009-09-07 11:07:59 +00:00
< ? php
2007-04-03 14:10:23 +00:00
2008-03-22 23:09:35 +00:00
unset ( $storage_exists );
2009-11-07 02:30:38 +00:00
echo ( " hrStorage : " );
2008-03-22 23:09:35 +00:00
2009-04-24 15:04:45 +00:00
$oids = shell_exec ( $config [ 'snmpwalk' ] . " -m HOST-RESOURCES-MIB -Osq - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " hrStorageIndex " );
2008-03-22 23:09:35 +00:00
$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 );
2009-05-11 13:43:59 +00:00
$temp = shell_exec ( $config [ 'snmpget' ] . " -m HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES -O qv - " . $device [ 'snmpver' ] . " -c " . $device [ 'community' ] . " " . $device [ 'hostname' ] . " : " . $device [ 'port' ] . " hrStorageDescr. $oid hrStorageAllocationUnits. $oid hrStorageSize. $oid hrStorageType. $oid " );
2007-04-03 14:10:23 +00:00
$temp = trim ( $temp );
2009-05-11 13:43:59 +00:00
list ( $descr , $units , $size , $fstype ) = explode ( " \n " , $temp );
2007-04-03 14:10:23 +00:00
list ( $units ) = explode ( " " , $units );
2008-03-23 21:32:54 +00:00
$allow = 1 ;
foreach ( $config [ 'ignore_mount' ] as $bi ) {
if ( $descr == $bi ) {
$allow = 0 ;
}
}
2009-05-11 13:43:59 +00:00
if ( strstr ( $fstype , " 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' ) {
2007-11-23 11:37:28 +00:00
$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 ( " + " );
2007-11-23 11:37:28 +00:00
} 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' ] . " ' " ));
2007-11-23 11:37:28 +00:00
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 " );
2007-11-23 11:37:28 +00:00
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' ];
2007-11-23 11:37:28 +00:00
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 ( " - " );
2007-11-23 11:37:28 +00:00
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
?>