mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	sensors table, with humidity as its first consumer - akcp humidity support implemented
git-svn-id: http://www.observium.org/svn/observer/trunk@1249 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								html/images/icons/greyscale/humidity.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								html/images/icons/greyscale/humidity.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 1.0 KiB  | 
							
								
								
									
										
											BIN
										
									
								
								html/images/icons/humidity.png
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								html/images/icons/humidity.png
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 626 B  | 
							
								
								
									
										51
									
								
								html/includes/graphs/device_humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								html/includes/graphs/device_humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
include("common.inc.php");
 | 
			
		||||
$device = device_by_id_cache($id);
 | 
			
		||||
 | 
			
		||||
$rrd_options .= " -l 0 -E ";
 | 
			
		||||
 | 
			
		||||
$iter = "1";
 | 
			
		||||
$sql = mysql_query("SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '$id' ORDER BY sensor_index");
 | 
			
		||||
$rrd_options .= " COMMENT:'                           Cur   Min   Max\\n'";
 | 
			
		||||
while($humidity = mysql_fetch_array($sql)) 
 | 
			
		||||
{
 | 
			
		||||
  switch ($iter)
 | 
			
		||||
  {
 | 
			
		||||
    case "1":
 | 
			
		||||
      $colour= "CC0000"; 
 | 
			
		||||
      break; 
 | 
			
		||||
    case "2":
 | 
			
		||||
      $colour= "008C00"; 
 | 
			
		||||
      break; 
 | 
			
		||||
    case "3":
 | 
			
		||||
      $colour= "4096EE"; 
 | 
			
		||||
      break; 
 | 
			
		||||
    case "4":
 | 
			
		||||
      $colour= "73880A"; 
 | 
			
		||||
      break;
 | 
			
		||||
    case "5":
 | 
			
		||||
      $colour= "D01F3C"; 
 | 
			
		||||
      break;
 | 
			
		||||
    case "6":
 | 
			
		||||
      $colour= "36393D"; 
 | 
			
		||||
      break; 
 | 
			
		||||
    case "7": 
 | 
			
		||||
    default:
 | 
			
		||||
      $colour= "FF0084"; 
 | 
			
		||||
      unset($iter);
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  $humidity['sensor_descr_fixed'] = substr(str_pad($humidity['sensor_descr'], 22),0,22);
 | 
			
		||||
  $humidityrrd  = $config['rrd_dir'] . "/".$device['hostname']."/".safename("humidity-" . $humidity['sensor_descr'] . ".rrd");
 | 
			
		||||
  $rrd_options .= " DEF:humidity" . $humidity['sensor_id'] . "=$humidityrrd:humidity:AVERAGE ";
 | 
			
		||||
  $rrd_options .= " LINE1:humidity" . $humidity['sensor_id'] . "#" . $colour . ":'" . str_replace(':','\:',str_replace('\*','*',quotemeta($humidity['sensor_descr_fixed']))) . "' ";
 | 
			
		||||
  $rrd_options .= " GPRINT:humidity" . $humidity['sensor_id'] . ":LAST:%3.0lf%% ";
 | 
			
		||||
  $rrd_options .= " GPRINT:humidity" . $humidity['sensor_id'] . ":MIN:%3.0lf%% ";
 | 
			
		||||
  $rrd_options .= " GPRINT:humidity" . $humidity['sensor_id'] . ":MAX:%3.0lf%%\\\l ";
 | 
			
		||||
  $iter++;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										37
									
								
								html/includes/graphs/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								html/includes/graphs/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$scale_min = "25";
 | 
			
		||||
$scale_max = "40";
 | 
			
		||||
 | 
			
		||||
include("common.inc.php");
 | 
			
		||||
 | 
			
		||||
  $rrd_options .= " COMMENT:'                                 Last   Max\\n'";
 | 
			
		||||
 | 
			
		||||
  $humidity = mysql_fetch_array(mysql_query("SELECT * FROM sensors WHERE sensor_class='humidity' AND sensor_id = '".mres($_GET['id'])."'"));
 | 
			
		||||
 | 
			
		||||
  $hostname = mysql_result(mysql_query("SELECT hostname FROM devices WHERE device_id = '" . $humidity['device_id'] . "'"),0);
 | 
			
		||||
 | 
			
		||||
  $humidity['sensor_descr_fixed'] = substr(str_pad($humidity['sensor_descr'], 28),0,28);
 | 
			
		||||
 | 
			
		||||
  $rrd_filename  = $config['rrd_dir'] . "/".$hostname."/" . safename("humidity-" . $humidity['sensor_descr'] . ".rrd");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  $rrd_options .= " DEF:humidity=$rrd_filename:humidity:AVERAGE";
 | 
			
		||||
  $rrd_options .= " DEF:humidity_max=$rrd_filename:humidity:MAX";
 | 
			
		||||
  $rrd_options .= " DEF:humidity_min=$rrd_filename:humidity:MIN";
 | 
			
		||||
  $rrd_options .= " CDEF:humiditywarm=humidity_max,".$humidity['sensor_limit'].",GT,humidity,UNKN,IF";
 | 
			
		||||
  $rrd_options .= " CDEF:humiditycold=humidity_min,20,LT,humidity,UNKN,IF";
 | 
			
		||||
  $rrd_options .= " AREA:humidity_max#c5c5c5";
 | 
			
		||||
  $rrd_options .= " AREA:humidity_min#ffffffff";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#  $rrd_options .= " AREA:humidity#bbd392";
 | 
			
		||||
#  $rrd_options .= " AREA:humiditywarm#FFCCCC";
 | 
			
		||||
#  $rrd_options .= " AREA:humiditycold#CCCCFF";
 | 
			
		||||
  $rrd_options .= " LINE1:humidity#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($humidity['sensor_descr_fixed'])))."'"; # Ugly hack :(
 | 
			
		||||
  $rrd_options .= " LINE1:humiditywarm#660000";
 | 
			
		||||
  $rrd_options .= " GPRINT:humidity:LAST:%3.0lf%%";
 | 
			
		||||
  $rrd_options .= " GPRINT:humidity:MAX:%3.0lf%%\\\\l";
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -181,6 +181,7 @@ echo('<li><a href="ports/?status=0"><img src="images/16/link_error.png" border="
 | 
			
		||||
        <li><a href="health/storage/"><img src="images/icons/storage.png" border="0" align="absmiddle" /> Storage</a></li>
 | 
			
		||||
        <li><hr width=140 /></li>
 | 
			
		||||
        <li><a href="health/temperatures/"><img src="images/icons/temperatures.png" border="0" align="absmiddle" /> Temperatures</a></li>
 | 
			
		||||
        <li><a href="health/humidity/"><img src="images/icons/humidity.png" border="0" align="absmiddle" /> Humidity</a></li>
 | 
			
		||||
        <li><a href="health/fanspeeds/"><img src="images/icons/fanspeeds.png" border="0" align="absmiddle" /> Fans</a></li>
 | 
			
		||||
        <li><hr width=140 /></li>
 | 
			
		||||
        <li><a href="health/voltages/"><img src="images/icons/voltages.png" border="0" align="absmiddle" /> Voltages</a></li>
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$temperatures = mysql_result(mysql_query("select count(*) from temperature WHERE 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);
 | 
			
		||||
$memory = mysql_result(mysql_query("select count(*) from mempools WHERE device_id = '" . $device['device_id'] . "'"), 0);
 | 
			
		||||
@@ -16,6 +17,7 @@ if ($memory) { $datas[] = 'memory'; }
 | 
			
		||||
if ($storage) { $datas[] = 'storage'; }
 | 
			
		||||
if ($diskio) { $datas[] = 'diskio'; }
 | 
			
		||||
if ($temperatures) { $datas[] = 'temperatures'; }
 | 
			
		||||
if ($humidity) { $datas[] = 'humidity'; }
 | 
			
		||||
if ($fans) { $datas[] = 'fanspeeds'; }
 | 
			
		||||
if ($volts) { $datas[] = 'voltages'; }
 | 
			
		||||
if ($freqs) { $datas[] = 'frequencies'; }
 | 
			
		||||
@@ -24,6 +26,7 @@ if ($current) { $datas[] = 'current'; }
 | 
			
		||||
 | 
			
		||||
$type_text['overview'] = "Overview";
 | 
			
		||||
$type_text['temperatures'] = "Temperatures";
 | 
			
		||||
$type_text['humidity'] = "Humidity";
 | 
			
		||||
$type_text['memory'] = "Memory Pools";
 | 
			
		||||
$type_text['storage'] = "Disk Usage";
 | 
			
		||||
$type_text['diskio'] = "Disk IO";
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										59
									
								
								html/pages/device/health/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								html/pages/device/health/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$sql = "SELECT * FROM `sensors` WHERE sensor_class='humidity' AND device_id = '" . $_GET[id] . "' ORDER BY sensor_descr";
 | 
			
		||||
$query = mysql_query($sql);
 | 
			
		||||
 | 
			
		||||
echo("<table cellspacing=0 cellpadding=5 width=100%>");
 | 
			
		||||
 | 
			
		||||
$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("<tr class=list-large style=\"background-color: $row_colour; padding: 5px;\">
 | 
			
		||||
          <td width=350>" . $humidity['sensor_descr'] . "</td>
 | 
			
		||||
          <td>" . $humidity['sensor_current'] . " %</td>
 | 
			
		||||
          <td>" . $humidity['sensor_limit'] . " %</td>
 | 
			
		||||
          <td>" . $humidity['sensor_notes'] . "</td>
 | 
			
		||||
        </tr>\n");
 | 
			
		||||
  echo("<tr  bgcolor=$row_colour><td colspan='4'>");
 | 
			
		||||
 | 
			
		||||
  $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("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$daily_humidity' border=0></a> ");
 | 
			
		||||
  echo("<a onmouseover=\"return overlib('<img src=\'$weekly_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$weekly_humidity' border=0></a> ");
 | 
			
		||||
  echo("<a onmouseover=\"return overlib('<img src=\'$monthly_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$monthly_humidity' border=0></a> ");
 | 
			
		||||
  echo("<a onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$yearly_humidity' border=0></a>");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  echo("</td></tr>");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  $row++;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
echo("</table>");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								html/pages/device/overview/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								html/pages/device/overview/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
unset($humidity_seperator);
 | 
			
		||||
if($total = mysql_result(mysql_query("SELECT count(sensor_id) from sensors WHERE sensor_class='humidity' 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/humidity.png'> Humidity</p>");
 | 
			
		||||
  $i = '1';
 | 
			
		||||
  $humiditys = mysql_query("SELECT * FROM sensors WHERE sensor_class='humidity' 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($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 = "<img src='graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$day&to=$now&width=80&height=20&bg=$graph_colour' align='absmiddle'>";
 | 
			
		||||
 | 
			
		||||
    $humidity_link  = "<a href='/device/".$device['device_id']."/health/humiditys/' onmouseover=\"return ";
 | 
			
		||||
    $humidity_link .= "overlib('<div class=list-large>".$device['hostname']." - ".$humidity['sensor_descr'];
 | 
			
		||||
    $humidity_link .= "</div><div style=\'width: 750px\'><img src=\'$humidity_day\'><img src=\'$humidity_week\'><img src=\'$humidity_month\'><img src=\'$humidity_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
 | 
			
		||||
 | 
			
		||||
    $humidity_link_c = $humidity_link . "<span style='color: $humidity_colour'>" . round($humidity['sensor_current'],0) . "%</span></a>";
 | 
			
		||||
    $humidity_link_b = $humidity_link . $humidity_minigraph . "</a>";
 | 
			
		||||
    $humidity_link_a = $humidity_link . $humidity['sensor_descr'] . "</a>";
 | 
			
		||||
 | 
			
		||||
    $humidity['sensor_descr'] = truncate($humidity['sensor_descr'], 25, '');
 | 
			
		||||
    echo("<tr bgcolor='$row_colour'><td class=tablehead><strong>$humidity_link_a</strong></td><td width=80 align=right class=tablehead>$humidity_link_b<td width=35 align=right class=tablehead>$humidity_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>");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$datas = array('Processors','Memory','Storage','Temperatures', 'Fanspeeds', 'Voltages', 'Frequencies', 'Current');
 | 
			
		||||
$datas = array('Processors','Memory','Storage','Temperatures', 'Humidity', 'Fanspeeds', 'Voltages', 'Frequencies', 'Current');
 | 
			
		||||
 | 
			
		||||
if(!$_GET['opta']) { $_GET['opta'] = "processors"; }
 | 
			
		||||
if(!$_GET['optb']) { $_GET['optb'] = "nographs"; }
 | 
			
		||||
@@ -57,6 +57,7 @@ switch ($_GET['opta'])
 | 
			
		||||
  case 'memory':
 | 
			
		||||
  case 'storage':
 | 
			
		||||
  case 'temperatures':
 | 
			
		||||
  case 'humidity':
 | 
			
		||||
  case 'voltages':
 | 
			
		||||
  case 'fanspeeds':
 | 
			
		||||
  case 'frequencies':
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										97
									
								
								html/pages/health/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								html/pages/health/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
if($_SESSION['userlevel'] >= '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('<table cellspacing="0" cellpadding="6" width="100%">');
 | 
			
		||||
 | 
			
		||||
echo('<tr class=tablehead>
 | 
			
		||||
        <th width="280">Device</th>
 | 
			
		||||
        <th width="280">Sensor</th>
 | 
			
		||||
	<th></th>
 | 
			
		||||
	<th></th>
 | 
			
		||||
        <th width="100">Current</th>
 | 
			
		||||
        <th width="100">Alert</th>
 | 
			
		||||
        <th>Notes</th>
 | 
			
		||||
      </tr>');
 | 
			
		||||
 | 
			
		||||
$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 = "<a onmouseover=\"return overlib('<img src=\'$weekly_humidity\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        " . $humidity['sensor_descr'] . "</a>";
 | 
			
		||||
 | 
			
		||||
  $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 = '<img src="images/16/flag_red.png" alt="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 = "<img src='graph.php?id=" . $humidity['sensor_id'] . "&type=humidity&from=$day&to=$now&width=100&height=20'";
 | 
			
		||||
  $humidity_minigraph .= " onmouseover=\"return overlib('<div class=list-large>".$humidity['hostname']." - ".$humidity['sensor_descr'];
 | 
			
		||||
  $humidity_minigraph .= "</div><div style=\'width: 750px\'><img src=\'$humidity_day\'><img src=\'$humidity_week\'><img src=\'$humidity_month\'><img src=\'$humidity_year\'></div>', RIGHT".$config['overlib_defaults'].");\" onmouseout=\"return nd();\" >";
 | 
			
		||||
 | 
			
		||||
  echo("<tr bgcolor=$row_colour>
 | 
			
		||||
          <td class=list-bold>" . generatedevicelink($humidity) . "</td>
 | 
			
		||||
          <td>$humidity_popup</td>
 | 
			
		||||
	  <td>$humidity_minigraph</td>
 | 
			
		||||
	  <td width=100>$alert</td>
 | 
			
		||||
          <td style='color: $humidity_colour; text-align: center; font-weight: bold;'>" . $humidity['sensor_current'] . " %</td>
 | 
			
		||||
          <td style='text-align: center'>" . $humidity['sensor_limit'] . " %</td>
 | 
			
		||||
          <td>" . (isset($humidity['sensor_notes']) ? $humidity['sensor_notes'] : '') . "</td>
 | 
			
		||||
        </tr>\n");
 | 
			
		||||
 | 
			
		||||
      if($_GET['optb'] == "graphs") { ## If graphs
 | 
			
		||||
 | 
			
		||||
  echo("<tr bgcolor='$row_colour'><td colspan=7>");
 | 
			
		||||
 | 
			
		||||
  $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("<a onmouseover=\"return overlib('<img src=\'$daily_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$daily_graph' border=0></a> ");
 | 
			
		||||
  echo("<a onmouseover=\"return overlib('<img src=\'$weekly_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$weekly_graph' border=0></a> ");
 | 
			
		||||
  echo("<a onmouseover=\"return overlib('<img src=\'$monthly_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$monthly_graph' border=0></a> ");
 | 
			
		||||
  echo("<a onmouseover=\"return overlib('<img src=\'$yearly_url\'>', LEFT);\" onmouseout=\"return nd();\">
 | 
			
		||||
        <img src='$yearly_graph' border=0></a>");
 | 
			
		||||
  echo("</td></tr>");
 | 
			
		||||
 | 
			
		||||
    } # endif graphs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  $row++;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
echo("</table>");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
f<?php
 | 
			
		||||
<?php
 | 
			
		||||
$id = $device['device_id'];
 | 
			
		||||
$hostname = $device['hostname'];
 | 
			
		||||
$community = $device['community'];
 | 
			
		||||
@@ -31,7 +31,7 @@ switch ($device['os'])
 | 
			
		||||
          $humidity_oid = ".1.3.6.1.4.1.3854.1.2.2.1.17.1.3.$humidity_id";
 | 
			
		||||
          $warnlimit_oid = ".1.3.6.1.4.1.3854.1.2.2.1.17.1.7.$humidity_id";
 | 
			
		||||
          $limit_oid = ".1.3.6.1.4.1.3854.1.2.2.1.17.1.8.$humidity_id";
 | 
			
		||||
          # .9 = low warn limit
 | 
			
		||||
          $warnlowlimit_oid = ".1.3.6.1.4.1.3854.1.2.2.1.17.1.9.$humidity_id";
 | 
			
		||||
          $lowlimit_oid = ".1.3.6.1.4.1.3854.1.2.2.1.17.1.10.$humidity_id";
 | 
			
		||||
          
 | 
			
		||||
          $descr = trim(snmp_get($device, $descr_oid, "-Oqv", ""),'"');
 | 
			
		||||
@@ -39,9 +39,9 @@ switch ($device['os'])
 | 
			
		||||
          $warnlimit = snmp_get($device, $warnlimit_oid, "-Oqv", "");
 | 
			
		||||
          $limit = snmp_get($device, $limit_oid, "-Oqv", "");
 | 
			
		||||
          $lowlimit = snmp_get($device, $lowlimit_oid, "-Oqv", "");
 | 
			
		||||
          $warnlowlimit = snmp_get($device, $warnlowlimit_oid, "-Oqv", "");
 | 
			
		||||
        
 | 
			
		||||
          # FIXME no warnlimit in table/discover function yet...
 | 
			
		||||
#          discover_humidity($valid_humidity, $device, $humidity_oid, $humidity_id, "akcp", $descr, 1, $lowlimit, $limit, $humidity);
 | 
			
		||||
          discover_humidity($valid_humidity, $device, $humidity_oid, $humidity_id, "akcp", $descr, 1, $lowlimit, $warnlowlimit, $limit, $warnlimit, $humidity);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
@@ -50,18 +50,18 @@ switch ($device['os'])
 | 
			
		||||
 | 
			
		||||
if($debug) { print_r($valid_humidity); }
 | 
			
		||||
 | 
			
		||||
$sql = "SELECT * FROM humidity 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='humidity' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
 | 
			
		||||
if ($query = mysql_query($sql))
 | 
			
		||||
{
 | 
			
		||||
  while ($test_humidity = mysql_fetch_array($query)) 
 | 
			
		||||
  {
 | 
			
		||||
    $humidity_index = $test_humidity['humidity_index'];
 | 
			
		||||
    $humidity_type = $test_humidity['humidity_type'];
 | 
			
		||||
    $humidity_index = $test_humidity['sensor_index'];
 | 
			
		||||
    $humidity_type = $test_humidity['sensor_type'];
 | 
			
		||||
    if($debug) { echo($humidity_index . " -> " . $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);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$hardware = trim(snmp_get($device, "1.3.6.1.4.1.3854.1.1.6.0", "-OQv", "", ""),'"');
 | 
			
		||||
$hardware .= trim(snmp_get($device, "1.3.6.1.4.1.3854.1.1.8.0", "-OQv", "", ""),'"');
 | 
			
		||||
$hardware .= ' ' . trim(snmp_get($device, "1.3.6.1.4.1.3854.1.1.8.0", "-OQv", "", ""),'"');
 | 
			
		||||
 | 
			
		||||
$hardware = str_replace('  ',' ',$hardware);
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										55
									
								
								includes/polling/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								includes/polling/humidity.inc.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,55 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
$query = "SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "'";
 | 
			
		||||
$hum_data = mysql_query($query);
 | 
			
		||||
while($humidity = mysql_fetch_array($hum_data)) {
 | 
			
		||||
 | 
			
		||||
  echo("Checking humidity " . $humidity['sensor_descr'] . "... ");
 | 
			
		||||
 | 
			
		||||
  $hum_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $humidity['sensor_oid'] . "|grep -v \"No Such Instance\"";
 | 
			
		||||
  $hum = trim(str_replace("\"", "", shell_exec($hum_cmd)));
 | 
			
		||||
 | 
			
		||||
  if ($humidity['sensor_precision']) 
 | 
			
		||||
  {
 | 
			
		||||
    $hum = $hum / $humidity['sensor_precision'];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $humrrd  = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("humidity-" . $humidity['sensor_descr'] . ".rrd");
 | 
			
		||||
 | 
			
		||||
  if (!is_file($humrrd)) {
 | 
			
		||||
    `rrdtool create $humrrd \
 | 
			
		||||
     --step 300 \
 | 
			
		||||
     DS:humidity:GAUGE:600:-273:1000 \
 | 
			
		||||
     RRA:AVERAGE:0.5:1:1200 \
 | 
			
		||||
     RRA:MIN:0.5:12:2400 \
 | 
			
		||||
     RRA:MAX:0.5:12:2400 \
 | 
			
		||||
     RRA:AVERAGE:0.5:12:2400`;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  echo($hum . " %\n");
 | 
			
		||||
 | 
			
		||||
  rrdtool_update($humrrd,"N:$hum");
 | 
			
		||||
 | 
			
		||||
  if($humidity['sensor_current'] > $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'] . "'");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
?>
 | 
			
		||||
@@ -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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user