mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-12 16:06:25 +02:00
try 5 times to get a valid temperature, Papouch TME sometimes returns 999.9 - refactor temp polling code a little bit
git-svn-id: http://www.observium.org/svn/observer/trunk@728 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
@@ -4,11 +4,22 @@ $query = "SELECT * FROM temperature WHERE temp_host = '" . $device['device_id']
|
||||
$temp_data = mysql_query($query);
|
||||
while($temperature = mysql_fetch_array($temp_data)) {
|
||||
|
||||
$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 = shell_exec($temp_cmd);
|
||||
|
||||
echo("Checking temp " . $temperature['temp_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 = 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;
|
||||
}
|
||||
|
||||
$temprrd = addslashes($config['rrd_dir'] . "/" . $device['hostname'] . "/temp-" . str_replace("/", "_", str_replace(" ", "_",$temperature['temp_descr'])) . ".rrd");
|
||||
$temprrd = str_replace(")", "_", $temprrd);
|
||||
$temprrd = str_replace("(", "_", $temprrd);
|
||||
@@ -23,13 +34,6 @@ while($temperature = mysql_fetch_array($temp_data)) {
|
||||
RRA:AVERAGE:0.5:12:2400`;
|
||||
}
|
||||
|
||||
$temp = trim(str_replace("\"", "", $temp));
|
||||
if($temperature['temp_tenths']) { $temp = $temp / 10; }
|
||||
else
|
||||
{
|
||||
if ($temperature['temp_precision']) { $temp = $temp / $temperature['temp_precision']; }
|
||||
}
|
||||
|
||||
echo($temp . "C\n");
|
||||
|
||||
$updatecmd = "rrdtool update $temprrd N:$temp";
|
||||
|
||||
Reference in New Issue
Block a user