mirror of
				https://github.com/librenms/librenms.git
				synced 2024-10-07 16:52:45 +00:00 
			
		
		
		
	git-svn-id: http://www.observium.org/svn/observer/trunk@2029 61d68cd4-352d-0410-923a-c4978735b2b8
		
			
				
	
	
		
			50 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
$query = "SELECT * FROM sensors WHERE sensor_class='humidity' AND device_id = '" . $device['device_id'] . "' AND poller_type='snmp'";
 | 
						|
$hum_data = mysql_query($query);
 | 
						|
while ($humidity = mysql_fetch_assoc($hum_data))
 | 
						|
{
 | 
						|
  echo("Checking humidity " . $humidity['sensor_descr'] . "... ");
 | 
						|
 | 
						|
  $hum = snmp_get($device, $humidity['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
 | 
						|
 | 
						|
  if ($humidity['sensor_divisor'])    { $hum = $hum / $humidity['sensor_divisor']; }
 | 
						|
  if ($humidity['sensor_multiplier']) { $hum = $hum / $humidity['sensor_multiplier']; }
 | 
						|
 | 
						|
  $humrrd  = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("humidity-" . $humidity['sensor_descr'] . ".rrd");
 | 
						|
 | 
						|
  if (!is_file($humrrd))
 | 
						|
  {
 | 
						|
    rrdtool_create($humrrd,"--step 300 \
 | 
						|
     DS:sensor: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'])
 | 
						|
  {
 | 
						|
    $msg  = "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'] . " is " . $hum . "% (Limit " . $humidity['sensor_limit'];
 | 
						|
    $msg .= "%) at " . date($config['timestamp_format']);
 | 
						|
    notify($device, "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'], $msg);
 | 
						|
    echo("Alerting for " . $device['hostname'] . " " . $humidity['sensor_descr'] . "\n");
 | 
						|
    log_event('Frequency ' . $humidity['sensor_descr'] . " under threshold: " . $hum . " % (< " . $humidity['sensor_limit_low'] . " %)", $device, 'humidity', $humidity['sensor_id']);
 | 
						|
  }
 | 
						|
  else if ($humidity['sensor_current'] < $humidity['sensor_limit'] && $hum >= $humidity['sensor_limit'])
 | 
						|
  {
 | 
						|
    $msg  = "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'] . " is " . $hum . "% (Limit " . $humidity['sensor_limit'];
 | 
						|
    $msg .= "%) at " . date($config['timestamp_format']);
 | 
						|
    notify($device, "Humidity Alarm: " . $device['hostname'] . " " . $humidity['sensor_descr'], $msg);
 | 
						|
    echo("Alerting for " . $device['hostname'] . " " . $humidity['sensor_descr'] . "\n");
 | 
						|
    log_event('Humidity ' . $humidity['sensor_descr'] . " above threshold: " . $hum . " % (> " . $humidity['sensor_limit'] . " %)", $device, 'humidity', $humidity['sensor_id']);
 | 
						|
  }
 | 
						|
 | 
						|
  mysql_query("UPDATE sensors SET sensor_current = '$hum' WHERE sensor_class='humidity' AND sensor_id = '" . $humidity['sensor_id'] . "'");
 | 
						|
}
 | 
						|
 | 
						|
?>
 |