move temperatures to sensors table - please run discovery immediately after svn up

git-svn-id: http://www.observium.org/svn/observer/trunk@1269 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-06-25 22:12:56 +00:00
parent 1c7c3e178e
commit 635398d2c8
10 changed files with 86 additions and 88 deletions

View File

@@ -6,7 +6,7 @@ $device = device_by_id_cache($id);
$rrd_options .= " -l 0 -E ";
$iter = "1";
$sql = mysql_query("SELECT * FROM temperature where device_id = '$id' ORDER BY temp_index");
$sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '$id' ORDER BY sensor_index");
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
while($temperature = mysql_fetch_array($sql))
{
@@ -37,13 +37,13 @@ while($temperature = mysql_fetch_array($sql))
break;
}
$temperature['temp_descr_fixed'] = substr(str_pad($temperature['temp_descr'], 22),0,22);
$temprrd = $config['rrd_dir'] . "/".$device['hostname']."/".safename("temp-" . $temperature['temp_descr'] . ".rrd");
$rrd_options .= " DEF:temp" . $temperature[temp_id] . "=$temprrd:temp:AVERAGE ";
$rrd_options .= " LINE1:temp" . $temperature[temp_id] . "#" . $colour . ":'" . str_replace(':','\:',str_replace('\*','*',quotemeta($temperature['temp_descr_fixed']))) . "' ";
$rrd_options .= " GPRINT:temp" . $temperature[temp_id] . ":LAST:%3.0lfC ";
$rrd_options .= " GPRINT:temp" . $temperature[temp_id] . ":MIN:%3.0lfC ";
$rrd_options .= " GPRINT:temp" . $temperature[temp_id] . ":MAX:%3.0lfC\\\l ";
$temperature['sensor_descr_fixed'] = substr(str_pad($temperature['sensor_descr'], 22),0,22);
$temprrd = $config['rrd_dir'] . "/".$device['hostname']."/".safename("temp-" . $temperature['sensor_descr'] . ".rrd");
$rrd_options .= " DEF:temp" . $temperature['sensor_id'] . "=$temprrd:temp:AVERAGE ";
$rrd_options .= " LINE1:temp" . $temperature['sensor_id'] . "#" . $colour . ":'" . str_replace(':','\:',str_replace('\*','*',quotemeta($temperature['sensor_descr_fixed']))) . "' ";
$rrd_options .= " GPRINT:temp" . $temperature['sensor_id'] . ":LAST:%3.0lfC ";
$rrd_options .= " GPRINT:temp" . $temperature['sensor_id'] . ":MIN:%3.0lfC ";
$rrd_options .= " GPRINT:temp" . $temperature['sensor_id'] . ":MAX:%3.0lfC\\\l ";
$iter++;
}

View File

@@ -7,19 +7,19 @@ include("common.inc.php");
$rrd_options .= " COMMENT:' Last Max\\n'";
$temperature = mysql_fetch_array(mysql_query("SELECT * FROM temperature where temp_id = '".mres($_GET['id'])."'"));
$temperature = mysql_fetch_array(mysql_query("SELECT * FROM sensors where sensor_id = '".mres($_GET['id'])."'"));
$hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $temperature['device_id'] . "'"),0);
$temperature['temp_descr_fixed'] = substr(str_pad($temperature['temp_descr'], 28),0,28);
$temperature['sensor_descr_fixed'] = substr(str_pad($temperature['sensor_descr'], 28),0,28);
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("temp-" . $temperature['temp_descr'] . ".rrd");
$rrd_filename = $config['rrd_dir'] . "/".$hostname."/" . safename("temp-" . $temperature['sensor_descr'] . ".rrd");
$rrd_options .= " DEF:temp=$rrd_filename:temp:AVERAGE";
$rrd_options .= " DEF:temp_max=$rrd_filename:temp:MAX";
$rrd_options .= " DEF:temp_min=$rrd_filename:temp:MIN";
$rrd_options .= " CDEF:tempwarm=temp_max,".$temperature['temp_limit'].",GT,temp,UNKN,IF";
$rrd_options .= " CDEF:tempwarm=temp_max,".$temperature['sensor_limit'].",GT,temp,UNKN,IF";
$rrd_options .= " CDEF:tempcold=temp_min,20,LT,temp,UNKN,IF";
$rrd_options .= " AREA:temp_max#c5c5c5";
$rrd_options .= " AREA:temp_min#ffffffff";
@@ -29,7 +29,7 @@ include("common.inc.php");
# $rrd_options .= " AREA:temp#bbd392";
# $rrd_options .= " AREA:tempwarm#FFCCCC";
# $rrd_options .= " AREA:tempcold#CCCCFF";
$rrd_options .= " LINE1:temp#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($temperature['temp_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " LINE1:temp#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($temperature['sensor_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " LINE1:tempwarm#660000";
$rrd_options .= " GPRINT:temp:LAST:%3.0lfC";
$rrd_options .= " GPRINT:temp:MAX:%3.0lfC\\\\l";

