2009-09-07 11:07:59 +00:00
|
|
|
|
<?php
|
2007-04-08 12:23:31 +00:00
|
|
|
|
|
2010-02-13 07:40:43 +00:00
|
|
|
|
$query = "SELECT * FROM temperature WHERE device_id = '" . $device['device_id'] . "'";
|
2007-04-08 12:23:31 +00:00
|
|
|
|
$temp_data = mysql_query($query);
|
|
|
|
|
while($temperature = mysql_fetch_array($temp_data)) {
|
|
|
|
|
|
2007-11-23 11:37:28 +00:00
|
|
|
|
echo("Checking temp " . $temperature['temp_descr'] . "... ");
|
|
|
|
|
|
2010-02-21 10:30:23 +00:00
|
|
|
|
for ($i = 0;$i < 5;$i++) # Try 5 times to get a valid temp reading
|
2010-01-26 11:33:12 +00:00
|
|
|
|
{
|
|
|
|
|
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 = trim(str_replace("\"", "", shell_exec($temp_cmd)));
|
|
|
|
|
|
2010-02-10 12:03:12 +00:00
|
|
|
|
if ($temp != 9999) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
|
2010-02-21 10:30:23 +00:00
|
|
|
|
sleep(1); # Give the TME some time to reset
|
2010-01-26 11:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-21 14:46:22 +00:00
|
|
|
|
if ($temperature['temp_precision']) { $temp = $temp / $temperature['temp_precision']; }
|
2010-02-10 12:03:12 +00:00
|
|
|
|
|
2010-02-05 22:10:06 +00:00
|
|
|
|
$temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['temp_descr'] . ".rrd");
|
2007-05-20 19:21:35 +00:00
|
|
|
|
|
2007-04-08 12:23:31 +00:00
|
|
|
|
if (!is_file($temprrd)) {
|
|
|
|
|
`rrdtool create $temprrd \
|
|
|
|
|
--step 300 \
|
|
|
|
|
DS:temp: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`;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-23 11:37:28 +00:00
|
|
|
|
echo($temp . "C\n");
|
2007-06-06 09:23:41 +00:00
|
|
|
|
|
2010-02-07 22:39:02 +00:00
|
|
|
|
rrdtool_update($temprrd,"N:$temp");
|
2007-04-08 12:23:31 +00:00
|
|
|
|
|
2007-11-23 11:37:28 +00:00
|
|
|
|
if($temperature['temp_current'] < $temperature['temp_limit'] && $temp >= $temperature['temp_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'];
|
2010-02-25 20:40:35 +00:00
|
|
|
|
$msg .= ") at " . date($config['timestamp_format']);
|
2007-11-23 11:37:28 +00:00
|
|
|
|
mail($email, "Temp Alarm: " . $device['hostname'] . " " . $temperature['temp_descr'], $msg, $config['email_headers']);
|
2010-01-09 00:50:29 +00:00
|
|
|
|
echo("Alerting for " . $device['hostname'] . " " . $temperature['temp_descr'] . "\n");
|
2010-06-10 19:51:49 +00:00
|
|
|
|
eventlog('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temp . " <20>C (> " . $temperature['temp_limit'] . " <20>C)", $device['device_id']);
|
2007-11-23 11:37:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 17:27:29 +00:00
|
|
|
|
mysql_query("UPDATE temperature SET temp_current = '$temp' WHERE temp_id = '" . $temperature['temp_id'] . "'");
|
2007-04-08 12:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
?>
|