From f63483a2afe1a492c01ff5cdea192a2ed689b08d Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Tue, 26 Jan 2010 11:33:12 +0000 Subject: [PATCH] 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 --- includes/polling/temperatures.inc.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index f8d060df0..bfe666b4d 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -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";