autoset thresholds for sensors which don't have them

git-svn-id: http://www.observium.org/svn/observer/trunk@1666 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Adam Amstrong
2010-08-11 12:46:07 +00:00
parent 7c97cf02c9
commit 3b5ed3524e
10 changed files with 98 additions and 44 deletions

View File

@@ -11,7 +11,7 @@ include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/temp-" . safename($sensor['sensor_type']."-".$sensor['sensor_index']) . ".rrd";
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 22),0,22);
$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 21),0,21);
$sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed']));
$rrd_options .= " DEF:temp=$rrd_filename:temp:AVERAGE";
@@ -27,10 +27,10 @@ include("includes/graphs/common.inc.php");
# $rrd_options .= " AREA:tempcold#CCCCFF";
# $rrd_options .= " LINE1:temp#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :(
$rrd_options .= " LINE1:temp#cc0000:'" . $sensor['sensor_descr_fixed']."'";
$rrd_options .= " LINE1:tempwarm#660000";
$rrd_options .= " LINE1.5:temp#cc0000:'" . $sensor['sensor_descr_fixed']."'";
# $rrd_options .= " LINE1.5:tempwarm#660000";
$rrd_options .= " GPRINT:temp:LAST:%4.1lfC";
$rrd_options .= " GPRINT:temp:MIN:%4.1lfC";
$rrd_options .= " GPRINT:temp:MAX:%4.1lfC\\\\l";
$rrd_options .= " GPRINT:temp_min:MIN:%4.1lfC";
$rrd_options .= " GPRINT:temp_max:MAX:%4.1lfC\\\\l";
?>

View File

@@ -21,7 +21,7 @@ $rrd_options .= " AREA:volt_min#ffffffff";
#$rrd_options .= " AREA:volt#FFFF99";
$rrd_options .= " LINE1.5:volt#cc0000:'" . $sensor['sensor_descr_fixed']."'";
$rrd_options .= " GPRINT:volt:LAST:%3.2lfV";
$rrd_options .= " GPRINT:volt:MAX:%3.2lfV\\\\l";
$rrd_options .= " GPRINT:volt:LAST:%6.2lfV";
$rrd_options .= " GPRINT:volt:MAX:%6.2lfV\\\\l";
?>

View File

@@ -12,13 +12,14 @@ 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=450>" . $temp['sensor_descr'] . "</td>
<td >" . $temp['sensor_type'] . "</td>
<td width=50>" . print_temperature($temp['sensor_current'], $temp['sensor_limit']) . " &deg;C</td>
<td width=50>" . $temp['sensor_limit'] . " &deg;C</td>
<td width=400>" . $temp['sensor_descr'] . "</td>
<td width=100>" . $temp['sensor_type'] . "</td>
<td width=50>" . print_temperature($temp['sensor_current'], $temp['sensor_limit']) . "&deg;C</td>
<td width=50>" . $temp['sensor_limit'] . "&deg;C</td>
<td width=50>" . $temp['sensor_limit_low'] . "&deg;C</td>
<td width=350>" . $temp['sensor_notes'] . "</td>
</tr>\n");
echo("<tr bgcolor=$row_colour><td colspan='5'>");
echo("<tr bgcolor=$row_colour><td colspan='6'>");
$graph_type = "sensor_temperature";

View File

@@ -9,8 +9,6 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$i = '1';
$currents = mysql_query("SELECT * FROM sensors WHERE sensor_class='current' AND device_id = '" . $device['device_id'] . "'");
echo("<table width=100% valign=top>");
echo("<tr><td width=50%>");
echo("<table width=100% cellspacing=0 cellpadding=2>");
while($current = mysql_fetch_array($currents)) {
if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
@@ -32,12 +30,9 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$current['sensor_descr'] = truncate($current['sensor_descr'], 25, '');
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$current_link_a</strong></td><td width=80 align=right class=tablehead>$current_link_b<td width=80 align=right class=tablehead>$current_link_c</td></tr>");
if($i == $rows) { echo("</table></td><td valign=top><table width=100% cellspacing=0 cellpadding=2>"); }
$i++;
}
echo("</table>");
echo("</td></tr>");
echo("</table>");
echo("</div>");
}

View File

@@ -9,8 +9,6 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$i = '1';
$fans = mysql_query("SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'");
echo("<table width=100% valign=top>");
echo("<tr><td width=50%>");
echo("<table width=100% cellspacing=0 cellpadding=2>");
while($fan = mysql_fetch_array($fans)) {
if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
@@ -32,12 +30,9 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$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++;
}
echo("</table>");
echo("</td></tr>");
echo("</table>");
echo("</div>");
}

View File

@@ -9,8 +9,6 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$i = '1';
$temps = mysql_query("SELECT * FROM sensors WHERE sensor_class='freq' 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">');
while($temp = mysql_fetch_array($temps)) {
if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
@@ -34,12 +32,9 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$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=80 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++;
}
echo("</table>");
echo("</td></tr>");
echo("</table>");
echo("</div>");
}

View File

