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
+6 -7
View File
@@ -143,25 +143,24 @@ function discover_temperature(&$valid, $device, $oid, $index, $type, $descr, $pr
global $config, $debug;
if($debug) { echo("$oid, $index, $type, $descr, $precision, $current\n"); }
if (mysql_result(mysql_query("SELECT COUNT(temp_id) FROM `temperature` WHERE temp_type = '$type' AND temp_index = '$index' AND device_id = '".$device['device_id']."'"),0) == '0')
if (mysql_result(mysql_query("SELECT COUNT(sensor_id) FROM `sensors` WHERE sensor_class='temperature' AND sensor_type = '$type' AND sensor_index = '$index' AND device_id = '".$device['device_id']."'"),0) == '0')
{
$query = "INSERT INTO temperature (`device_id`, `temp_type`,`temp_index`,`temp_oid`, `temp_descr`, `temp_limit`, `temp_current`, `temp_precision`)";
$query .= " values ('".$device['device_id']."', '$type','$index','$oid', '$descr','" . ($high_limit ? $high_limit : $config['defaults']['temp_limit']) . "', '$current', '$precision')";
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_type`,`sensor_index`,`sensor_oid`, `sensor_descr`, `sensor_limit`, `sensor_current`, `sensor_precision`)";
$query .= " values ('temperature','".$device['device_id']."', '$type','$index','$oid', '$descr','" . ($high_limit ? $high_limit : $config['defaults']['sensor_limit']) . "', '$current', '$precision')";
mysql_query($query);
echo("+");
}
else
{
$entry = mysql_fetch_array(mysql_query("SELECT * FROM `temperature` WHERE device_id = '".$device['device_id']."' AND `temp_type` = '$type' AND `temp_index` = '$index'"));
$entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='temperature' AND device_id = '".$device['device_id']."' AND `sensor_type` = '$type' AND `sensor_index` = '$index'"));
echo(mysql_error());
if($oid == $entry['temp_oid'] && $descr == $entry['temp_descr'] && $precision == $entry['temp_precision'])
if($oid == $entry['sensor_oid'] && $descr == $entry['sensor_descr'] && $precision == $entry['sensor_precision'])
{
echo(".");
}
else
{
mysql_query("UPDATE temperature SET `temp_descr` = '$descr', `temp_oid` = '$oid', `temp_precision` = '$precision' WHERE `temp_id` = '".$entry['temp_id']."'");
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE sensor_class` = 'temperature' AND`sensor_id` = '".$entry['sensor_id']."'");
echo("U");
}
}
+4 -4
View File
@@ -310,18 +310,18 @@ if (strstr($device['hardware'], "dell"))
if($debug) { print_r($valid_temp); }
$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
$sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='temperature' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'";
if ($query = mysql_query($sql))
{
while ($test_temperature = mysql_fetch_array($query))
{
$temperature_index = $test_temperature['temp_index'];
$temperature_type = $test_temperature['temp_type'];
$temperature_index = $test_temperature['sensor_index'];
$temperature_type = $test_temperature['sensor_type'];
if($debug) { echo($temperature_index . " -> " . $temperature_type . "\n"); }
if(!$valid_temp[$temperature_type][$temperature_index])
{
echo("-");
mysql_query("DELETE FROM `temperature` WHERE temp_id = '" . $test_temperature['temp_id'] . "'");
mysql_query("DELETE FROM `sensors` WHERE sensor_class='temperature' AND sensor_id = '" . $test_temperature['sensor_id'] . "'");
}
unset($temperature_oid); unset($temperature_type);
}
+1 -1
View File
@@ -290,7 +290,6 @@ function delete_device($id)
mysql_query("DELETE FROM `devices_attribs` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `devices_perms` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `bgpPeers` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `temperature` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `vlans` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `vrfs` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `storage` WHERE `device_id` = '$id'");
@@ -305,6 +304,7 @@ function delete_device($id)
mysql_query("DELETE FROM `toner` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `frequency` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `current` WHERE `device_id` = '$id'");
mysql_query("DELETE FROM `sensors` WHERE `device_id` = '$id'");
shell_exec("rm -rf ".$config['rrd_dir']."/$host");
return $ret . "Removed device $host\n";
}
+11 -11
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 . " °C (> " . $temperature['temp_limit'] . " °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 . " °C (> " . $temperature['sensor_limit'] . " °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'] . "'");
}
?>