coding style on temp discovery

git-svn-id: http://www.observium.org/svn/observer/trunk@788 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
Tom Laermans
2010-02-08 00:43:19 +00:00
parent 88ec70ad14
commit 5d7eec48d3
+101 -48
View File
@@ -8,41 +8,50 @@
echo("Temperatures : "); echo("Temperatures : ");
## JunOS Temperatures ## JunOS Temperatures
if($device['os'] == "junos") { if ($device['os'] == "junos")
{
echo("JunOS "); echo("JunOS ");
$oids = shell_exec($config['snmpwalk'] . " -m JUNIPER-MIB -$snmpver -CI -Osqn -c $community $hostname:$port 1.3.6.1.4.1.2636.3.1.13.1.7"); $oids = shell_exec($config['snmpwalk'] . " -m JUNIPER-MIB -$snmpver -CI -Osqn -c $community $hostname:$port 1.3.6.1.4.1.2636.3.1.13.1.7");
$oids = trim($oids); $oids = trim($oids);
foreach(explode("\n", $oids) as $data) { foreach(explode("\n", $oids) as $data)
{
$data = trim($data); $data = trim($data);
$data = substr($data, 29); $data = substr($data, 29);
if($data) { if ($data)
{
list($oid) = explode(" ", $data); list($oid) = explode(" ", $data);
$temp_oid = "1.3.6.1.4.1.2636.3.1.13.1.7.$oid"; $temp_oid = "1.3.6.1.4.1.2636.3.1.13.1.7.$oid";
$descr_oid = "1.3.6.1.4.1.2636.3.1.13.1.5.$oid"; $descr_oid = "1.3.6.1.4.1.2636.3.1.13.1.5.$oid";
$descr = trim(shell_exec($config['snmpget'] . " -m JUNIPER-MIB -O qv -$snmpver -c $community $hostname:$port $descr_oid")); $descr = trim(shell_exec($config['snmpget'] . " -m JUNIPER-MIB -O qv -$snmpver -c $community $hostname:$port $descr_oid"));
$temp = trim(shell_exec($config['snmpget'] . " -m JUNIPER-MIB -O qv -$snmpver -c $community $hostname:$port $temp_oid")); $temp = trim(shell_exec($config['snmpget'] . " -m JUNIPER-MIB -O qv -$snmpver -c $community $hostname:$port $temp_oid"));
if(!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" && $temp != "0") { if (!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" && $temp != "0")
{
$descr = str_replace("\"", "", $descr); $descr = str_replace("\"", "", $descr);
$descr = str_replace("temperature", "", $descr); $descr = str_replace("temperature", "", $descr);
$descr = str_replace("temp", "", $descr); $descr = str_replace("temp", "", $descr);
$descr = str_replace("sensor", "", $descr); $descr = str_replace("sensor", "", $descr);
$descr = trim($descr); $descr = trim($descr);
if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0') { if (mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0')
{
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr'," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')"; $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr'," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')";
mysql_query($query); mysql_query($query);
echo("+"); echo("+");
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"), 0) != $descr) { } elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"), 0) != $descr) {
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"); mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'");
echo("U"); echo("U");
} else { echo("."); } } else {
echo(".");
}
$temp_exists[] = "$id $temp_oid"; $temp_exists[] = "$id $temp_oid";
} }
} }
} }
} }
## Papouch TME Temperatures ## Papouch TME Temperatures
if($device['os'] == "papouch-tme") { if ($device['os'] == "papouch-tme")
{
echo("Papouch TME "); echo("Papouch TME ");
$descr = trim(shell_exec($config['snmpget'] . " -O qv -$snmpver -c $community $hostname:$port SNMPv2-SMI::enterprises.18248.1.1.3.0")); $descr = trim(shell_exec($config['snmpget'] . " -O qv -$snmpver -c $community $hostname:$port SNMPv2-SMI::enterprises.18248.1.1.3.0"));
$temp = trim(shell_exec($config['snmpget'] . " -O qv -$snmpver -c $community $hostname:$port SNMPv2-SMI::enterprises.18248.1.1.1.0")) / 10; $temp = trim(shell_exec($config['snmpget'] . " -O qv -$snmpver -c $community $hostname:$port SNMPv2-SMI::enterprises.18248.1.1.1.0")) / 10;
@@ -55,7 +64,8 @@
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr',10," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')"; $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr',10," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')";
mysql_query($query); mysql_query($query);
echo("+"); echo("+");
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"), 0) != $descr) { } elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"), 0) != $descr)
{
echo("U"); echo("U");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"); mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'");
} else { } else {
@@ -65,67 +75,86 @@
} }
} }
## Begin Observer-Style ## Observer-Style Temperatures
if($device['os'] == "linux") { if ($device['os'] == "linux")
{
$oids = shell_exec($config['snmpwalk'] . " -$snmpver -m SNMPv2-SMI -Osqn -CI -c $community $hostname:$port .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep '.1.1 ' | grep -v '.101.' | cut -d'.' -f 1"); $oids = shell_exec($config['snmpwalk'] . " -$snmpver -m SNMPv2-SMI -Osqn -CI -c $community $hostname:$port .1.3.6.1.4.1.2021.7891 | sed s/.1.3.6.1.4.1.2021.7891.// | grep '.1.1 ' | grep -v '.101.' | cut -d'.' -f 1");
$oids = trim($oids); $oids = trim($oids);
if ($oids) echo("Observer-Style "); if ($oids) echo("Observer-Style ");
foreach(explode("\n",$oids) as $oid) { foreach(explode("\n",$oids) as $oid)
{
$oid = trim($oid); $oid = trim($oid);
if($oid != "") { if ($oid != "")
{
$descr_query = $config['snmpget'] . " -$snmpver -m SNMPv2-SMI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //"; $descr_query = $config['snmpget'] . " -$snmpver -m SNMPv2-SMI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.2021.7891.$oid.2.1 | sed s/.1.3.6.1.4.1.2021.7891.$oid.2.1\ //";
$descr = trim(str_replace("\"", "", shell_exec($descr_query))); $descr = trim(str_replace("\"", "", shell_exec($descr_query)));
$fulloid = ".1.3.6.1.4.1.2021.7891.$oid.101.1"; $fulloid = ".1.3.6.1.4.1.2021.7891.$oid.101.1";
if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) { if (!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0))
{
echo("+"); echo("+");
mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`,`temp_limit`) VALUES ('$id', '$fulloid', '$descr'," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ")"); mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`,`temp_limit`) VALUES ('$id', '$fulloid', '$descr'," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ")");
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) { }
elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr)
{
echo("U"); echo("U");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"); mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
} else { }
else
{
echo("."); echo(".");
} }
$temp_exists[] = "$id $fulloid"; $temp_exists[] = "$id $fulloid";
} }
} }
} ## End Observer-Style }
## Dell Temperatures ## Dell Temperatures
if(strstr($device['hardware'], "dell")) { if (strstr($device['hardware'], "dell"))
{
$oids = shell_exec($config['snmpwalk'] . " -m MIB-Dell-10892 -$snmpver -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.674.10892.1.700.20.1.8"); $oids = shell_exec($config['snmpwalk'] . " -m MIB-Dell-10892 -$snmpver -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.674.10892.1.700.20.1.8");
$oids = trim($oids); $oids = trim($oids);
if ($oids) echo("Dell OMSA "); if ($oids) echo("Dell OMSA ");
foreach(explode("\n",$oids) as $oid) { foreach(explode("\n",$oids) as $oid)
{
$oid = substr(trim($oid), 36); $oid = substr(trim($oid), 36);
list($oid) = explode(" ", $oid); list($oid) = explode(" ", $oid);
if($oid != "") { if ($oid != "")
{
$descr_query = $config['snmpget'] . " -m MIB-Dell-10892 -$snmpver -Onvq -c $community $hostname:$port .1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid"; $descr_query = $config['snmpget'] . " -m MIB-Dell-10892 -$snmpver -Onvq -c $community $hostname:$port .1.3.6.1.4.1.674.10892.1.700.20.1.8.$oid";
$descr = trim(str_replace("\"", "", shell_exec($descr_query))); $descr = trim(str_replace("\"", "", shell_exec($descr_query)));
$fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid"; $fulloid = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.$oid";
if(!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0)) { if (!mysql_result(mysql_query("SELECT count(temp_id) FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0))
{
mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`, `temp_precision`, `temp_limit`) VALUES ('$id', '$fulloid', '$descr', '10', " . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ")"); mysql_query("INSERT INTO `temperature` (`temp_host`,`temp_oid`,`temp_descr`, `temp_precision`, `temp_limit`) VALUES ('$id', '$fulloid', '$descr', '10', " . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ")");
echo("+"); echo("+");
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr) { }
elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"), 0) != $descr)
{
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"); mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
echo("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'"); echo("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$fulloid'");
echo("U"); echo("U");
} else { }
else
{
echo("."); echo(".");
} }
$temp_exists[] = "$id $fulloid"; $temp_exists[] = "$id $fulloid";
} }
} }
} ## End Dell Sensors }
## LMSensors Temperatures ## LMSensors Temperatures
if($device['os'] == "linux") { if ($device['os'] == "linux")
{
$oids = shell_exec($config['snmpwalk'] . " -m LM-SENSORS-MIB -$snmpver -CI -Osqn -c $community $hostname:$port lmTempSensorsDevice"); $oids = shell_exec($config['snmpwalk'] . " -m LM-SENSORS-MIB -$snmpver -CI -Osqn -c $community $hostname:$port lmTempSensorsDevice");
if ($debug) { echo($oids."\n"); } if ($debug) { echo($oids."\n"); }
$oids = trim($oids); $oids = trim($oids);
if ($oids) echo("LM-SENSORS "); if ($oids) echo("LM-SENSORS ");
foreach(explode("\n", $oids) as $data) { foreach(explode("\n", $oids) as $data)
{
$data = trim($data); $data = trim($data);
if($data) { if ($data)
{
list($oid,$descr) = explode(" ", $data,2); list($oid,$descr) = explode(" ", $data,2);
if (substr($descr,0,5) == "temp-") if (substr($descr,0,5) == "temp-")
{ {
@@ -135,30 +164,38 @@
$temp = trim(shell_exec($config['snmpget'] . " -m LM-SENSORS-MIB -O qv -$snmpver -c $community $hostname:$port $temp_oid")) / 1000; $temp = trim(shell_exec($config['snmpget'] . " -m LM-SENSORS-MIB -O qv -$snmpver -c $community $hostname:$port $temp_oid")) / 1000;
$descr = str_ireplace("temp-", "", $descr); $descr = str_ireplace("temp-", "", $descr);
$descr = trim($descr); $descr = trim($descr);
if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0') { if (mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0')
{
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr',1000, " . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')"; $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr',1000, " . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')";
mysql_query($query); mysql_query($query);
echo("+"); echo("+");
} elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"), 0) != $descr) { }
elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"), 0) != $descr)
{
echo("U"); echo("U");
mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'"); mysql_query("UPDATE temperature SET `temp_descr` = '$descr' WHERE `temp_host` = '$id' AND `temp_oid` = '$temp_oid'");
} else { }
else
{
echo("."); echo(".");
} }
$temp_exists[] = "$id $temp_oid"; $temp_exists[] = "$id $temp_oid";
} }
} }
} }
} ## End LMSensors Temperatures }
## Supermicro Temperatures ## Supermicro Temperatures
if($device['os'] == "linux") { if ($device['os'] == "linux")
{
$oids = shell_exec($config['snmpwalk'] . " -m SUPERMICRO-HEALTH-MIB -$snmpver -CI -Osqn -c $community $hostname:$port 1.3.6.1.4.1.10876.2.1.1.1.1.3 | sed s/1.3.6.1.4.1.10876.2.1.1.1.1.3.//g"); $oids = shell_exec($config['snmpwalk'] . " -m SUPERMICRO-HEALTH-MIB -$snmpver -CI -Osqn -c $community $hostname:$port 1.3.6.1.4.1.10876.2.1.1.1.1.3 | sed s/1.3.6.1.4.1.10876.2.1.1.1.1.3.//g");
$oids = trim($oids); $oids = trim($oids);
if ($oids) echo("Supermicro "); if ($oids) echo("Supermicro ");
foreach(explode("\n", $oids) as $data) { foreach(explode("\n", $oids) as $data)
{
$data = trim($data); $data = trim($data);
if($data) { if ($data)
{
list($oid,$type) = explode(" ", $data); list($oid,$type) = explode(" ", $data);
if ($type == 2) if ($type == 2)
{ {
@@ -170,61 +207,78 @@
$limit = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $limit_oid")); $limit = trim(shell_exec($config['snmpget'] . " -m SUPERMICRO-HEALTH-MIB -O qv -$snmpver -c $community $hostname:$port $limit_oid"));
$descr = str_ireplace("temperature", "", $descr); $descr = str_ireplace("temperature", "", $descr);
$descr = trim($descr); $descr = trim($descr);
if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0') { if (mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0')
{
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_current`, `temp_limit`) values ('$id', '$temp_oid', '$descr', '$temp', '$limit')"; $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_current`, `temp_limit`) values ('$id', '$temp_oid', '$descr', '$temp', '$limit')";
mysql_query($query); mysql_query($query);
echo("+"); echo("+");
} else { echo("."); } }
else
{
echo(".");
}
$temp_exists[] = "$id $temp_oid"; $temp_exists[] = "$id $temp_oid";
} }
} }
} }
} ## End Supermicro Temperatures }
## Cisco Temperatures ## Cisco Temperatures
if($device['os'] == "ios") { if ($device['os'] == "ios")
{
echo("Cisco "); echo("Cisco ");
$oids = shell_exec($config['snmpwalk'] . " -m CISCO-ENVMON-MIB -$snmpver -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g"); $oids = shell_exec($config['snmpwalk'] . " -m CISCO-ENVMON-MIB -$snmpver -CI -Osqn -c $community $hostname:$port .1.3.6.1.4.1.9.9.13.1.3.1.2 | sed s/.1.3.6.1.4.1.9.9.13.1.3.1.2.//g");
$oids = trim($oids); $oids = trim($oids);
foreach(explode("\n", $oids) as $data) { foreach(explode("\n", $oids) as $data)
{
$data = trim($data); $data = trim($data);
if($data) { if ($data)
{
list($oid) = explode(" ", $data); list($oid) = explode(" ", $data);
$temp_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.3.$oid"; $temp_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.3.$oid";
$descr_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.2.$oid"; $descr_oid = ".1.3.6.1.4.1.9.9.13.1.3.1.2.$oid";
$descr = trim(shell_exec($config['snmpget'] . " -m CISCO-ENVMON-MIB -O qv -$snmpver -c $community $hostname:$port $descr_oid")); $descr = trim(shell_exec($config['snmpget'] . " -m CISCO-ENVMON-MIB -O qv -$snmpver -c $community $hostname:$port $descr_oid"));
$temp = trim(shell_exec($config['snmpget'] . " -m CISCO-ENVMON-MIB -O qv -$snmpver -c $community $hostname:$port $temp_oid")); $temp = trim(shell_exec($config['snmpget'] . " -m CISCO-ENVMON-MIB -O qv -$snmpver -c $community $hostname:$port $temp_oid"));
if(!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" ) { if (!strstr($descr, "No") && !strstr($temp, "No") && $descr != "" )
{
$descr = str_replace("\"", "", $descr); $descr = str_replace("\"", "", $descr);
$descr = str_replace("temperature", "", $descr); $descr = str_replace("temperature", "", $descr);
$descr = str_replace("temp", "", $descr); $descr = str_replace("temp", "", $descr);
$descr = trim($descr); $descr = trim($descr);
if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0') { if (mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$temp_oid' AND temp_host = '$id'"),0) == '0')
{
$query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr', " . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')"; $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_limit`, `temp_current`) values ('$id', '$temp_oid', '$descr', " . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp')";
mysql_query($query); mysql_query($query);
echo("+"); echo("+");
} else { echo("."); } }
else
{
echo(".");
}
$temp_exists[] = "$id $temp_oid"; $temp_exists[] = "$id $temp_oid";
} }
} }
} }
} ## End Cisco Temperatures }
## Delete removed sensors ## Delete removed sensors
$sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.device_id = '".$device['device_id']."'"; $sql = "SELECT * FROM temperature AS T, devices AS D WHERE T.temp_host = D.device_id AND D.device_id = '".$device['device_id']."'";
$query = mysql_query($sql); $query = mysql_query($sql);
while ($sensor = mysql_fetch_array($query)) { while ($sensor = mysql_fetch_array($query))
{
unset($exists); unset($exists);
$i = 0; $i = 0;
while ($i < count($temp_exists) && !$exists) { while ($i < count($temp_exists) && !$exists)
{
$thistemp = $sensor['temp_host'] . " " . $sensor['temp_oid']; $thistemp = $sensor['temp_host'] . " " . $sensor['temp_oid'];
if ($temp_exists[$i] == $thistemp) { $exists = 1; } if ($temp_exists[$i] == $thistemp) { $exists = 1; }
$i++; $i++;
} }
if(!$exists) {
if (!$exists)
{
echo("-"); echo("-");
mysql_query("DELETE FROM temperature WHERE temp_id = '" . $sensor['temp_id'] . "'"); mysql_query("DELETE FROM temperature WHERE temp_id = '" . $sensor['temp_id'] . "'");
} }
@@ -232,5 +286,4 @@ while ($sensor = mysql_fetch_array($query)) {
unset($temp_exists); echo("\n"); unset($temp_exists); echo("\n");
?> ?>