View File

@@ -1,6 +1,6 @@
<?php
$temperatures = mysql_result(mysql_query("select count(*) from temperature WHERE device_id = '" . $device['device_id'] . "'"), 0);
$temperatures = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "'"), 0);
$humidity = mysql_result(mysql_query("select count(*) from sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "'"), 0);
$storage = mysql_result(mysql_query("select count(*) from storage WHERE device_id = '" . $device['device_id'] . "'"), 0);
$diskio = mysql_result(mysql_query("select count(*) from ucd_diskio WHERE device_id = '" . $device['device_id'] . "'"), 0);

View File

@@ -1,6 +1,6 @@
<?php
$sql = "SELECT * FROM `temperature` WHERE device_id = '" . $_GET[id] . "' ORDER BY temp_descr";
$sql = "SELECT * FROM `sensors` WHERE sensor_class='temperature' 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($temp = 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>" . $temp['temp_descr'] . "</td>
<td>" . print_temperature($temp['temp_current'], $temp['temp_limit']) . " &deg;C</td>
<td>" . $temp['temp_limit'] . " &deg;C</td>
<td>" . $temp['temp_notes'] . "</td>
<td width=350>" . $temp['sensor_descr'] . "</td>
<td>" . print_temperature($temp['sensor_current'], $temp['sensor_limit']) . " &deg;C</td>
<td>" . $temp['sensor_limit'] . " &deg;C</td>
<td>" . $temp['sensor_notes'] . "</td>
</tr>\n");
echo("<tr bgcolor=$row_colour><td colspan='4'>");
@@ -23,17 +23,17 @@ while($temp = mysql_fetch_array($query)) {
// start temperature graphs
$daily_temp = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
$daily_temp = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150";
$weekly_temp = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
$weekly_temp = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150";
$monthly_temp = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
$monthly_temp = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150";
$yearly_temp = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $temp['temp_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150";
$yearly_temp = "graph.php?id=" . $temp['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $temp['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_temp' border=0></a> ");
@@ -55,5 +55,4 @@ while($temp = mysql_fetch_array($query)) {
echo("</table>");
?>
?>

View File

@@ -1,12 +1,12 @@
<?php
unset($temp_seperator);
if($total = mysql_result(mysql_query("SELECT count(temp_id) from temperature WHERE device_id = '" . $device['device_id'] . "'"),0)) {
if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE sensor_class='temperature' 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/temperatures.png'> Temperatures</p>");
$i = '1';
$temps = mysql_query("SELECT * FROM temperature WHERE device_id = '" . $device['device_id'] . "' ORDER BY temp_index");
$temps = mysql_query("SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "' ORDER BY sensor_index");
echo('<table width="100%" valign="top">');
echo('<tr><td width="50%">');
echo('<table width="100%" cellspacing="0" cellpadding="2">');
@@ -15,23 +15,23 @@ if($total = mysql_result(mysql_query("SELECT count(temp_id) from temperature WHE
$graph_colour = str_replace("#", "", $row_colour);
$temp_perc = $temp['temp_current'] / $temp['temp_limit'] * 100;
$temp_perc = $temp['sensor_current'] / $temp['sensor_limit'] * 100;
$temp_colour = percent_colour($temp_perc);
$temp_day = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$day&to=$now&width=300&height=100";
$temp_week = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$week&to=$now&width=300&height=100";
$temp_month = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$month&to=$now&width=300&height=100";
$temp_year = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$year&to=$now&width=300&height=100";
$temp_minigraph = "<img src='graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
$temp_day = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$day&to=$now&width=300&height=100";
$temp_week = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$week&to=$now&width=300&height=100";
$temp_month = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$month&to=$now&width=300&height=100";
$temp_year = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$year&to=$now&width=300&height=100";
$temp_minigraph = "<img src='graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
$temp_link = "<a href='/device/".$device['device_id']."/health/temperatures/' onmouseover=\"return ";
$temp_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$temp['temp_descr'];
$temp_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$temp['sensor_descr'];
$temp_link .= "</div><div style=\'width: 750px\'><img src=\'$temp_day\'><img src=\'$temp_week\'><img src=\'$temp_month\'><img src=\'$temp_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
$temp_link_c = $temp_link . "<span style='color: $temp_colour'>" . round($temp['temp_current'],0) . "&deg;C</span></a>";
$temp_link_c = $temp_link . "<span style='color: $temp_colour'>" . round($temp['sensor_current'],0) . "&deg;C</span></a>";
$temp_link_b = $temp_link . $temp_minigraph . "</a>";
$temp_link_a = $temp_link . $temp['temp_descr'] . "</a>";
$temp_link_a = $temp_link . $temp['sensor_descr'] . "</a>";
$temp['temp_descr'] = truncate($temp['temp_descr'], 25, '');
$temp['sensor_descr'] = truncate($temp['sensor_descr'], 25, '');
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$temp_link_a</strong></td><td width=80 align=right class=tablehead>$temp_link_b<td width=35 align=right class=tablehead>$temp_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 `temperature` AS T, `devices` AS D WHERE T.device_id = D.device_id ORDER BY D.hostname, T.temp_index, T.temp_descr";
$sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.device_id = D.device_id ORDER BY D.hostname, S.sensor_index, S.sensor_descr";
} else {
$sql = "SELECT * FROM `temperature` AS T, `devices` AS D, devices_perms as P WHERE T.device_id = D.device_id AND D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' ORDER BY D.hostname, T.temp_index, T.temp_descr";
$sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE 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_index, S.sensor_descr";
}
$query = mysql_query($sql);
@@ -26,24 +26,24 @@ while($temp = mysql_fetch_array($query))
{
if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
$weekly_temp = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from=$week&amp;to=$now&amp;width=500&amp;height=150";
$weekly_temp = "graph.php?id=" . $temp['sensor_id'] . "&amp;type=temperature&amp;from=$week&amp;to=$now&amp;width=500&amp;height=150";
$temp_popup = "<a onmouseover=\"return overlib('<img src=\'$weekly_temp\'>', LEFT);\" onmouseout=\"return nd();\">
" . $temp['temp_descr'] . "</a>";
" . $temp['sensor_descr'] . "</a>";
$temp['temp_current'] = round($temp['temp_current'],1);
$temp['sensor_current'] = round($temp['sensor_current'],1);
$temp_perc = $temp['temp_current'] / $temp['temp_limit'] * 100;
$temp_perc = $temp['sensor_current'] / $temp['sensor_limit'] * 100;
$temp_colour = percent_colour($temp_perc);
if($temp['temp_current'] >= $temp['temp_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
if($temp['sensor_current'] >= $temp['sensor_limit']) { $alert = '<img src="images/16/flag_red.png" alt="alert" />'; } else { $alert = ""; }
$temp_day = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from=$day&amp;to=$now&amp;width=300&amp;height=100";
$temp_week = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from=$week&amp;to=$now&amp;width=300&amp;height=100";
$temp_month = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from=$month&amp;to=$now&amp;width=300&amp;height=100";
$temp_year = "graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from=$year&amp;to=$now&amp;width=300&amp;height=100";
$temp_day = "graph.php?id=" . $temp['sensor_id'] . "&amp;type=temperature&amp;from=$day&amp;to=$now&amp;width=300&amp;height=100";
$temp_week = "graph.php?id=" . $temp['sensor_id'] . "&amp;type=temperature&amp;from=$week&amp;to=$now&amp;width=300&amp;height=100";
$temp_month = "graph.php?id=" . $temp['sensor_id'] . "&amp;type=temperature&amp;from=$month&amp;to=$now&amp;width=300&amp;height=100";
$temp_year = "graph.php?id=" . $temp['sensor_id'] . "&amp;type=temperature&amp;from=$year&amp;to=$now&amp;width=300&amp;height=100";
$temp_minigraph = "<img src='graph.php?id=" . $temp['temp_id'] . "&amp;type=temperature&amp;from=$day&amp;to=$now&amp;width=100&amp;height=20'";
$temp_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$temp['hostname']." - ".$temp['temp_descr'];
$temp_minigraph = "<img src='graph.php?id=" . $temp['sensor_id'] . "&amp;type=temperature&amp;from=$day&amp;to=$now&amp;width=100&amp;height=20'";
$temp_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$temp['hostname']." - ".$temp['sensor_descr'];
$temp_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$temp_day\'><img src=\'$temp_week\'><img src=\'$temp_month\'><img src=\'$temp_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
echo("<tr bgcolor=$row_colour>
@@ -51,26 +51,26 @@ while($temp = mysql_fetch_array($query))
<td>$temp_popup</td>
<td>$temp_minigraph</td>
<td width=100>$alert</td>
<td style='color: $temp_colour; text-align: center; font-weight: bold;'>" . $temp['temp_current'] . " &deg;C</td>
<td style='text-align: center'>" . $temp['temp_limit'] . " &deg;C</td>
<td>" . (isset($temp['temp_notes']) ? $temp['temp_notes'] : '') . "</td>
<td style='color: $temp_colour; text-align: center; font-weight: bold;'>" . $temp['sensor_current'] . " &deg;C</td>
<td style='text-align: center'>" . $temp['sensor_limit'] . " &deg;C</td>
<td>" . (isset($temp['sensor_notes']) ? $temp['sensor_notes'] : '') . "</td>
</tr>\n");
if($_GET['optb'] == "graphs") { ## If graphs
echo("<tr bgcolor='$row_colour'><td colspan=7>");
$daily_graph = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$day&to=$now&width=400&height=150";
$daily_graph = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$day&to=$now&width=211&height=100";
$daily_url = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$day&to=$now&width=400&height=150";
$weekly_graph = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$week&to=$now&width=400&height=150";
$weekly_graph = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$week&to=$now&width=211&height=100";
$weekly_url = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$week&to=$now&width=400&height=150";
$monthly_graph = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$month&to=$now&width=400&height=150";
$monthly_graph = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$month&to=$now&width=211&height=100";
$monthly_url = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$month&to=$now&width=400&height=150";
$yearly_graph = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $temp['temp_id'] . "&type=temperature&from=$year&to=$now&width=400&height=150";
$yearly_graph = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&from=$year&to=$now&width=211&height=100";
$yearly_url = "graph.php?id=" . $temp['sensor_id'] . "&type=temperature&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

@@ -143,25 +143,24 @@ function discover_temperature(&$valid, $device, $oid, $index, $type, $descr, $pr
global $config, $debug;
if($debug) { echo("$oid, $index, $type, $descr, $precision, $current\n"); }
if (mysql_result(mysql_query("SELECT COUNT(temp_id) FROM `temperature` WHERE temp_type = '$type' AND temp_index = '$index' AND device_id = '".$device['device_id']."'"),0) == '0')
if (mysql_result(mysql_query("SELECT COUNT(sensor_id) FROM `sensors` WHERE sensor_class='temperature' AND sensor_type = '$type' AND sensor_index = '$index' AND device_id = '".$device['device_id']."'"),0) == '0')
{
$query = "INSERT INTO temperature (`device_id`, `temp_type`,`temp_index`,`temp_oid`, `temp_descr`, `temp_limit`, `temp_current`, `temp_precision`)";
$query .= " values ('".$device['device_id']."', '$type','$index','$oid', '$descr','" . ($high_limit ? $high_limit : $config['defaults']['temp_limit']) . "', '$current', '$precision')";
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_type`,`sensor_index`,`sensor_oid`, `sensor_descr`, `sensor_limit`, `sensor_current`, `sensor_precision`)";
$query .= " values ('temperature','".$device['device_id']."', '$type','$index','$oid', '$descr','" . ($high_limit ? $high_limit : $config['defaults']['sensor_limit']) . "', '$current', '$precision')";
mysql_query($query);
echo("+");
}
else
{
$entry = mysql_fetch_array(mysql_query("SELECT * FROM `temperature` WHERE device_id = '".$device['device_id']."' AND `temp_type` = '$type' AND `temp_index` = '$index'"));
$entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='temperature' AND device_id = '".$device['device_id']."' AND `sensor_type` = '$type' AND `sensor_index` = '$index'"));
echo(mysql_error());
if($oid == $entry['temp_oid'] && $descr == $entry['temp_descr'] && $precision == $entry['temp_precision'])
if($oid == $entry['sensor_oid'] && $descr == $entry['sensor_descr'] && $precision == $entry['sensor_precision'])
{
echo(".");
}
else
{
mysql_query("UPDATE temperature SET `temp_descr` = '$descr', `temp_oid` = '$oid', `temp_precision` = '$precision' WHERE `temp_id` = '".$entry['temp_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");
}
}

View File

@@ -310,18 +310,18 @@ if (strstr($device['hardware'], "dell"))
if($debug) { print_r($valid_temp); }
$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
$sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='temperature' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))
{
while ($test_temperature = mysql_fetch_array($query))
{
$temperature_index = $test_temperature['temp_index'];
$temperature_type = $test_temperature['temp_type'];
$temperature_index = $test_temperature['sensor_index'];
$temperature_type = $test_temperature['sensor_type'];
if($debug) { echo($temperature_index . " -> " . $temperature_type . "\n"); }
if(!$valid_temp[$temperature_type][$temperature_index])
{
echo("-");
mysql_query("DELETE FROM `temperature` WHERE temp_id = '" . $test_temperature['temp_id'] . "'");
mysql_query("DELETE FROM `sensors` WHERE sensor_class='temperature' AND sensor_id = '" . $test_temperature['sensor_id'] . "'");
}
unset($temperature_oid); unset($temperature_type);
}

View File

@@ -290,7 +290,6 @@ function delete_device($id)
mysql_query("DELETE FROM `devices_attribs` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `devices_perms` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `bgpPeers` WHERE `device_id` = '$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 `device_id` = '$id'");
@@ -305,6 +304,7 @@ function delete_device($id)
mysql_query("DELETE FROM `toner` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `current` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `sensors` WHERE `device_id` = '$id'");
shell_exec("rm -rf ".$config['rrd_dir']."/$host");
return $ret . "Removed device $host\n";
}

View File

@@ -1,24 +1,24 @@
<?php
$query = "SELECT * FROM temperature WHERE device_id = '" . $device['device_id'] . "'";
$query = "SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "'";
$temp_data = mysql_query($query);
while($temperature = mysql_fetch_array($temp_data)) {
echo("Checking temp " . $temperature['temp_descr'] . "... ");
echo("Checking temp " . $temperature['sensor_descr'] . "... ");
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
{
if ($debug) echo "Attempt $i ";
$temp_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['temp_oid'] . "|grep -v \"No Such Instance\"";
$temp_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['sensor_oid'] . "|grep -v \"No Such Instance\"";
$temp = trim(str_replace("\"", "", shell_exec($temp_cmd)));
if ($temp != 9999) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
sleep(1); # Give the TME some time to reset
}
if ($temperature['temp_precision']) { $temp = $temp / $temperature['temp_precision']; }
if ($temperature['sensor_precision']) { $temp = $temp / $temperature['sensor_precision']; }
$temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['temp_descr'] . ".rrd");
$temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['sensor_descr'] . ".rrd");
if (!is_file($temprrd)) {
`rrdtool create $temprrd \
@@ -34,16 +34,16 @@ while($temperature = mysql_fetch_array($temp_data)) {
rrdtool_update($temprrd,"N:$temp");
if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) {
if($temperature['sensor_current'] < $temperature['sensor_limit'] && $temp >= $temperature['sensor_limit']) {
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
$msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'] . " is " . $temp . " (Limit " . $temperature['temp_limit'];
$msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['sensor_descr'] . " is " . $temp . " (Limit " . $temperature['sensor_limit'];
$msg .= ") at " . date($config['timestamp_format']);
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "\n");
log_event('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['temp_limit'] . " <20>C)", $device['device_id'], 'temperature', $temperature['temp_id']);
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['sensor_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $temperature['sensor_descr'] . "\n");
log_event('Temperature ' . $temperature['sensor_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['sensor_limit'] . " <20>C)", $device['device_id'], 'temperature', $temperature['sensor_id']);
}
mysql_query("UPDATE temperature SET temp_current = '$temp' WHERE temp_id = '" . $temperature['temp_id'] . "'");
mysql_query("UPDATE sensors SET sensor_current = '$temp' WHERE sensor_class='temperature' AND sensor_id = '" . $temperature['sensor_id'] . "'");
}
?>