move temperatures to sensors table - please run discovery immediately after svn up

git-svn-id: http://www.observium.org/svn/observer/trunk@1269 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-06-25 22:12:56 +00:00
parent 1c7c3e178e
commit 635398d2c8
10 changed files with 86 additions and 88 deletions

View File

@@ -1,24 +1,24 @@
<?php
$query = "SELECT * FROM temperature WHERE device_id = '" . $device['device_id'] . "'";
$query = "SELECT * FROM sensors WHERE sensor_class='temperature' AND device_id = '" . $device['device_id'] . "'";
$temp_data = mysql_query($query);
while($temperature = mysql_fetch_array($temp_data)) {
echo("Checking temp " . $temperature['temp_descr'] . "... ");
echo("Checking temp " . $temperature['sensor_descr'] . "... ");
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
{
if ($debug) echo "Attempt $i ";
$temp_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['temp_oid'] . "|grep -v \"No Such Instance\"";
$temp_cmd = $config['snmpget'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $temperature['sensor_oid'] . "|grep -v \"No Such Instance\"";
$temp = trim(str_replace("\"", "", shell_exec($temp_cmd)));
if ($temp != 9999) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
sleep(1); # Give the TME some time to reset
}
if ($temperature['temp_precision']) { $temp = $temp / $temperature['temp_precision']; }
if ($temperature['sensor_precision']) { $temp = $temp / $temperature['sensor_precision']; }
$temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['temp_descr'] . ".rrd");
$temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['sensor_descr'] . ".rrd");
if (!is_file($temprrd)) {
`rrdtool create $temprrd \
@@ -34,16 +34,16 @@ while($temperature = mysql_fetch_array($temp_data)) {
rrdtool_update($temprrd,"N:$temp");
if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_limit']) {
if($temperature['sensor_current'] < $temperature['sensor_limit'] && $temp >= $temperature['sensor_limit']) {
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
$msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'] . " is " . $temp . " (Limit " . $temperature['temp_limit'];
$msg = "Temp Alarm: " . $device['hostname'] . " " . $temperature['sensor_descr'] . " is " . $temp . " (Limit " . $temperature['sensor_limit'];
$msg .= ") at " . date($config['timestamp_format']);
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "\n");
log_event('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['temp_limit'] . " <20>C)", $device['device_id'], 'temperature', $temperature['temp_id']);
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['sensor_descr'], $msg, $config['email_headers']);
echo("Alerting for " . $device['hostname'] . " " . $temperature['sensor_descr'] . "\n");
log_event('Temperature ' . $temperature['sensor_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['sensor_limit'] . " <20>C)", $device['device_id'], 'temperature', $temperature['sensor_id']);
}
mysql_query("UPDATE temperature SET temp_current = '$temp' WHERE temp_id = '" . $temperature['temp_id'] . "'");
mysql_query("UPDATE sensors SET sensor_current = '$temp' WHERE sensor_class='temperature' AND sensor_id = '" . $temperature['sensor_id'] . "'");
}
?>