@@ -9,8 +9,6 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$i = '1';
$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">');
while($temp = mysql_fetch_array($temps)) {
if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
@@ -23,23 +21,22 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$temp_month = "graph.php?id=" . $temp['sensor_id'] . "&type=".$graph_type."&from=$month&to=$now&width=300&height=100";
$temp_year = "graph.php?id=" . $temp['sensor_id'] . "&type=".$graph_type."&from=$year&to=$now&width=300&height=100";
$temp_minigraph = "<img src='graph.php?id=" . $temp['sensor_id'] . "&type=".$graph_type."&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
$temp_minigraph_b = "<img src='graph.php?id=" . $temp['sensor_id'] . "&type=".$graph_type."&from=$week&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['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['sensor_current'],0) . "&deg;C</span></a>";
$temp_link_b = $temp_link . $temp_minigraph . "</a>";
$temp_link_b = $temp_link . $temp_minigraph . " " . $temp_minigraph_b . "</a>";
$temp_link_a = $temp_link . $temp['sensor_descr'] . "</a>";
$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=80 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>"); }
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$temp_link_a</strong></td><td width=170 align=right class=tablehead>$temp_link_b<td width=80 align=right class=tablehead>$temp_link_c</td></tr>");
$i++;
}
echo("</table>");
echo("</td></tr>");
echo("</table>");
echo("</div>");
}

View File

@@ -9,8 +9,6 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$i = '1';
$volts = mysql_query("SELECT * FROM sensors WHERE sensor_class='voltage' AND device_id = '" . $device['device_id'] . "'");
echo("<table width=100% valign=top>");
echo("<tr><td width=50%>");
echo("<table width=100% cellspacing=0 cellpadding=2>");
while($volt = mysql_fetch_array($volts)) {
if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; }
@@ -32,12 +30,9 @@ if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE
$volt['sensor_descr'] = truncate($volt['sensor_descr'], 25, '');
echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$volt_link_a</strong></td><td width=80 align=right class=tablehead>$volt_link_b<td width=80 align=right class=tablehead>$volt_link_c</td></tr>");
if($i == $rows) { echo("</table></td><td valign=top><table width=100% cellspacing=0 cellpadding=2>"); }
$i++;
}
echo("</table>");
echo("</td></tr>");
echo("</table>");
echo("</div>");
}

View File

@@ -1,14 +1,15 @@
<?php
function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL)
function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL)
{
global $config, $debug;
if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); }
if(!$low_limit)
{
$low_limit = $config['limit']['current'];
}
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0')
{
if(!$high_limit) { $high_limit = sensor_limit($class, $current); }
if(!$low_limit) { $low_limit = sensor_low_limit($class, $current); }
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_divisor`, `sensor_multiplier`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) ";
$query .= " VALUES ('" . mres($class) . "', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$divisor', '$multiplier', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')";
mysql_query($query);
@@ -20,6 +21,23 @@ function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $d
else
{
$sensor_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
if(!$sensor_entry['sensor_limit'])
{
$high_limit = sensor_limit($class, $current);
mysql_query("UPDATE sensors SET `sensor_limit` = '".$high_limit."' WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'");
echo("H");
log_event("Sensor High Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$high_limit.")", $device['device_id'], 'sensor', $sensor_id);
}
if(!$sensor_entry['sensor_low_limit'])
{
$low_limit = sensor_low_limit($class, $current);
mysql_query("UPDATE sensors SET `sensor_limit_low` = '".$low_limit."' WHERE `sensor_id` = '".$sensor_entry['sensor_id']."'");
echo("L");
log_event("Sensor Low Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$low_limit.")", $device['device_id'], 'sensor', $sensor_id);
}
if($oid == $sensor_entry['sensor_oid'] && $descr == $sensor_entry['sensor_descr'] && $multiplier == $sensor_entry['sensor_multiplier'] && $divisor == $sensor_entry['sensor_divisor'])
{
echo(".");
@@ -36,6 +54,61 @@ function discover_sensor (&$valid, $class, $device, $oid, $index, $type, $d
return $return;
}
function sensor_low_limit ($class, $current) {
$limit = NULL;
switch($class) {
case 'temperature':
$limit = $current * 0.7;
break;
case 'voltage':
$limit = $current * 0.95;
break;
case 'humidity':
$limit = "70";
break;
case 'freq':
$limit = $current * 0.95;
break;
case 'current':
$limit = $current * 0.90;
break;
case 'fanspeed':
$limit = $current * 0.80;
break;
}
return $limit;
}
function sensor_limit ($class, $current) {
$limit = NULL;
switch($class) {
case 'temperature':
$limit = $current * 1.20;
break;
case 'voltage':
$limit = $current * 1.05;
break;
case 'humidity':
$limit = "70";
break;
case 'freq':
$limit = $current * 1.05;
break;
case 'current':
$limit = $current * 1.10;
break;
case 'fanspeed':
$limit = $current * 1.30;
break;
}
return $limit;
}
function check_valid_sensors($device, $class, $valid) {
$sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='".$class."' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))

View File

@@ -29,6 +29,9 @@ if($device['os'] == "ironware")
$descr = str_replace("Active management module", "Mgmt Module", $descr);
$descr = str_replace(" ", " ", $descr);
$descr = trim($descr);
$current = $temperature / 2;
discover_sensor($valid_sensor, 'temperature', $device, $temperature_oid, $oid, 'ironware', $descr, '2', '1', NULL, NULL, NULL, NULL, $current);
}
}