2010-02-10 11:42:45 +00:00
|
|
|
<?php
|
|
|
|
|
2010-06-25 23:16:04 +00:00
|
|
|
$query = "SELECT * FROM sensors WHERE sensor_class='fanspeed' AND device_id = '" . $device['device_id'] . "'";
|
2010-02-10 11:42:45 +00:00
|
|
|
$fan_data = mysql_query($query);
|
|
|
|
while($fanspeed = mysql_fetch_array($fan_data)) {
|
|
|
|
|
2010-06-25 23:16:04 +00:00
|
|
|
echo("Checking fan " . $fanspeed['sensor_descr'] . "... ");
|
2010-02-10 11:42:45 +00:00
|
|
|
|
2010-07-05 21:55:56 +00:00
|
|
|
$fan = snmp_get($device, $fanspeed['sensor_oid'], "-OUqnv", "SNMPv2-MIB");
|
2010-07-02 19:58:13 +00:00
|
|
|
|
2010-06-25 23:16:04 +00:00
|
|
|
if ($fanspeed['sensor_precision']) { $fan = $fan / $fanspeed['sensor_precision']; }
|
2010-02-10 11:42:45 +00:00
|
|
|
|
2010-06-25 23:16:04 +00:00
|
|
|
$fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $fanspeed['sensor_descr'] . ".rrd");
|
2010-02-10 11:42:45 +00:00
|
|
|
|
|
|
|
if (!is_file($fanrrd)) {
|
2010-02-15 01:53:00 +00:00
|
|
|
`rrdtool create $fanrrd \
|
2010-02-10 11:42:45 +00:00
|
|
|
--step 300 \
|
2010-02-11 18:29:14 +00:00
|
|
|
DS:fan:GAUGE:600:0:20000 \
|
2010-02-10 11:42:45 +00:00
|
|
|
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($fan . " rpm\n");
|
|
|
|
|
|
|
|
rrdtool_update($fanrrd,"N:$fan");
|
|
|
|
|
2010-06-25 23:16:04 +00:00
|
|
|
if($fanspeed['sensor_current'] > $fanspeed['sensor_limit'] && $fan <= $fanspeed['sensor_limit']) {
|
2010-02-10 11:42:45 +00:00
|
|
|
if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
|
2010-06-25 23:16:04 +00:00
|
|
|
$msg = "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['sensor_descr'] . " is " . $fan . "rpm (Limit " . $fanspeed['sensor_limit'];
|
2010-02-25 20:40:35 +00:00
|
|
|
$msg .= "rpm) at " . date($config['timestamp_format']);
|
2010-07-11 19:11:46 +00:00
|
|
|
notify($device, "Fan Alarm: " . $device['hostname'] . " " . $fanspeed['sensor_descr'], $msg);
|
2010-06-25 23:16:04 +00:00
|
|
|
echo("Alerting for " . $device['hostname'] . " " . $fanspeed['sensor_descr'] . "\n");
|
|
|
|
log_event('Fan speed ' . $fanspeed['sensor_descr'] . " under threshold: " . $fanspeed['sensor_current'] . " rpm (> " . $fanspeed['sensor_limit'] . " rpm)", $device['device_id'], 'fanspeed', $fanspeed['sensor_id']);
|
2010-02-10 11:42:45 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 23:16:04 +00:00
|
|
|
mysql_query("UPDATE sensors SET sensor_current = '$fan' WHERE sensor_class='fanspeed' AND sensor_id = '" . $fanspeed['sensor_id'] . "'");
|
2010-02-10 11:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|