mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
rewrite of some discovery stuff
git-svn-id: http://www.observium.org/svn/observer/trunk@840 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -8,13 +8,14 @@ $port = $device['port'];
|
||||
echo("Fanspeeds : ");
|
||||
|
||||
## LMSensors Fanspeeds
|
||||
/*
|
||||
if ($device['os'] == "linux")
|
||||
{
|
||||
$oids = shell_exec($config['snmpwalk'] . " -m LM-SENSORS-MIB -$snmpver -CI -Osqn -c $community $hostname:$port lmTempSensorsDevice");
|
||||
$oids = snmp_walk($device, "lmFanSensorsDevice", "-OsqnU", "LM-SENSORS-MIB");
|
||||
if ($debug) { echo($oids."\n"); }
|
||||
$oids = trim($oids);
|
||||
if ($oids) echo("LM-SENSORS ");
|
||||
$precision = 1;
|
||||
$type = 'lmsensors';
|
||||
foreach(explode("\n", $oids) as $data)
|
||||
{
|
||||
$data = trim($data);
|
||||
@@ -22,70 +23,48 @@ if ($device['os'] == "linux")
|
||||
{
|
||||
list($oid,$descr) = explode(" ", $data,2);
|
||||
$split_oid = explode('.',$oid);
|
||||
$fan_id = $split_oid[count($split_oid)-1];
|
||||
$fan_oid = "1.3.6.1.4.1.2021.13.16.2.1.3.$fan_id";
|
||||
$fan = trim(shell_exec($config['snmpget'] . " -m LM-SENSORS-MIB -O qv -$snmpver -c $community $hostname:$port $fan_oid")) / 1000;
|
||||
$descr = str_ireplace("temp-", "", $descr);
|
||||
$descr = trim($descr);
|
||||
if (mysql_result(mysql_query("SELECT count(fan_id) FROM `fanspeed` WHERE fan_oid = '$fan_oid' AND device_id = '$id'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO fanspeed (`device_id`, `fan_oid`, `fan_descr`, `fan_precision`, `fan_limit`, `fan_current`) values ('$id', '$fan_oid', '$descr',1000, " . ($config['defaults']['fan_limit'] ? $config['defaults']['fan_limit'] : '60') . ", '$fan')";
|
||||
mysql_query($query);
|
||||
echo("+");
|
||||
}
|
||||
elseif (mysql_result(mysql_query("SELECT `fan_descr` FROM fanspeed WHERE `device_id` = '$id' AND `fan_oid` = '$fan_oid'"), 0) != $descr)
|
||||
{
|
||||
echo("U");
|
||||
mysql_query("UPDATE fanspeed SET `fan_descr` = '$descr' WHERE `device_id` = '$id' AND `fan_oid` = '$fan_oid'");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
$fan_exists[] = "$id $fan_oid";
|
||||
$index = $split_oid[count($split_oid)-1];
|
||||
$oid = ".1.3.6.1.4.1.2021.13.16.3.1.3.". $index;
|
||||
$current = snmp_get($device, $oid, "-Oqv", "LM-SENSORS-MIB");
|
||||
$descr = trim(str_ireplace("fan-", "", $descr));
|
||||
discover_fan($device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $high_limit = NULL, $current = NULL);
|
||||
$fan_exists[$type][$index] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
## Supermicro Fanspeeds
|
||||
if ($device['os'] == "linux")
|
||||
{
|
||||
$oids = shell_exec($config['snmpwalk'] . " -m SUPERMICRO-HEALTH-MIB -$snmpver -CI -Osqn -c $community $hostname:$port 1.3.6.1.4.1.10876.2.1.1.1.1.3 | sed s/1.3.6.1.4.1.10876.2.1.1.1.1.3.//g");
|
||||
$oids = snmp_walk($device, "1.3.6.1.4.1.10876.2.1.1.1.1.3", "-OsqnU", "SUPERMICRO-HEALTH-MIB");
|
||||
$oids = str_replace("1.3.6.1.4.1.10876.2.1.1.1.1.3.", "", $oids);
|
||||
if ($debug) { echo($oids."\n"); }
|
||||
$oids = trim($oids);
|
||||
if ($oids) echo("Supermicro ");
|
||||
$type = "supermicro";
|
||||
foreach(explode("\n", $oids) as $data)
|
||||
{
|
||||
$data = trim($data);
|
||||
if ($data)
|
||||
{
|
||||
list($oid,$type) = explode(" ", $data);
|
||||
if ($type == 0)
|
||||
list($index,$kind) = explode(" ", $data);
|
||||
if ($kind == 0)
|
||||
{
|
||||
$fan_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.4$oid";
|
||||
$descr_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.2$oid";
|
||||
$limit_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.6$oid";
|
||||
$divisor_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.9$oid";
|
||||
$monitor_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.10$oid";
|
||||
$descr = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $descr_oid"));
|
||||
$fan = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $fan_oid"));
|
||||
$limit = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $limit_oid"));
|
||||
$divisor = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $divisor_oid"));
|
||||
$monitor = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $monitor_oid"));
|
||||
$oid = "1.3.6.1.4.1.10876.2.1.1.1.1.4$index";
|
||||
$descr_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.2$index";
|
||||
$limit_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.6$index";
|
||||
$precision_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.9$index";
|
||||
$monitor_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.10$index";
|
||||
$descr = snmp_get($device, $descr_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB");
|
||||
$current = snmp_get($device, $fan_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB");
|
||||
$limit = snmp_get($device, $limit_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB");
|
||||
$precision = snmp_get($device, $precision_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB");
|
||||
$monitor = snmp_get($device, $monitor_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB");
|
||||
if ($monitor == 'true')
|
||||
{
|
||||
$descr = trim(str_replace(" Fan","",str_ireplace("Speed", "", $descr)));
|
||||
if (mysql_result(mysql_query("SELECT count(fan_id) FROM `fanspeed` WHERE fan_oid = '$fan_oid' AND device_id = '$id'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO fanspeed (`device_id`, `fan_oid`, `fan_descr`, `fan_current`, `fan_limit`) values ('$id', '$fan_oid', '$descr', '$fan', '$limit')";
|
||||
mysql_query($query);
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
$fan_exists[] = "$id $fan_oid";
|
||||
discover_fan($device, $oid, $index, $type, $descr, $precision = 1, NULL, $limit, $current);
|
||||
$fan_exists[$type][$index] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,24 +73,19 @@ if ($device['os'] == "linux")
|
||||
|
||||
## Delete removed sensors
|
||||
|
||||
$sql = "SELECT * FROM fanspeed AS V, devices AS D WHERE V.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
|
||||
if($debug) { echo("\n Checking ... \n"); print_r($fan_exists); }
|
||||
|
||||
$sql = "SELECT * FROM fanspeed WHERE device_id = '".$device['device_id']."'";
|
||||
if ($query = mysql_query($sql))
|
||||
{
|
||||
while ($sensor = mysql_fetch_array($query))
|
||||
{
|
||||
unset($exists);
|
||||
$i = 0;
|
||||
while ($i < count($fan_exists) && !$exists)
|
||||
{
|
||||
$thisfan = $sensor['device_id'] . " " . $sensor['fan_oid'];
|
||||
if ($fan_exists[$i] == $thisfan) { $exists = 1; }
|
||||
$i++;
|
||||
}
|
||||
|
||||
if (!$exists)
|
||||
{
|
||||
while ($test_fan = mysql_fetch_array($query))
|
||||
{
|
||||
if($debug) { echo("$fan_type -> $fan_index\n"); }
|
||||
$fan_index = $test_fan['fan_index'];
|
||||
$fan_type = $test_fan['fan_type'];
|
||||
if(!$fan_exists[$fan_type][$fan_index]) {
|
||||
echo("-");
|
||||
mysql_query("DELETE FROM fanspeed WHERE fan_id = '" . $sensor['fan_id'] . "'");
|
||||
mysql_query("DELETE FROM `fanspeed` WHERE fan_id = '" . $test_fan['fan_id'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
27
includes/discovery/functions.inc.php
Normal file
27
includes/discovery/functions.inc.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
function discover_fan($device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $high_limit = NULL, $current = NULL) {
|
||||
|
||||
global $config; global $debug;
|
||||
if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); }
|
||||
if(!$low_limit) { $low_limit = $config['limit']['fan']; }
|
||||
if (mysql_result(mysql_query("SELECT count(fan_id) FROM `fanspeed` WHERE device_id = '".$device['device_id']."' AND fan_type = '$type' AND `fan_index` = '$index'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO fanspeed (`device_id`, `fan_oid`, `fan_index`, `fan_type`, `fan_descr`, `fan_precision`, `fan_limit`, `fan_current`) ";
|
||||
$query .= " VALUES ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$low_limit', '$current')";
|
||||
mysql_query($query);
|
||||
$return = "+";
|
||||
} else {
|
||||
$fan_entry = mysql_fetch_array(mysql_query("SELECT count(fan_id) FROM `fanspeed` WHERE device_id = '".$device['device_id']."' AND fan_type = '$type' AND `fan_index` = '$index'"));
|
||||
if($oid == $fan_entry['fan_oid'] && $descr == $fan_entry['fan_descr'] && $precision == $fan_entry['fan_precision']) {
|
||||
$return = ".";
|
||||
} else {
|
||||
mysql_query("UPDATE fanspeed SET `fan_descr` = '$descr', `fan_oid` = '$oid', `fan_precision` = '$precision' WHERE `device_id` = '$id' AND fan_type = '$type' AND `fan_index` = '$fan_index' ");
|
||||
$return = "U";
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -7,13 +7,11 @@ $port = $device['port'];
|
||||
|
||||
echo("Voltages : ");
|
||||
|
||||
## LMSensors Voltages
|
||||
/*
|
||||
## LMSensors Voltages (returned as 10,000ths of a volt.)
|
||||
|
||||
if ($device['os'] == "linux")
|
||||
{
|
||||
$oids = shell_exec($config['snmpwalk'] . " -m LM-SENSORS-MIB -$snmpver -CI -Osqn -c $community $hostname:$port lmTempSensorsDevice");
|
||||
if ($debug) { echo($oids."\n"); }
|
||||
$oids = trim($oids);
|
||||
$oids = snmp_walk($device, "lmTempSensorsDevice", "-OsqnU", "LM-SENSORS-MIB");
|
||||
if ($oids) echo("LM-SENSORS ");
|
||||
foreach(explode("\n", $oids) as $data)
|
||||
{
|
||||
@@ -23,13 +21,14 @@ if ($device['os'] == "linux")
|
||||
list($oid,$descr) = explode(" ", $data,2);
|
||||
$split_oid = explode('.',$oid);
|
||||
$volt_id = $split_oid[count($split_oid)-1];
|
||||
$volt_oid = "1.3.6.1.4.1.2021.13.16.2.1.3.$volt_id";
|
||||
$volt = trim(shell_exec($config['snmpget'] . " -m LM-SENSORS-MIB -O qv -$snmpver -c $community $hostname:$port $volt_oid")) / 1000;
|
||||
$volt_oid = "1.3.6.1.4.1.2021.13.16.2.1.3." . $volt_id;
|
||||
$volt = snmp_get($device, $volt_oid, "-Oqv", "LM-SENSORS-MIB");
|
||||
$volt = $volt / 10000;
|
||||
$descr = str_ireplace("temp-", "", $descr);
|
||||
$descr = trim($descr);
|
||||
if (mysql_result(mysql_query("SELECT count(volt_id) FROM `voltage` WHERE volt_oid = '$volt_oid' AND device_id = '$id'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO voltage (`device_id`, `volt_oid`, `volt_descr`, `volt_precision`, `volt_limit`, `volt_current`) values ('$id', '$volt_oid', '$descr',1000, " . ($config['defaults']['volt_limit'] ? $config['defaults']['volt_limit'] : '60') . ", '$volt')";
|
||||
$query = "INSERT INTO voltage (`device_id`, `volt_oid`, `volt_descr`, `volt_precision`, `volt_limit`, `volt_current`) values ('$id', '$volt_oid', '$descr',10000, " . ($config['defaults']['volt_limit'] ? $config['defaults']['volt_limit'] : '60') . ", '$volt')";
|
||||
mysql_query($query);
|
||||
echo("+");
|
||||
}
|
||||
@@ -46,7 +45,7 @@ if ($device['os'] == "linux")
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
## Supermicro Voltages
|
||||
if ($device['os'] == "linux")
|
||||
|
||||
Reference in New Issue
Block a user