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:
Tom Laermans
2010-06-25 23:16:04 +00:00
parent 635398d2c8
commit 600b0ba2bf
9 changed files with 76 additions and 78 deletions

View File

@@ -7,7 +7,7 @@ $device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E ";
$iter = "1";
$sql = mysql_query("SELECT * FROM fanspeed where device_id = '$id'");
$sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '$id'");
$rrd_options .= " COMMENT:'RPM Cur Min Max\\n'";
while($fanspeed = mysql_fetch_array($sql))
{
@@ -38,9 +38,9 @@ while($fanspeed = mysql_fetch_array($sql))
break;
}
$descr = substr(str_pad($fanspeed['fan_descr'], 17),0,17);
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("fan-" . $fanspeed['fan_descr'] . ".rrd");
$fan_id = $fanspeed['fan_id'];
$descr = substr(str_pad($fanspeed['sensor_descr'], 17),0,17);
$rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("fan-" . $fanspeed['sensor_descr'] . ".rrd");
$fan_id = $fanspeed['sensor_id'];
$rrd_options .= " DEF:fan$fan_id=$rrd_filename:fan:AVERAGE";
$rrd_options .= " LINE1:fan$fan_id#".$colour.":'" . $descr . "'";
@@ -51,5 +51,4 @@ while($fanspeed = mysql_fetch_array($sql))
$iter++;
}
?>

View File

