mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
continuation of storage changes, addition of rrdtool functions
git-svn-id: http://www.observium.org/svn/observer/trunk@937 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -111,3 +111,6 @@ ALTER TABLE `processors` CHANGE `processor_oid` `processor_oid` VARCHAR( 128
|
||||
ALTER TABLE eventlog CHANGE `type` `type` VARCHAR( 64 ) NOT NULL;
|
||||
ALTER TABLE `services` CHANGE `service_host` `device_id` INT( 11 ) NOT NULL;
|
||||
CREATE TABLE IF NOT EXISTS `mempools` ( `mempool_id` int(11) NOT NULL AUTO_INCREMENT, `mempool_index` varchar(8) CHARACTER SET latin1 NOT NULL, `entPhysicalIndex` int(11) DEFAULT NULL, `hrDeviceIndex` int(11) DEFAULT NULL, `mempool_type` varchar(32) CHARACTER SET latin1 NOT NULL, `mempool_precision` int(11) NOT NULL DEFAULT '1', `mempool_descr` varchar(32) CHARACTER SET latin1 NOT NULL, `device_id` int(11) NOT NULL, `mempool_used` int(11) NOT NULL, `mempool_free` int(11) NOT NULL, `mempool_total` int(11) NOT NULL, `mempool_largestfree` int(11) DEFAULT NULL, `mempool_lowestfree` int(11) DEFAULT NULL, PRIMARY KEY (`mempool_id`), KEY `device_id` (`device_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin ;
|
||||
ALTER TABLE `storage` CHANGE `storage_id` `storage_id` INT( 11 ) NOT NULL AUTO_INCREMENT , CHANGE `host_id` `device_id` INT( 11 ) NOT NULL , CHANGE `hrStorageIndex` `storage_index` INT( 11 ) NOT NULL , CHANGE `hrStorageType` `storage_type` VARCHAR( 32 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL , CHANGE `hrStorageDescr` `storage_descr` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL , CHANGE `hrStorageSize` `storage_size` INT( 11 ) NOT NULL , CHANGE `hrStorageAllocationUnits` `storage_units` INT( 11 ) NOT NULL , CHANGE `hrStorageUsed` `storage_used` INT( 11 ) NOT NULL , CHANGE `storage_perc` `storage_perc` TEXT CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL;
|
||||
ALTER TABLE `storage` ADD `storage_mib` VARCHAR( 16 ) NOT NULL AFTER `device_id`;
|
||||
ALTER TABLE `storage` ADD `storage_free` INT NOT NULL AFTER `storage_used`;
|
||||
|
||||
@@ -26,6 +26,29 @@ function discover_link($local_interface_id, $protocol, $remote_interface_id, $re
|
||||
|
||||
}
|
||||
|
||||
function discover_storage(&$valid_storage, $device, $index, $type, $mib, $descr, $size, $units, $used = NULL) {
|
||||
|
||||
global $config; global $debug;
|
||||
if($debug) { echo("$device, $index, $type, $mib, $descr, $units, $used, $size\n"); }
|
||||
if($descr && $size > "0") {
|
||||
if(mysql_result(mysql_query("SELECT count(storage_id) FROM `storage` WHERE `storage_index` = '$index' AND `device_id` = '".$device['device_id']."' AND `storage_mib` = '$mib'"),0) == '0') {
|
||||
$query = "INSERT INTO storage (`device_id`, `storage_descr`, `storage_index`, `storage_mib`, `storage_type`, `storage_units`,`storage_size`,`storage_used`)
|
||||
values ('".$device['device_id']."', '$descr', '$index', '$mib','$type', '$units', '$size', '$used')";
|
||||
mysql_query($query);
|
||||
if($debug) { print $query . "\n"; mysql_error(); }
|
||||
echo("+");
|
||||
} else {
|
||||
echo(".");
|
||||
$query = "UPDATE `storage` SET `storage_descr` = '".$descr."', `storage_type` = '".$type."', `storage_units` = '".$units."', `storage_size` = '".$size."'
|
||||
WHERE `device_id` = '".$device['device_id']."' AND `storage_index` = '".$index."' AND `storage_mib` = '".$mib."'";
|
||||
mysql_query($query);
|
||||
if($debug) { print $query . "\n"; }
|
||||
}
|
||||
$valid_storage[$mib][$index] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function discover_processor(&$valid_processor, $device, $oid, $index, $type, $descr, $precision = "1", $current = NULL, $entPhysicalIndex = NULL, $hrDeviceIndex = NULL) {
|
||||
|
||||
global $config; global $debug;
|
||||
|
||||
@@ -6,7 +6,7 @@ if($device['os'] == "ios" || $device['os_type'] == "ios") {
|
||||
|
||||
$cmp_oids = array('ciscoMemoryPool');
|
||||
|
||||
foreach ($cmp_oids as $oid) { $cmp_array = snmp_cache_oid($oid, $device, $cmp_array, "CISCO-MEMORY-POOL-MIB"); }
|
||||
foreach ($cmp_oids as $oid) { $cmp_array = snmp_cache_oid($oid, $device, array(), "CISCO-MEMORY-POOL-MIB"); }
|
||||
|
||||
if(is_array($cmp_array)) {
|
||||
foreach($cmp_array[$device[device_id]] as $index => $cmp) {
|
||||
|
||||
33
includes/discovery/storage-hrstorage.inc.php
Executable file
33
includes/discovery/storage-hrstorage.inc.php
Executable file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
$storage_array = snmp_cache_oid("hrStorageEntry", $device, array(), "HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES");
|
||||
|
||||
if(is_array($storage_array)) {
|
||||
echo("hrStorage : ");
|
||||
foreach($storage_array[$device[device_id]] as $index => $storage) {
|
||||
foreach($config['ignore_mount'] as $bi) { if($bi == $descr) { $deny = 1; if ($debug) echo("$bi == $descr \n"); } }
|
||||
foreach($config['ignore_mount_string'] as $bi) { if(strpos($descr, $bi) !== FALSE) { $deny = 1; if ($debug) echo("$descr, $bi \n"); } }
|
||||
foreach($config['ignore_mount_regexp'] as $bi) { if(preg_match($bi, $descr)) { $deny = 1; if ($debug) echo("$bi, $descr \n"); } }
|
||||
if (isset($config['ignore_mount_removable']) && $config['ignore_mount_removable'] && $fstype == "hrStorageRemovableDisk") { $deny = 1; if ($debug) echo("skip(removable)\n"); }
|
||||
if (isset($config['ignore_mount_network']) && $config['ignore_mount_network'] && $fstype == "hrStorageNetworkDisk") { $deny = 1; if ($debug) echo("skip(network)\n"); }
|
||||
|
||||
$type = $storage['hrStorageType'];
|
||||
$descr = $storage['hrStorageDescr'];
|
||||
$size = $storage['hrStorageSize'] * $storage['hrStorageAllocationUnits'];
|
||||
$used = $storage['hrStorageUsed'] * $storage['hrStorageAllocationUnits'];
|
||||
$units = $storage['hrStorageAllocationUnits'];
|
||||
|
||||
if(!$deny && is_numeric($index)) {
|
||||
discover_storage($valid_storage, $device, $index, $type, "hrstorage", $descr, $size , $units, $used);
|
||||
}
|
||||
|
||||
#$old_storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("hrStorage-" . $index . ".rrd");
|
||||
#$storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("storage-hrstorage-" . $index . ".rrd");
|
||||
#if(is_file($old_storage_rrd)) { rename($old_storage_rrd,$storage_rrd); }
|
||||
|
||||
unset($deny, $type, $descr, $size, $used, $units, $storage_rrd, $old_storage_rrd, $storage_array);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,70 +1,28 @@
|
||||
<?php
|
||||
|
||||
unset( $storage_exists );
|
||||
echo("Storage : ");
|
||||
|
||||
echo("HOST-RESOURCES-MIB Storage : ");
|
||||
include("storage-hrstorage.inc.php");
|
||||
|
||||
$oids = shell_exec($config['snmpwalk'] . " -CI -m HOST-RESOURCES-MIB -Osq -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageIndex");
|
||||
$oids = trim(str_replace("hrStorageIndex.","",$oids));
|
||||
### Remove storage which weren't redetected here
|
||||
|
||||
foreach(explode("\n", $oids) as $data) {
|
||||
if($data) {
|
||||
$data = trim($data);
|
||||
list($oid,$hrStorageIndex) = explode(" ", $data);
|
||||
$temp = shell_exec($config['snmpget'] . " -m HOST-RESOURCES-MIB:HOST-RESOURCES-TYPES -O sqv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageDescr.$oid hrStorageAllocationUnits.$oid hrStorageSize.$oid hrStorageType.$oid");
|
||||
$temp = trim($temp);
|
||||
list($descr, $units, $size, $fstype) = explode("\n", $temp);
|
||||
list($units) = explode(" ", $units);
|
||||
$allow = 1;
|
||||
foreach($config['ignore_mount'] as $bi) { if($bi == $descr) { $allow = 0; if ($debug) echo("$bi == $descr \n"); } }
|
||||
foreach($config['ignore_mount_string'] as $bi) { if(strpos($descr, $bi) !== FALSE) { $allow = 0; if ($debug) echo("$descr, $bi \n"); } }
|
||||
foreach($config['ignore_mount_regexp'] as $bi) { if(preg_match($bi, $descr)) { $allow = 0; if ($debug) echo("$bi, $descr \n"); } }
|
||||
if (isset($config['ignore_mount_removable']) && $config['ignore_mount_removable'] && $fstype == "hrStorageRemovableDisk") { $allow = 0; if ($debug) echo("removable, skipping\n"); }
|
||||
if (isset($config['ignore_mount_network']) && $config['ignore_mount_network'] && $fstype == "hrStorageNetworkDisk") { $allow = 0; if ($debug) echo("network, skipping\n"); }
|
||||
$descr = str_replace("mounted on: ", "", $descr);
|
||||
$descr = preg_replace("/: [A-Za-z0-9_]+ file system, /", ", ", $descr);
|
||||
if ($debug) { echo("$fstype"); }
|
||||
|
||||
if($size > '0' && $allow) {
|
||||
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`, `hrStorageType`, `hrStorageDescr`,`hrStorageSize`,`hrStorageAllocationUnits`) ";
|
||||
$query .= "values ('".$device['device_id']."', '$hrStorageIndex', '$fstype', '$descr', '$size', '$units')";
|
||||
mysql_query($query); if($debug) { echo("$query"); }
|
||||
echo("+");
|
||||
} else {
|
||||
$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 || $data['hrStorageType'] != $fstype) {
|
||||
$query = "UPDATE storage SET `hrStorageDescr` = '$descr', `hrStorageType` = '$fstype', `hrStorageSize` = '$size', `hrStorageAllocationUnits` = '$units' ";
|
||||
$query .= ", `hrStorageType` = '$fstype' ";
|
||||
$query .= "WHERE hrStorageIndex = '$hrStorageIndex' AND host_id = '".$device['device_id']."'";
|
||||
echo("U");
|
||||
if($debug) { echo("$query \n"); }
|
||||
mysql_query($query);
|
||||
} else { echo("."); }
|
||||
}
|
||||
$storage_exists[] = $device['device_id']." $hrStorageIndex";
|
||||
} else { echo("X"); };
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM storage AS S, devices AS D where S.host_id = D.device_id AND D.device_id = '".$device['device_id']."'";
|
||||
$sql = "SELECT * FROM `storage` WHERE `device_id` = '".$device['device_id']."'";
|
||||
$query = mysql_query($sql);
|
||||
|
||||
while ($store = mysql_fetch_array($query)) {
|
||||
unset($exists);
|
||||
$i = 0;
|
||||
while ($i < count($storage_exists) && !isset($exists)) {
|
||||
$thisstore = $store['host_id'] . " " . $store['hrStorageIndex'];
|
||||
if ($storage_exists[$i] == $thisstore) { $exists = 1; }
|
||||
$i++;
|
||||
}
|
||||
if(!$exists) {
|
||||
if($debug) { print_r ($valid_storage); }
|
||||
|
||||
while ($test_storage = mysql_fetch_array($query)) {
|
||||
$storage_index = $test_storage['storage_index'];
|
||||
$storage_mib = $test_storage['storage_mib'];
|
||||
if($debug) { echo($storage_index . " -> " . $storage_mib . "\n"); }
|
||||
if(!$valid_storage[$storage_mib][$storage_index]) {
|
||||
echo("-");
|
||||
mysql_query("DELETE FROM storage WHERE storage_id = '" . $store['storage_id'] . "'");
|
||||
mysql_query("DELETE FROM `storage` WHERE storage_id = '" . $test_storage['storage_id'] . "'");
|
||||
}
|
||||
unset($storage_index); unset($storage_mib);
|
||||
}
|
||||
|
||||
unset($valid_storage);
|
||||
echo("\n");
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -8,7 +8,7 @@ include_once("Net/IPv6.php");
|
||||
## Observer Includes
|
||||
|
||||
include_once($config['install_dir'] . "/includes/common.php");
|
||||
|
||||
include_once($config['install_dir'] . "/includes/rrdtool.inc.php");
|
||||
include_once($config['install_dir'] . "/includes/generic.php");
|
||||
include_once($config['install_dir'] . "/includes/procurve.php");
|
||||
include_once($config['install_dir'] . "/includes/graphing.php");
|
||||
@@ -105,22 +105,6 @@ function shorthost($hostname, $len=16)
|
||||
return ($shorthost);
|
||||
}
|
||||
|
||||
function rrdtool_update($rrdfile, $rrdupdate)
|
||||
{
|
||||
global $config, $debug;
|
||||
|
||||
if ($debug) { echo($config['rrdtool'] . " update $rrdfile $rrdupdate \n"); }
|
||||
return shell_exec($config['rrdtool'] . " update $rrdfile $rrdupdate");
|
||||
}
|
||||
|
||||
function rrdtool($command, $file, $options)
|
||||
{
|
||||
global $config;
|
||||
|
||||
if ($config['debug']) { echo($config['rrdtool'] . " $command $file $options \n"); }
|
||||
return shell_exec($config['rrdtool'] . " $command $file $options");
|
||||
}
|
||||
|
||||
function device_array($device_id)
|
||||
{
|
||||
$sql = "SELECT * FROM `devices` WHERE `device_id` = '".$device_id."'";
|
||||
@@ -256,19 +240,6 @@ function print_message($text)
|
||||
echo('<table class="messagebox" cellpadding="3"><tr><td><img src="/images/16/tick.png" align="absmiddle">'.$text.'</td></tr></table>');
|
||||
}
|
||||
|
||||
function interface_rates ($rrd_file) // Returns the last in/out value in RRD
|
||||
{
|
||||
global $config;
|
||||
$cmd = $config['rrdtool']." fetch -s -600s -e now $rrd_file AVERAGE | grep : | cut -d\" \" -f 2,3 | grep e";
|
||||
$data = trim(`$cmd`);
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
list($in, $out) = split(" ", $entry);
|
||||
$rate['in'] = $in * 8;
|
||||
$rate['out'] = $out * 8;
|
||||
}
|
||||
return $rate;
|
||||
}
|
||||
|
||||
function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/out errors value in RRD
|
||||
{
|
||||
global $config;
|
||||
@@ -284,19 +255,6 @@ function interface_errors ($rrd_file, $period = '-1d') // Returns the last in/ou
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function interface_packets ($rrd_file) // Returns the last in/out pps value in RRD
|
||||
{
|
||||
global $config;
|
||||
$cmd = $config['rrdtool']." fetch -s -1d -e -300s $rrd_file AVERAGE | grep : | cut -d\" \" -f 6,7";
|
||||
$data = trim(shell_exec($cmd));
|
||||
foreach( explode("\n", $data) as $entry) {
|
||||
list($in, $out) = explode(" ", $entry);
|
||||
}
|
||||
$packets['in'] = round($in);
|
||||
$packets['out'] = round($out);
|
||||
return $packets;
|
||||
}
|
||||
|
||||
function geteventicon ($message)
|
||||
{
|
||||
if ($message == "Device status changed to Down") { $icon = "server_connect.png"; }
|
||||
@@ -389,7 +347,6 @@ function getImage($host)
|
||||
return $image;
|
||||
}
|
||||
|
||||
|
||||
function renamehost($id, $new) {
|
||||
global $config;
|
||||
$host = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '$id'"), 0);
|
||||
@@ -425,7 +382,7 @@ function delHost($id)
|
||||
mysql_query("DELETE FROM `temperature` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `vrfs` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `storage` WHERE `host_id` = '$id'");
|
||||
mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `eventlog` WHERE `host` = '$id'");
|
||||
mysql_query("DELETE FROM `syslog` WHERE `device_id` = '$id'");
|
||||
@@ -456,7 +413,7 @@ function retireHost($id)
|
||||
}
|
||||
mysql_query("DELETE FROM `entPhysical` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `temperature` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `storage` WHERE `host_id` = '$id'");
|
||||
mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `alerts` WHERE `device_id` = '$id'");
|
||||
mysql_query("DELETE FROM `services` WHERE `device_id` = '$id'");
|
||||
shell_exec("rm -rf ".$config['rrd_dir']."/$host");
|
||||
|
||||
@@ -360,13 +360,13 @@ function unixfsgraph ($id, $graph, $from, $to, $width, $height, $title, $vertica
|
||||
$sql = mysql_query("SELECT * FROM storage where storage_id = '$id'");
|
||||
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Size\ \ \ \ \ \ Used\ \ \ \ %age\l";
|
||||
while($fs = mysql_fetch_array($sql)) {
|
||||
$hostname = gethostbyid($fs['host_id']);
|
||||
$hostname = gethostbyid($fs['device_id']);
|
||||
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
|
||||
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
|
||||
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
|
||||
$descr = str_pad($fs[hrStorageDescr], 14);
|
||||
$descr = str_pad($fs[storage_descr], 14);
|
||||
$descr = substr($descr,0,14);
|
||||
$text = str_replace("/", "_", $fs['hrStorageDescr']);
|
||||
$text = str_replace("/", "_", $fs['storage_descr']);
|
||||
$rrd = $config['rrd_dir'] . "/$hostname/storage-$text.rrd";
|
||||
$options .= " DEF:$fs[storage_id]=$rrd:used:AVERAGE";
|
||||
$options .= " DEF:$fs[storage_id]s=$rrd:size:AVERAGE";
|
||||
@@ -391,16 +391,16 @@ function unixfsgraph_dev ($device, $graph, $from, $to, $width, $height, $title,
|
||||
if($width <= "300") { $options .= " --font LEGEND:7:".$config['mono_font']." --font AXIS:6:".$config['mono_font']." --font-render-mode normal "; }
|
||||
$hostname = gethostbyid($device);
|
||||
$iter = "1";
|
||||
$sql = mysql_query("SELECT * FROM storage where host_id = '$device'");
|
||||
$sql = mysql_query("SELECT * FROM storage where device_id = '$device'");
|
||||
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Size\ \ \ \ \ \ Used\ \ \ \ %age\l";
|
||||
while($fs = mysql_fetch_array($sql)) {
|
||||
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
|
||||
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
|
||||
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
|
||||
|
||||
$descr = str_pad($fs[hrStorageDescr], 14);
|
||||
$descr = str_pad($fs[storage_descr], 14);
|
||||
$descr = substr($descr,0,14);
|
||||
$text = str_replace("/", "_", $fs['hrStorageDescr']);
|
||||
$text = str_replace("/", "_", $fs['storage_descr']);
|
||||
$rrd = $config['rrd_dir'] . "/$hostname/storage-$text.rrd";
|
||||
$options .= " DEF:$fs[storage_id]=$rrd:used:AVERAGE";
|
||||
$options .= " DEF:$fs[storage_id]s=$rrd:size:AVERAGE";
|
||||
|
||||
@@ -33,6 +33,5 @@ if (!is_file($hrSystem_rrd)) {
|
||||
|
||||
rrdtool_update($hrSystem_rrd, "N:$hrSystemNumUsers:$hrSystemProcesses:$uptime");
|
||||
|
||||
include("hr-mib_storage.inc.php"); // Run HOST-RESOURCES-MIB Storage
|
||||
|
||||
?>
|
||||
|
||||
@@ -2,20 +2,21 @@
|
||||
|
||||
/// HOST-RESOURCES-MIB - Storage Objects
|
||||
|
||||
$dq = mysql_query("SELECT * FROM storage WHERE host_id = '" . $device['device_id'] . "'");
|
||||
$dq = mysql_query("SELECT * FROM storage WHERE device_id = '" . $device['device_id'] . "'");
|
||||
while ($dr = mysql_fetch_array($dq)) {
|
||||
$hrStorageIndex = $dr['hrStorageIndex'];
|
||||
$hrStorageAllocationUnits = $dr['hrStorageAllocationUnits'];
|
||||
$hrStorageSize = $dr['hrStorageAllocationUnits'] * $dr['hrStorageSize'];
|
||||
$hrStorageDescr = $dr['hrStorageDescr'];
|
||||
$cmd = $config['snmpget'] . " -m HOST-RESOURCES-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " hrStorageUsed.$hrStorageIndex";
|
||||
$storage_index = $dr['storage_index'];
|
||||
$storage_units = $dr['storage_units'];
|
||||
$storage_size = $dr['storage_units'] * $dr['storage_size'];
|
||||
$storage_descr = $dr['storage_descr'];
|
||||
$cmd = $config['snmpget'] . " -m HOST-RESOURCES-MIB -O qv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " storage_used.$storage_index";
|
||||
$used_units = trim(shell_exec($cmd));
|
||||
$used = $used_units * $hrStorageAllocationUnits;
|
||||
$perc = round($used / $hrStorageSize * 100, 2);
|
||||
$filedesc = str_replace("\"", "", str_replace("/", "_", $hrStorageDescr));
|
||||
$used = $used_units * $storage_units;
|
||||
$perc = round($used / $storage_size * 100, 2);
|
||||
$filedesc = str_replace("\"", "", str_replace("/", "_", $storage_descr));
|
||||
$old_storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("storage-" . $filedesc . ".rrd");
|
||||
$storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("hrStorage-" . $hrStorageIndex . ".rrd");
|
||||
$storage_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("hrStorage-" . $storage_index . ".rrd");
|
||||
if(is_file($old_storage_rrd)) { rename($old_storage_rrd,$storage_rrd); }
|
||||
|
||||
if (!is_file($storage_rrd)) {
|
||||
shell_exec($config['rrdtool'] . " create $storage_rrd \
|
||||
--step 300 \
|
||||
@@ -31,13 +32,14 @@ while ($dr = mysql_fetch_array($dq)) {
|
||||
RRA:MAX:0.5:24:800 \
|
||||
RRA:MAX:0.5:288:800");
|
||||
}
|
||||
rrdtool_update($storage_rrd, "N:$hrStorageSize:$used:$perc");
|
||||
mysql_query("UPDATE `storage` SET `hrStorageUsed` = '$used_units', `storage_perc` = '$perc' WHERE storage_id = '" . $dr['storage_id'] . "'");
|
||||
|
||||
rrdtool_update($storage_rrd, "N:$storage_size:$used:$perc");
|
||||
mysql_query("UPDATE `storage` SET `storage_used` = '$used_units', `storage_perc` = '$perc' WHERE storage_id = '" . $dr['storage_id'] . "'");
|
||||
if (!is_numeric($dr['storage_perc_warn'])) { $dr['storage_perc_warn'] = 60; }
|
||||
if($dr['storage_perc'] < $dr['storage_perc_warn'] && $perc >= $dr['storage_perc_warn'])
|
||||
{
|
||||
$msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['hrStorageDescr'] . " is " . $perc . "% at " . date('l dS F Y h:i:s A');
|
||||
notify($device, "Disk Alarm: " . $device['hostname'] . " " . $dr['hrStorageDescr'], $msg);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dr['hrStorageDescr'] . "\n");
|
||||
$msg = "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'] . " is " . $perc . "% at " . date('l dS F Y h:i:s A');
|
||||
notify($device, "Disk Alarm: " . $device['hostname'] . " " . $dr['storage_descr'], $msg);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $dr['storage_descr'] . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,8 +676,6 @@ function rewrite_junose_hardware ($hardware)
|
||||
return ($hardware);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function fixiftype ($type)
|
||||
{
|
||||
global $rewrite_iftype;
|
||||
|
||||
40
includes/rrdtool.inc.php
Normal file
40
includes/rrdtool.inc.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
function rrdtool_update($rrdfile, $rrdupdate)
|
||||
{
|
||||
return rrdtool("update", $rrdfile, $rrdupdate);
|
||||
}
|
||||
|
||||
function rrdtool_create($rrdfile, $rrdupdate)
|
||||
{
|
||||
return rrdtool("create", $rrdfile, $rrdupdate);
|
||||
}
|
||||
|
||||
function rrdtool_fetch($rrdfile, $rrdupdate)
|
||||
{
|
||||
return rrdtool("fetch", $rrdfile, $rrdupdate);
|
||||
}
|
||||
|
||||
function rrdtool_graph($rrdfile, $rrdupdate)
|
||||
{
|
||||
return rrdtool("graph", $rrdfile, $rrdupdate);
|
||||
}
|
||||
|
||||
function rrdtool_last($rrdfile, $rrdupdate)
|
||||
{
|
||||
return rrdtool("last", $rrdfile, $rrdupdate);
|
||||
}
|
||||
|
||||
function rrdtool_lastupdate($rrdfile, $rrdupdate)
|
||||
{
|
||||
return rrdtool("lastupdate", $rrdfile, $rrdupdate);
|
||||
}
|
||||
|
||||
function rrdtool($command, $file, $options)
|
||||
{
|
||||
global $config; global $debug;
|
||||
if ($config['debug']) { echo($config['rrdtool'] . " $command $file $options \n"); }
|
||||
return shell_exec($config['rrdtool'] . " $command $file $options");
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -345,13 +345,13 @@ function unixfsgraph ($id, $graph, $from, $to, $width, $height, $title, $vertica
|
||||
$sql = mysql_query("SELECT * FROM storage where storage_id = '$id'");
|
||||
$options .= "COMMENT:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ Size\ \ \ \ \ \ Used\ \ \ \ %age\l";
|
||||
while($fs = mysql_fetch_array($sql)) {
|
||||
$hostname = gethostbyid($fs['host_id']);
|
||||
$hostname = gethostbyid($fs['device_id']);
|
||||
if($iter=="1") {$colour="CC0000";} elseif($iter=="2") {$colour="008C00";} elseif($iter=="3") {$colour="4096EE";
|
||||
} elseif($iter=="4") {$colour="73880A";} elseif($iter=="5") {$colour="D01F3C";} elseif($iter=="6") {$colour="36393D";
|
||||
} elseif($iter=="7") {$colour="FF0084"; $iter = "0"; }
|
||||
$descr = str_pad($fs[hrStorageDescr], 14);
|
||||
$descr = str_pad($fs[storage_descr], 14);
|
||||
$descr = substr($descr,0,14);
|
||||
$text = str_replace("/", "_", $fs['hrStorageDescr']);
|
||||
$text = str_replace("/", "_", $fs['storage_descr']);
|
||||
$rrd = $config['rrd_dir'] . "/$hostname/storage-$text.rrd";
|
||||
$options .= " DEF:$fs[storage_id]=$rrd:used:AVERAGE";
|
||||
$options .= " DEF:$fs[storage_id]s=$rrd:size:AVERAGE";
|
||||
|
||||
@@ -115,6 +115,7 @@ while ($device = mysql_fetch_array($device_query)) {
|
||||
include("includes/polling/voltages.inc.php");
|
||||
include("includes/polling/processors.inc.php");
|
||||
include("includes/polling/mempools.inc.php");
|
||||
include("includes/polling/storage.inc.php");
|
||||
include("includes/polling/device-netstats.inc.php");
|
||||
include("includes/polling/ipSystemStats.inc.php");
|
||||
include("includes/polling/ports.inc.php");
|
||||
|
||||
Reference in New Issue
Block a user