mirror of
https://github.com/librenms/librenms.git
synced 2024-09-22 10:58:42 +00:00
start of universal discover_sensor, change humidity to that one already, rest needs small rework
git-svn-id: http://www.observium.org/svn/observer/trunk@1313 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
parent
1ed4749f40
commit
6996cc2e24
@ -1,5 +1,41 @@
|
||||
<?php
|
||||
|
||||
function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL)
|
||||
{
|
||||
global $config, $debug;
|
||||
|
||||
if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); }
|
||||
if(!$low_limit)
|
||||
{
|
||||
$low_limit = $config['limit']['current'];
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='humidity' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) ";
|
||||
$query .= " VALUES ('" . mres($class) . "', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')";
|
||||
mysql_query($query);
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sensor_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='" . mres($class) . "' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
|
||||
if($oid == $sensor_entry['sensor_oid'] && $descr == $sensor_entry['sensor_descr'] && $precision == $sensor_entry['sensor_precision'])
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = '" . mres($class) . "' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index' ");
|
||||
echo("U");
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " updated"); }
|
||||
}
|
||||
}
|
||||
|
||||
$valid[$type][$index] = 1;
|
||||
return $return;
|
||||
}
|
||||
|
||||
function discover_juniAtmVp(&$valid, $interface_id, $vp_id, $vp_descr)
|
||||
{
|
||||
@ -296,39 +332,7 @@ function discover_freq(&$valid, $device, $oid, $index, $type, $descr, $precision
|
||||
|
||||
function discover_humidity(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $low_warn_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL)
|
||||
{
|
||||
global $config, $debug;
|
||||
|
||||
if($debug) { echo("$oid, $index, $type, $descr, $precision\n"); }
|
||||
if(!$low_limit)
|
||||
{
|
||||
$low_limit = $config['limit']['current'];
|
||||
}
|
||||
|
||||
if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='humidity' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0')
|
||||
{
|
||||
$query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_warn`, `sensor_limit_low`, `sensor_limit_low_warn`, `sensor_current`) ";
|
||||
$query .= " VALUES ('humidity', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_limit', '$low_limit', '$low_warn_limit', '$current')";
|
||||
mysql_query($query);
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); }
|
||||
echo("+");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sensor_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='humidity' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"));
|
||||
if($oid == $sensor_entry['sensor_oid'] && $descr == $sensor_entry['sensor_descr'] && $precision == $sensor_entry['sensor_precision'])
|
||||
{
|
||||
echo(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'humidity' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index' ");
|
||||
echo("U");
|
||||
if($debug) { echo("$query ". mysql_affected_rows() . " updated"); }
|
||||
}
|
||||
}
|
||||
|
||||
$valid[$type][$index] = 1;
|
||||
return $return;
|
||||
return discover_sensor($valid, 'humidity', $device, $oid, $index, $type, $descr, $precision, $low_limit, $low_warn_limit, $warn_limit, $high_limit, $current);
|
||||
}
|
||||
|
||||
function discover_current(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $warn_limit = NULL, $high_limit = NULL, $current = NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user