mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
move fanspeed to sensors table - please run discovery immediately after svn up
git-svn-id: http://www.observium.org/svn/observer/trunk@1270 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -105,17 +105,17 @@ if ($device['os'] == "linux")
|
||||
|
||||
if($debug) { echo("\n Checking ... \n"); print_r($valid_fan); }
|
||||
|
||||
$sql = "SELECT * FROM fanspeed WHERE device_id = '".$device['device_id']."'";
|
||||
$sql = "SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '".$device['device_id']."'";
|
||||
if ($query = mysql_query($sql))
|
||||
{
|
||||
while ($test_fan = mysql_fetch_array($query))
|
||||
{
|
||||
$fan_index = $test_fan['fan_index'];
|
||||
$fan_type = $test_fan['fan_type'];
|
||||
$fan_index = $test_fan['sensor_index'];
|
||||
$fan_type = $test_fan['sensor_type'];
|
||||
if($debug) { echo("$fan_type -> $fan_index\n"); }
|
||||
if(!$valid_fan[$fan_type][$fan_index]) {
|
||||
echo("-");
|
||||
mysql_query("DELETE FROM `fanspeed` WHERE fan_id = '" . $test_fan['fan_id'] . "'");
|
||||
mysql_query("DELETE FROM `fanspeed` WHERE sensor_id = '" . $test_fan['sensor_id'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ function discover_temperature(&$valid, $device, $oid, $index, $type, $descr, $pr
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE sensor_class` = 'temperature' AND`sensor_id` = '".$entry['sensor_id']."'");
|
||||
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'temperature' AND`sensor_id` = '".$entry['sensor_id']."'");
|
||||
echo("U");
|
||||
}
|
||||
}
|
||||
@@ -179,23 +179,23 @@ function discover_fan(&$valid, $device, $oid, $index, $type, $descr, $precision
|
||||
$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')
|
||||
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_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')";
|
||||
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_current`) ";
|
||||
$query .= " VALUES ('fanspeed','".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$low_limit', '$current')";
|
||||
mysql_query($query);
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
$fan_entry = mysql_fetch_array(mysql_query("SELECT * 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'])
|
||||
$fan_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
|
||||
if($oid == $fan_entry['sensor_oid'] && $descr == $fan_entry['sensor_descr'] && $precision == $fan_entry['sensor_precision'])
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("UPDATE fanspeed SET `fan_descr` = '$descr', `fan_oid` = '$oid', `fan_precision` = '$precision' WHERE `device_id` = '".$device['device_id']."' AND fan_type = '$type' AND `fan_index` = '$index' ");
|
||||
mysql_query("UPDATE fanspeed SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'fanspeed' AND `device_id` = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index' ");
|
||||
echo("U");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?php
|
||||
|
||||
$query = "SELECT * FROM fanspeed WHERE device_id = '" . $device['device_id'] . "'";
|
||||
$query = "SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'";
|
||||
$fan_data = mysql_query($query);
|
||||
while($fanspeed = mysql_fetch_array($fan_data)) {
|
||||
|
||||
echo("Checking fan " . $fanspeed['fan_descr'] . "... ");
|
||||
echo("Checking fan " . $fanspeed['sensor_descr'] . "... ");
|
||||
|
||||
$fan_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $fanspeed['fan_oid'] . "|grep -v \"No Such Instance\"";
|
||||
$fan_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $fanspeed['sensor_oid'] . "|grep -v \"No Such Instance\"";
|
||||
$fan = trim(str_replace("\"", "", shell_exec($fan_cmd)));
|
||||
if ($fanspeed['fan_precision']) { $fan = $fan / $fanspeed['fan_precision']; }
|
||||
if ($fanspeed['sensor_precision']) { $fan = $fan / $fanspeed['sensor_precision']; }
|
||||
|
||||
$fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $fanspeed['fan_descr'] . ".rrd");
|
||||
$fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $fanspeed['sensor_descr'] . ".rrd");
|
||||
|
||||
if (!is_file($fanrrd)) {
|
||||
`rrdtool create $fanrrd \
|
||||
@@ -26,16 +26,16 @@ while($fanspeed = mysql_fetch_array($fan_data)) {
|
||||
|
||||
rrdtool_update($fanrrd,"N:$fan");
|
||||
|
||||
if($fanspeed['fan_current'] > $fanspeed['fan_limit'] && $fan <= $fanspeed['fan_limit']) {
|
||||
if($fanspeed['sensor_current'] > $fanspeed['sensor_limit'] && $fan <= $fanspeed['sensor_limit']) {
|
||||
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
||||
$msg = "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'] . " is " . $fan . "rpm (Limit " . $fanspeed['fan_limit'];
|
||||
$msg = "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['sensor_descr'] . " is " . $fan . "rpm (Limit " . $fanspeed['sensor_limit'];
|
||||
$msg .= "rpm) at " . date($config['timestamp_format']);
|
||||
mail($email, "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['fan_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $fanspeed['fan_descr'] . "\n");
|
||||
log_event('Fan speed ' . $fanspeed['fan_descr'] . " under threshold: " . $fanspeed['fan_current'] . " rpm (> " . $fanspeed['fan_limit'] . " rpm)", $device['device_id'], 'fanspeed', $fanspeed['fan_id']);
|
||||
mail($email, "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['sensor_descr'], $msg, $config['email_headers']);
|
||||
echo("Alerting for " . $device['hostname'] . " " . $fanspeed['sensor_descr'] . "\n");
|
||||
log_event('Fan speed ' . $fanspeed['sensor_descr'] . " under threshold: " . $fanspeed['sensor_current'] . " rpm (> " . $fanspeed['sensor_limit'] . " rpm)", $device['device_id'], 'fanspeed', $fanspeed['sensor_id']);
|
||||
}
|
||||
|
||||
mysql_query("UPDATE fanspeed SET fan_current = '$fan' WHERE fan_id = '" . $fanspeed['fan_id'] . "'");
|
||||
mysql_query("UPDATE sensors SET sensor_current = '$fan' WHERE sensor_class='fanspeed' AND sensor_id = '" . $fanspeed['sensor_id'] . "'");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user