2009-09-07 11:07:59 +00:00
|
|
|
<?php
|
2007-04-08 12:23:31 +00:00
|
|
|
|
2007-04-08 14:34:19 +00:00
|
|
|
$query = "SELECT * FROM temperature WHERE temp_host = '" . $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-01-26 11:33:12 +00:00
|
|
|
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 = trim(str_replace("\"", "", shell_exec($temp_cmd)));
|
|
|
|
if($temperature['temp_tenths']) { $temp = $temp / 10; }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($temperature['temp_precision']) { $temp = $temp / $temperature['temp_precision']; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($temp != 999.9) break; # TME sometimes sends 999.9 when it is right in the middle of an update;
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:32:25 +00:00
|
|
|
$temprrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
|
2007-06-06 09:23:41 +00:00
|
|
|
$temprrd = str_replace(")", "_", $temprrd);
|
|
|
|
$temprrd = str_replace("(", "_", $temprrd);
|
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
|
|
|
|
2007-11-23 11:37:28 +00:00
|
|
|
$updatecmd = "rrdtool update $temprrd N:$temp";
|
2007-04-08 12:23:31 +00:00
|
|
|
|
2009-04-24 15:04:45 +00:00
|
|
|
shell_exec($updatecmd);
|
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']) {
|
|
|
|
$updated = ", `service_changed` = '" . time() . "' ";
|
|
|
|
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 .= ") at " . date('l dS F Y h:i:s A');
|
|
|
|
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-01-26 15:41:45 +00:00
|
|
|
eventlog('Temperature ' . $temperature['temp_descr'] . " over threshold: " . $temperature['temp_current'] . " °C (> " . $temperature['temp_limit'] . " °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
|
|
|
}
|
|
|
|
|
|
|
|
?>
|