diff --git a/database-update.sql b/database-update.sql index 78c51bff2..4b2b6ec3a 100644 --- a/database-update.sql +++ b/database-update.sql @@ -16,3 +16,4 @@ CREATE TABLE IF NOT EXISTS `ucd_diskio` ( `diskio_id` int(11) NOT NULL AUTO_INC ALTER TABLE `eventlog` CHANGE `type` `type` VARCHAR( 64 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL; ALTER TABLE `bills` ADD `bill_custid` VARCHAR( 64 ) NOT NULL ,ADD `bill_ref` VARCHAR( 64 ) NOT NULL ,ADD `bill_notes` VARCHAR( 256 ) NOT NULL; CREATE TABLE IF NOT EXISTS `applications` ( `app_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `app_type` varchar(64) NOT NULL, PRIMARY KEY (`app_id`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; +CREATE TABLE IF NOT EXISTS `sensors` ( `sensor_id` int(11) NOT NULL auto_increment, `sensor_class` varchar(64) NOT NULL, `device_id` int(11) NOT NULL default '0', `sensor_oid` varchar(64) NOT NULL, `sensor_index` varchar(8) NOT NULL, `sensor_type` varchar(32) NOT NULL, `sensor_descr` varchar(32) NOT NULL default '', `sensor_precision` int(11) NOT NULL default '1', `sensor_current` float default NULL, `sensor_limit` float default NULL, `sensor_limit_warn` float default NULL, `sensor_limit_low` float default NULL, `sensor_limit_low_warn` float default NULL, PRIMARY KEY (`sensor_id`), KEY `sensor_host` (`device_id`)) ENGINE=MyISAM AUTO_INCREMENT=189 DEFAULT CHARSET=latin1; diff --git a/html/images/icons/greyscale/humidity.png b/html/images/icons/greyscale/humidity.png new file mode 100644 index 000000000..fe7d85690 Binary files /dev/null and b/html/images/icons/greyscale/humidity.png differ diff --git a/html/images/icons/humidity.png b/html/images/icons/humidity.png new file mode 100755 index 000000000..cb3d54d06 Binary files /dev/null and b/html/images/icons/humidity.png differ diff --git a/html/includes/graphs/device_humidity.inc.php b/html/includes/graphs/device_humidity.inc.php new file mode 100644 index 000000000..0ac5e2b81 --- /dev/null +++ b/html/includes/graphs/device_humidity.inc.php @@ -0,0 +1,51 @@ + diff --git a/html/includes/graphs/humidity.inc.php b/html/includes/graphs/humidity.inc.php new file mode 100644 index 000000000..a07a89164 --- /dev/null +++ b/html/includes/graphs/humidity.inc.php @@ -0,0 +1,37 @@ + diff --git a/html/includes/graphs/temperature.inc.php b/html/includes/graphs/temperature.inc.php index fec3b9c3b..bff7b6021 100644 --- a/html/includes/graphs/temperature.inc.php +++ b/html/includes/graphs/temperature.inc.php @@ -7,7 +7,6 @@ include("common.inc.php"); $rrd_options .= " COMMENT:' Last Max\\n'"; - $sql = mysql_query("SELECT * FROM temperature where temp_id = '$temp'"); $temperature = mysql_fetch_array(mysql_query("SELECT * FROM temperature where temp_id = '".mres($_GET['id'])."'")); $hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $temperature['device_id'] . "'"),0); diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 119b3fc33..1c0b3d7cf 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -181,6 +181,7 @@ echo('
  • Storage

  • Temperatures
  • +
  • Humidity
  • Fans

  • Voltages
  • diff --git a/html/pages/device/health.inc.php b/html/pages/device/health.inc.php index 267643b7f..bc1ee400f 100644 --- a/html/pages/device/health.inc.php +++ b/html/pages/device/health.inc.php @@ -1,6 +1,7 @@ "); + +$row = 1; + +while($humidity = mysql_fetch_array($query)) { + + if(!is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + echo(" + " . $humidity['sensor_descr'] . " + " . $humidity['sensor_current'] . " % + " . $humidity['sensor_limit'] . " % + " . $humidity['sensor_notes'] . " + \n"); + echo(""); + + $graph_type = "humidity"; + +// start humidity graphs + + $daily_humidity = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=211&height=100"; + $daily_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$day&to=$now&width=400&height=150"; + + $weekly_humidity = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=211&height=100"; + $weekly_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$week&to=$now&width=400&height=150"; + + $monthly_humidity = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=211&height=100"; + $monthly_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$month&to=$now&width=400&height=150"; + + $yearly_humidity = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=211&height=100"; + $yearly_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=$graph_type&from=$year&to=$now&width=400&height=150"; + + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + + + echo(""); + + + $row++; + +} + +echo(""); + + +?> + diff --git a/html/pages/device/overview.inc.php b/html/pages/device/overview.inc.php index a6a8ac0ce..d84d41684 100644 --- a/html/pages/device/overview.inc.php +++ b/html/pages/device/overview.inc.php @@ -91,6 +91,7 @@ include("overview/mempools.inc.php"); #include("overview/hrStorage.inc.php"); include("overview/storage.inc.php"); include("overview/temperatures.inc.php"); +include("overview/humidity.inc.php"); include("overview/fanspeeds.inc.php"); include("overview/voltages.inc.php"); include("overview/frequencies.inc.php"); diff --git a/html/pages/device/overview/humidity.inc.php b/html/pages/device/overview/humidity.inc.php new file mode 100644 index 000000000..093ab4467 --- /dev/null +++ b/html/pages/device/overview/humidity.inc.php @@ -0,0 +1,46 @@ +"); + echo("

    Humidity

    "); + $i = '1'; + $humiditys = mysql_query("SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "' ORDER BY sensor_index"); + echo(''); + echo('"); + echo("
    '); + echo(''); + while($humidity = mysql_fetch_array($humiditys)) { + if(is_integer($i/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + $graph_colour = str_replace("#", "", $row_colour); + + $humidity_perc = $humidity['sensor_current'] / $humidity['sensor_limit'] * 100; + $humidity_colour = percent_colour($humidity_perc); + $humidity_day = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$day&to=$now&width=300&height=100"; + $humidity_week = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$week&to=$now&width=300&height=100"; + $humidity_month = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$month&to=$now&width=300&height=100"; + $humidity_year = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$year&to=$now&width=300&height=100"; + $humidity_minigraph = ""; + + $humidity_link = ""; + + $humidity_link_c = $humidity_link . "" . round($humidity['sensor_current'],0) . "%"; + $humidity_link_b = $humidity_link . $humidity_minigraph . ""; + $humidity_link_a = $humidity_link . $humidity['sensor_descr'] . ""; + + $humidity['sensor_descr'] = truncate($humidity['sensor_descr'], 25, ''); + echo(""); + if($i == $rows) { echo("
    $humidity_link_a$humidity_link_b$humidity_link_c
    "); } + $i++; + } + echo("
    "); + echo("
    "); + echo(""); +} + + +?> diff --git a/html/pages/health.php b/html/pages/health.php index 99e5db414..1a67e478b 100644 --- a/html/pages/health.php +++ b/html/pages/health.php @@ -1,6 +1,6 @@ = '5') { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D WHERE S.sensor_class='humidity' AND S.device_id = D.device_id ORDER BY D.hostname, S.sensor_index, S.sensor_descr"; +} else { + $sql = "SELECT * FROM `sensors` AS S, `devices` AS D, devices_perms as P WHERE S.sensor_class='humidity' 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_index, S.sensor_descr"; +} + +$query = mysql_query($sql); + +echo(''); + +echo(' + + + + + + + + '); + +$row = 1; + +while($humidity = mysql_fetch_array($query)) +{ + if(is_integer($row/2)) { $row_colour = $list_colour_a; } else { $row_colour = $list_colour_b; } + + $weekly_humidity = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$week&to=$now&width=500&height=150"; + $humidity_popup = "', LEFT);\" onmouseout=\"return nd();\"> + " . $humidity['sensor_descr'] . ""; + + $humidity['sensor_current'] = round($humidity['sensor_current'],1); + + $humidity_perc = $humidity['sensor_current'] / $humidity['sensor_limit'] * 100; + $humidity_colour = percent_colour($humidity_perc); + + if($humidity['sensor_current'] >= $humidity['sensor_limit']) { $alert = 'alert'; } else { $alert = ""; } + + $humidity_day = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$day&to=$now&width=300&height=100"; + $humidity_week = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$week&to=$now&width=300&height=100"; + $humidity_month = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$month&to=$now&width=300&height=100"; + $humidity_year = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$year&to=$now&width=300&height=100"; + + $humidity_minigraph = "".$humidity['hostname']." - ".$humidity['sensor_descr']; + $humidity_minigraph .= "
    ', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >"; + + echo(" + + + + + + + + \n"); + + if($_GET['optb'] == "graphs") { ## If graphs + + echo(""); + + } # endif graphs + + + + $row++; + +} + +echo("
    DeviceSensorCurrentAlertNotes
    " . generatedevicelink($humidity) . "$humidity_popup$humidity_minigraph$alert" . $humidity['sensor_current'] . " %" . $humidity['sensor_limit'] . " %" . (isset($humidity['sensor_notes']) ? $humidity['sensor_notes'] : '') . "
    "); + + $daily_graph = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$day&to=$now&width=211&height=100"; + $daily_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$day&to=$now&width=400&height=150"; + + $weekly_graph = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$week&to=$now&width=211&height=100"; + $weekly_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$week&to=$now&width=400&height=150"; + + $monthly_graph = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$month&to=$now&width=211&height=100"; + $monthly_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$month&to=$now&width=400&height=150"; + + $yearly_graph = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$year&to=$now&width=211&height=100"; + $yearly_url = "graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$year&to=$now&width=400&height=150"; + + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("', LEFT);\" onmouseout=\"return nd();\"> + "); + echo("
    "); + + +?> + diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 16a29c6db..e234662aa 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -295,6 +295,43 @@ function discover_freq(&$valid, $device, $oid, $index, $type, $descr, $precision return $return; } +function discover_humidity(&$valid, $device, $oid, $index, $type, $descr, $precision = 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='humidity' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0') + { + $query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) "; + $query .= " VALUES ('humidity', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')"; + mysql_query($query); + if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); } + echo("+"); + } + else + { + $sensor_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='humidity' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'")); + if($oid == $sensor_entry['sensor_oid'] && $descr == $sensor_entry['sensor_descr'] && $precision == $sensor_entry['sensor_precision']) + { + echo("."); + } + else + { + mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'humidity' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index' "); + echo("U"); + if($debug) { echo("$query ". mysql_affected_rows() . " updated"); } + } + } + + $valid[$type][$index] = 1; + return $return; +} + function discover_current(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL) { global $config, $debug; diff --git a/includes/discovery/humidity.inc.php b/includes/discovery/humidity.inc.php index beb5f2653..5e3f15027 100755 --- a/includes/discovery/humidity.inc.php +++ b/includes/discovery/humidity.inc.php @@ -1,4 +1,4 @@ -f " . $humidity_type . "\n"); } if(!$valid_humidity[$humidity_type][$humidity_index]) { echo("-"); - mysql_query("DELETE FROM `humidity` WHERE humidity_id = '" . $test_humidity['humidity_id'] . "'"); + mysql_query("DELETE FROM `sensors` WHERE sensor_class='humidity' AND sensor_id = '" . $test_humidity['sensor_id'] . "'"); } unset($humidity_oid); unset($humidity_type); } diff --git a/includes/polling/device-akcp.inc.php b/includes/polling/device-akcp.inc.php index b3b8948e2..68586e4ec 100644 --- a/includes/polling/device-akcp.inc.php +++ b/includes/polling/device-akcp.inc.php @@ -1,6 +1,8 @@ diff --git a/includes/polling/humidity.inc.php b/includes/polling/humidity.inc.php new file mode 100644 index 000000000..94b859b51 --- /dev/null +++ b/includes/polling/humidity.inc.php @@ -0,0 +1,55 @@ + $humidity['sensor_limit_low'] && $hum <= $humidity['sensor_limit_low']) + { + if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } + $msg = "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'] . " is " . $hum . "% (Limit " . $humidity['sensor_limit']; + $msg .= "%) at " . date($config['timestamp_format']); + mail($email, "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'], $msg, $config['email_headers']); + echo("Alerting for " . $device['hostname'] . " " . $humidity['sensor_descr'] . "\n"); + log_event('Frequency ' . $humidity['sensor_descr'] . " under threshold: " . $hum . " % (< " . $humidity['sensor_limit_low'] . " %)", $device['device_id'] , 'humidity', $humidity['sensor_id']); + } + else if($humidity['sensor_current'] < $humidity['sensor_limit'] && $hum >= $humidity['sensor_limit']) + { + if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; } + $msg = "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'] . " is " . $hum . "% (Limit " . $humidity['sensor_limit']; + $msg .= "%) at " . date($config['timestamp_format']); + mail($email, "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'], $msg, $config['email_headers']); + echo("Alerting for " . $device['hostname'] . " " . $humidity['sensor_descr'] . "\n"); + log_event('Humidity ' . $humidity['sensor_descr'] . " above threshold: " . $hum . " % (> " . $humidity['sensor_limit'] . " %)", $device['device_id'], 'humidity', $humidity['sensor_id']); + } + + mysql_query("UPDATE sensors SET sensor_current = '$hum' WHERE sensor_class='humidity' AND sensor_id = '" . $humidity['sensor_id'] . "'"); +} + +?> diff --git a/poll-device.php b/poll-device.php index 339d8beb7..1ec2897ff 100755 --- a/poll-device.php +++ b/poll-device.php @@ -166,6 +166,7 @@ while ($device = mysql_fetch_array($device_query)) { $sysLocation = str_replace("\"","", $sysLocation); include("includes/polling/temperatures.inc.php"); + include("includes/polling/humidity.inc.php"); include("includes/polling/fanspeeds.inc.php"); include("includes/polling/voltages.inc.php"); include("includes/polling/frequencies.inc.php");