@@ -6,16 +6,16 @@ include("common.inc.php");
$rrd_options .= " COMMENT:' Last Max\\n'";
$fanspeed = mysql_fetch_array(mysql_query("SELECT * FROM fanspeed where fan_id = '".mres($_GET['id'])."'"));
$fanspeed = mysql_fetch_array(mysql_query("SELECT * FROM sensors WHERE sensor_class='fanspeed' AND fan_id = '".mres($_GET['id'])."'"));
$hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $fanspeed['device_id'] . "'"),0);
$fanspeed['fan_descr_fixed'] = substr(str_pad($fanspeed['fan_descr'], 20),0,20);
$fanspeed['sensor_descr_fixed'] = substr(str_pad($fanspeed['sensor_descr'], 20),0,20);
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("fan-" . $fanspeed['fan_descr'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("fan-" . $fanspeed['sensor_descr'] . ".rrd");
$rrd_options .= " DEF:fan=$rrd_filename:fan:AVERAGE";
$rrd_options .= " LINE1.5:fan#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($fanspeed['fan_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " LINE1.5:fan#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($fanspeed['sensor_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " GPRINT:fan:LAST:%3.0lfrpm";
$rrd_options .= " GPRINT:fan:MAX:%3.0lfrpm\\\\l";

View File

@@ -6,7 +6,7 @@ $storage = mysql_result(mysql_query("select count(*) from storage WHERE device_i
$diskio = mysql_result(mysql_query("select count(*) from ucd_diskio WHERE device_id = '" . $device['device_id'] . "'"), 0);
$memory = mysql_result(mysql_query("select count(*) from mempools WHERE device_id = '" . $device['device_id'] . "'"), 0);
$processor = mysql_result(mysql_query("select count(*) from processors WHERE device_id = '" . $device['device_id'] . "'"), 0);
$fans = mysql_result(mysql_query("select count(*) from fanspeed WHERE device_id = '" . $device['device_id'] . "'"), 0);
$fans = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'"), 0);
$volts = mysql_result(mysql_query("select count(*) from voltage WHERE device_id = '" . $device['device_id'] . "'"), 0);
$freqs = mysql_result(mysql_query("select count(*) from frequency WHERE device_id = '" . $device['device_id'] . "'"), 0);
$current = mysql_result(mysql_query("select count(*) from current WHERE device_id = '" . $device['device_id'] . "'"), 0);

View File

@@ -1,6 +1,6 @@
<?php
$sql = "SELECT * FROM `fanspeed` WHERE device_id = '" . $_GET[id] . "' ORDER BY fan_descr";
$sql = "SELECT * FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = '" . $_GET[id] . "' ORDER BY sensor_descr";
$query = mysql_query($sql);
echo("<table cellspacing=0 cellpadding=5 width=100%>");
@@ -12,10 +12,10 @@ while($fan = mysql_fetch_array($query)) {
if(!is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
echo("<tr class=list-large style=\"background-color: $row_colour; padding: 5px;\">
<td width=350>" . $fan['fan_descr'] . "</td>
<td>" . $fan['fan_current'] . " rpm</td>
<td>" . $fan['fan_limit'] . " rpm</td>
<td>" . $fan['fan_notes'] . "</td>
<td width=350>" . $fan['sensor_descr'] . "</td>
<td>" . $fan['sensor_current'] . " rpm</td>
<td>" . $fan['sensor_limit'] . " rpm</td>
<td>" . $fan['sensor_notes'] . "</td>
</tr>\n");
echo("<tr bgcolor=$row_colour><td colspan='4'>");
@@ -23,17 +23,17 @@ while($fan = mysql_fetch_array($query)) {
// start fanspeed graphs
$daily_fan = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
$daily_fan = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
$weekly_fan = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
$weekly_fan = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
$monthly_fan = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
$monthly_fan = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
$yearly_fan = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $fan['fan_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150";
$yearly_fan = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $fan['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150";
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$daily_fan' border=0></a> ");

View File

@@ -1,8 +1,7 @@
<?php
unset($fan_seperator);
if(mysql_result(mysql_query("SELECT count(fan_id) from fanspeed WHERE device_id = '" . $device['device_id'] . "'"),0)) {
$total = mysql_result(mysql_query("SELECT count(fan_id) from fanspeed WHERE device_id = '" . $device['device_id'] . "'"),0);
if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'"),0)) {
$rows = round($total / 2,0);
echo("<div style='background-color: #eeeeee; margin: 5px; padding: 5px;'>");
echo("<p style='padding: 0px 5px 5px;' class=sectionhead><img align='absmiddle' src='".$config['base_url']."/images/icons/fanspeeds.png'> Fanspeeds</p>");
@@ -16,21 +15,21 @@ if(mysql_result(mysql_query("SELECT count(fan_id) from fanspeed WHERE device_id
$graph_colour = str_replace("#", "", $row_colour);
$fan_day = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$day&to=$now&width=300&height=100";
$fan_week = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$week&to=$now&width=300&height=100";
$fan_month = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$month&to=$now&width=300&height=100";
$fan_year = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$year&to=$now&width=300&height=100";
$fan_minigraph = "<img src='graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
$fan_day = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$day&to=$now&width=300&height=100";
$fan_week = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$week&to=$now&width=300&height=100";
$fan_month = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$month&to=$now&width=300&height=100";
$fan_year = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$year&to=$now&width=300&height=100";
$fan_minigraph = "<img src='graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
$fan_link = "<a href='/device/".$device['device_id']."/health/fanspeeds/' onmouseover=\"return ";
$fan_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$fan['fan_descr'];
$fan_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$fan['sensor_descr'];
$fan_link .= "</div><div style=\'width: 750px\'><img src=\'$fan_day\'><img src=\'$fan_week\'><img src=\'$fan_month\'><img src=\'$fan_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
$fan_link_b = $fan_link . $fan_minigraph . "</a>";
$fan_link_c = $fan_link . "<span style='" . ($fan['fan_current'] <= $fan['fan_limit'] ? "color: red" : '') . "'>" . $fan['fan_current'] . "rpm</span></a>";
$fan_link_a = $fan_link . $fan['fan_descr'] . "</a>";
$fan_link_c = $fan_link . "<span style='" . ($fan['sensor_current'] <= $fan['sensor_limit'] ? "color: red" : '') . "'>" . $fan['sensor_current'] . "rpm</span></a>";
$fan_link_a = $fan_link . $fan['sensor_descr'] . "</a>";
$fan['fan_descr'] = truncate($fan['fan_descr'], 25, '');
$fan['sensor_descr'] = truncate($fan['sensor_descr'], 25, '');
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$fan_link_a</strong></td><td width=80 align=right class=tablehead>$fan_link_b<td width=80 align=right class=tablehead>$fan_link_c</td></tr>");
if($i == $rows) { echo("</table></td><td valign=top><table width=100% cellspacing=0 cellpadding=2>"); }
$i++;

View File

@@ -1,9 +1,9 @@
<?php
if($_SESSION['userlevel'] >= '5') {
$sql = "SELECT * FROM `fanspeed` AS F, `devices` AS D WHERE F.device_id = D.device_id ORDER BY D.hostname, F.fan_descr";
$sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='fanspeed' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_descr";
} else {
$sql = "SELECT * FROM `fanspeed` AS F, `devices` AS D, devices_perms as P WHERE F.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, F.fan_descr";
$sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='fanspeed' AND S.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, S.sensor_descr";
}
$query = mysql_query($sql);
@@ -26,19 +26,19 @@ while($fan = mysql_fetch_array($query))
{
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$weekly_fan = "graph.php?id=" . $fan['fan_id'] . "&amp;type=fanspeed&amp;from=$week&amp;to=$now&amp;width=500&amp;height=150";
$weekly_fan = "graph.php?id=" . $fan['sensor_id'] . "&amp;type=fanspeed&amp;from=$week&amp;to=$now&amp;width=500&amp;height=150";
$fan_popup = "<a onmouseover=\"return overlib('<img src=\'$weekly_fan\'>', LEFT);\" onmouseout=\"return nd();\">
" . $fan['fan_descr'] . "</a>";
" . $fan['sensor_descr'] . "</a>";
if($fan['fan_current'] <= $fan['fan_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
if($fan['sensor_current'] <= $fan['sensor_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
$fan_day = "graph.php?id=" . $fan['fan_id'] . "&amp;type=fanspeed&amp;from=$day&amp;to=$now&amp;width=300&amp;height=100";
$fan_week = "graph.php?id=" . $fan['fan_id'] . "&amp;type=fanspeed&amp;from=$week&amp;to=$now&amp;width=300&amp;height=100";
$fan_month = "graph.php?id=" . $fan['fan_id'] . "&amp;type=fanspeed&amp;from=$month&amp;to=$now&amp;width=300&amp;height=100";
$fan_year = "graph.php?id=" . $fan['fan_id'] . "&amp;type=fanspeed&amp;from=$year&amp;to=$now&amp;width=300&amp;height=100";
$fan_day = "graph.php?id=" . $fan['sensor_id'] . "&amp;type=fanspeed&amp;from=$day&amp;to=$now&amp;width=300&amp;height=100";
$fan_week = "graph.php?id=" . $fan['sensor_id'] . "&amp;type=fanspeed&amp;from=$week&amp;to=$now&amp;width=300&amp;height=100";
$fan_month = "graph.php?id=" . $fan['sensor_id'] . "&amp;type=fanspeed&amp;from=$month&amp;to=$now&amp;width=300&amp;height=100";
$fan_year = "graph.php?id=" . $fan['sensor_id'] . "&amp;type=fanspeed&amp;from=$year&amp;to=$now&amp;width=300&amp;height=100";
$fan_minigraph = "<img src='graph.php?id=" . $fan['fan_id'] . "&amp;type=fanspeed&amp;from=$day&amp;to=$now&amp;width=100&amp;height=20'";
$fan_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$fan['hostname']." - ".$fan['fan_descr'];
$fan_minigraph = "<img src='graph.php?id=" . $fan['sensor_id'] . "&amp;type=fanspeed&amp;from=$day&amp;to=$now&amp;width=100&amp;height=20'";
$fan_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$fan['hostname']." - ".$fan['sensor_descr'];
$fan_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$fan_day\'><img src=\'$fan_week\'><img src=\'$fan_month\'><img src=\'$fan_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
echo("<tr bgcolor=$row_colour>
@@ -46,26 +46,26 @@ while($fan = mysql_fetch_array($query))
<td>$fan_popup</td>
<td>$fan_minigraph</td>
<td width=100>$alert</td>
<td style='text-align: center; font-weight: bold;'>" . $fan['fan_current'] . " rpm</td>
<td style='text-align: center'>" . $fan['fan_limit'] . " rpm</td>
<td>" . (isset($fan['fan_notes']) ? $fan['fan_notes'] : '') . "</td>
<td style='text-align: center; font-weight: bold;'>" . $fan['sensor_current'] . " rpm</td>
<td style='text-align: center'>" . $fan['sensor_limit'] . " rpm</td>
<td>" . (isset($fan['sensor_notes']) ? $fan['sensor_notes'] : '') . "</td>
</tr>\n");
if($_GET['optb'] == "graphs") { ## If graphs
echo("<tr bgcolor='$row_colour'><td colspan=6>");
$daily_graph = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$day&to=$now&width=400&height=150";
$daily_graph = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$day&to=$now&width=400&height=150";
$weekly_graph = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$week&to=$now&width=400&height=150";
$weekly_graph = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$week&to=$now&width=400&height=150";
$monthly_graph = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$month&to=$now&width=400&height=150";
$monthly_graph = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$month&to=$now&width=400&height=150";
$yearly_graph = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $fan['fan_id'] . "&type=fanspeed&from=$year&to=$now&width=400&height=150";
$yearly_graph = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$year&to=$now&width=400&height=150";
echo("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
<img src='$daily_graph' border=0></a> ");

View File

@@ -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'] . "'");
}
}
}

View File

@@ -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");
}
}

View File

@@ -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 (&gt; " . $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 (&gt; " . $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'] . "'");
}
?>