diff --git a/html/includes/graphs/device_fanspeeds.inc.php b/html/includes/graphs/device_fanspeeds.inc.php index 8c1e67e40..322ccf6b2 100644 --- a/html/includes/graphs/device_fanspeeds.inc.php +++ b/html/includes/graphs/device_fanspeeds.inc.php @@ -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++; } - ?> diff --git a/html/includes/graphs/fanspeed.inc.php b/html/includes/graphs/fanspeed.inc.php index b697720ef..ac1c5ff3e 100644 --- a/html/includes/graphs/fanspeed.inc.php +++ b/html/includes/graphs/fanspeed.inc.php @@ -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"; diff --git a/html/pages/device/health.inc.php b/html/pages/device/health.inc.php index e53303340..62c650b78 100644 --- a/html/pages/device/health.inc.php +++ b/html/pages/device/health.inc.php @@ -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); diff --git a/html/pages/device/health/fanspeeds.inc.php b/html/pages/device/health/fanspeeds.inc.php index 5c6f9c809..a53774afb 100644 --- a/html/pages/device/health/fanspeeds.inc.php +++ b/html/pages/device/health/fanspeeds.inc.php @@ -1,6 +1,6 @@ "); @@ -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(" - " . $fan['fan_descr'] . " - " . $fan['fan_current'] . " rpm - " . $fan['fan_limit'] . " rpm - " . $fan['fan_notes'] . " + " . $fan['sensor_descr'] . " + " . $fan['sensor_current'] . " rpm + " . $fan['sensor_limit'] . " rpm + " . $fan['sensor_notes'] . " \n"); echo(""); @@ -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("', LEFT);\" onmouseout=\"return nd();\"> "); diff --git a/html/pages/device/overview/fanspeeds.inc.php b/html/pages/device/overview/fanspeeds.inc.php index ec7c1efaa..2de393ef5 100644 --- a/html/pages/device/overview/fanspeeds.inc.php +++ b/html/pages/device/overview/fanspeeds.inc.php @@ -1,8 +1,7 @@ "); echo("

Fanspeeds

"); @@ -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 = ""; + $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 = ""; $fan_link = ""; $fan_link_b = $fan_link . $fan_minigraph . ""; - $fan_link_c = $fan_link . "" . $fan['fan_current'] . "rpm"; - $fan_link_a = $fan_link . $fan['fan_descr'] . ""; + $fan_link_c = $fan_link . "" . $fan['sensor_current'] . "rpm"; + $fan_link_a = $fan_link . $fan['sensor_descr'] . ""; - $fan['fan_descr'] = truncate($fan['fan_descr'], 25, ''); + $fan['sensor_descr'] = truncate($fan['sensor_descr'], 25, ''); echo("$fan_link_a$fan_link_b$fan_link_c"); if($i == $rows) { echo(""); } $i++; diff --git a/html/pages/health/fanspeeds.inc.php b/html/pages/health/fanspeeds.inc.php index 6736e4ba5..72a38e96c 100644 --- a/html/pages/health/fanspeeds.inc.php +++ b/html/pages/health/fanspeeds.inc.php @@ -1,9 +1,9 @@ = '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'] . "&type=fanspeed&from=$week&to=$now&width=500&height=150"; + $weekly_fan = "graph.php?id=" . $fan['sensor_id'] . "&type=fanspeed&from=$week&to=$now&width=500&height=150"; $fan_popup = "', LEFT);\" onmouseout=\"return nd();\"> - " . $fan['fan_descr'] . ""; + " . $fan['sensor_descr'] . ""; - if($fan['fan_current'] <= $fan['fan_limit']) { $alert = 'alert'; } else { $alert = ""; } + if($fan['sensor_current'] <= $fan['sensor_limit']) { $alert = 'alert'; } else { $alert = ""; } - $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_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 = "".$fan['hostname']." - ".$fan['fan_descr']; + $fan_minigraph = "".$fan['hostname']." - ".$fan['sensor_descr']; $fan_minigraph .= "
', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >"; echo(" @@ -46,26 +46,26 @@ while($fan = mysql_fetch_array($query)) - - - + + + \n"); if($_GET['optb'] == "graphs") { ## If graphs echo("
$fan_popup $fan_minigraph $alert" . $fan['fan_current'] . " rpm" . $fan['fan_limit'] . " rpm" . (isset($fan['fan_notes']) ? $fan['fan_notes'] : '') . "" . $fan['sensor_current'] . " rpm" . $fan['sensor_limit'] . " rpm" . (isset($fan['sensor_notes']) ? $fan['sensor_notes'] : '') . "
"); - $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("', LEFT);\" onmouseout=\"return nd();\"> "); diff --git a/includes/discovery/fanspeeds.inc.php b/includes/discovery/fanspeeds.inc.php index fe8e09141..8aff8f19e 100644 --- a/includes/discovery/fanspeeds.inc.php +++ b/includes/discovery/fanspeeds.inc.php @@ -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'] . "'"); } } } diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index eb15a8872..ab06be2c9 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -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"); } } diff --git a/includes/polling/fanspeeds.inc.php b/includes/polling/fanspeeds.inc.php index cd6b1bee9..d158d198a 100755 --- a/includes/polling/fanspeeds.inc.php +++ b/includes/polling/fanspeeds.inc.php @@ -1,16 +1,16 @@ $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'] . "'"); } ?>