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
@@ -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++;
}
+5 -5
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";
+1 -1
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);
+14 -15
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>");
?>
?>
+12 -12
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++;
+24 -24
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> ");