From 4f2972660f916b1f7dcd87f8abaeb26f0853e8ad Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Thu, 29 Jul 2010 18:25:11 +0000 Subject: [PATCH] retooled sensors discovery. use global $valid_sensor, use sensors table only, replace sensor_precision with sensor_multiplier and sensor_divisor, remove all old discover_* functions and replace with discover_sensor git-svn-id: http://www.observium.org/svn/observer/trunk@1529 61d68cd4-352d-0410-923a-c4978735b2b8 --- database-update.sql | 7 +- discovery.php | 13 +- includes/discovery/current.inc.php | 58 ++--- includes/discovery/fanspeeds.inc.php | 24 +- includes/discovery/fanspeeds/areca.inc.php | 6 +- .../discovery/fanspeeds/lmsensors.inc.php | 8 +- .../discovery/fanspeeds/supermicro.inc.php | 14 +- includes/discovery/frequencies.inc.php | 65 ++--- includes/discovery/functions.inc.php | 239 +++--------------- includes/discovery/humidity.inc.php | 23 +- includes/discovery/humidity/akcp.inc.php | 22 +- includes/discovery/mempools/cemp.inc.php | 2 + includes/discovery/mempools/cmp.inc.php | 2 + includes/discovery/mempools/hrstorage.inc.php | 2 + .../discovery/mempools/ironware-dyn.inc.php | 2 + includes/discovery/mempools/junos.inc.php | 2 + includes/discovery/mempools/screenos.inc.php | 2 + includes/discovery/temperatures.inc.php | 23 +- includes/discovery/temperatures/adva.inc.php | 56 ++-- includes/discovery/temperatures/akcp.inc.php | 30 +-- includes/discovery/temperatures/apc.inc.php | 6 +- includes/discovery/temperatures/areca.inc.php | 18 +- .../temperatures/cisco-entity-sensor.inc.php | 11 +- .../temperatures/cisco-envmon.inc.php | 12 +- includes/discovery/temperatures/dell.inc.php | 7 +- .../temperatures/entity-sensor.inc.php | 12 +- .../temperatures/ftos-c-series.inc.php | 10 +- .../temperatures/ftos-e-series.inc.php | 8 +- .../temperatures/ftos-s-series.inc.php | 8 +- .../discovery/temperatures/ironware.inc.php | 12 +- includes/discovery/temperatures/junos.inc.php | 15 +- .../discovery/temperatures/junose.inc.php | 7 +- .../discovery/temperatures/lm-sensors.inc.php | 14 +- .../discovery/temperatures/netmanplus.inc.php | 14 +- .../temperatures/observernms-custom.inc.php | 6 +- .../temperatures/papouch-tme.inc.php | 12 +- .../temperatures/powerconnect.inc.php | 11 +- .../discovery/temperatures/supermicro.inc.php | 8 +- .../discovery/temperatures/zyxel-ies.inc.php | 7 +- includes/discovery/voltages.inc.php | 106 +++----- includes/polling/current.inc.php | 7 +- includes/polling/fanspeeds.inc.php | 4 +- includes/polling/humidity.inc.php | 7 +- includes/polling/temperatures.inc.php | 3 +- includes/polling/voltages.inc.php | 6 +- 45 files changed, 314 insertions(+), 617 deletions(-) diff --git a/database-update.sql b/database-update.sql index 97b42eae77..5981ce2160 100644 --- a/database-update.sql +++ b/database-update.sql @@ -41,10 +41,11 @@ CREATE TABLE IF NOT EXISTS `ports_adsl` ( `interface_id` int(11) NOT NULL, `po ALTER TABLE `devices` ADD `last_polled_timetaken` DOUBLE( 5, 2 ) NOT NULL AFTER `last_polled` , ADD `last_discovered_timetaken` DOUBLE( 5, 2 ) NOT NULL AFTER `last_polled_timetaken`; CREATE TABLE IF NOT EXISTS `perf_times` ( `type` varchar(8) NOT NULL, `doing` varchar(64) NOT NULL, `start` int(11) NOT NULL, `duration` double(5,2) NOT NULL, `devices` int(11) NOT NULL, KEY `type` (`type`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; ## 0.10.7.1 -ALTER TABLE `bills` ADD `bill_autoadded` BOOLEAN NOT NULL DEFAULT '0' -ALTER TABLE `bill_ports` ADD `bill_port_autoadded` BOOLEAN NOT NULL DEFAULT '0' +ALTER TABLE `bills` ADD `bill_autoadded` BOOLEAN NOT NULL DEFAULT '0'; +ALTER TABLE `bill_ports` ADD `bill_port_autoadded` BOOLEAN NOT NULL DEFAULT '0'; +ALTER TABLE `sensors` CHANGE `sensor_precision` `sensor_divisor` INT( 11 ) NOT NULL DEFAULT '1' +ALTER TABLE `sensors` ADD `sensor_multiplier` INT( 11 ) NOT NULL AFTER `sensor_divisor`; CREATE TABLE IF NOT EXISTS `device_graphs` ( `device_id` int(11) NOT NULL, `graph` varchar(32) COLLATE utf8_unicode_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; DROP TABLE IF EXISTS `graph_types`; CREATE TABLE IF NOT EXISTS `graph_types` ( `graph_type` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `graph_subtype` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `graph_section` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `graph_descr` varchar(64) COLLATE utf8_unicode_ci NOT NULL, `graph_order` int(11) NOT NULL, KEY `graph_type` (`graph_type`), KEY `graph_subtype` (`graph_subtype`), KEY `graph_section` (`graph_section`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; INSERT INTO `graph_types` (`graph_type`, `graph_subtype`, `graph_section`, `graph_descr`, `graph_order`) VALUES('device', 'bits', 'netstats', 'Total Traffic', 0),('device', 'hr_users', 'system', 'Users Logged In', 0),('device', 'ucd_load', 'system', 'Load Averages', 0),('device', 'ucd_cpu', 'system', 'Detailed Processor Usage', 0),('device', 'ucd_memory', 'system', 'Detailed Memory Usage', 0),('device', 'netstat_tcp', 'netstats', 'TCP Statistics', 0),('device', 'netstat_icmp_info', 'netstats', 'ICMP Informational Statistics', 0),('device', 'netstat_icmp_stat', 'netstats', 'ICMP Statistics', 0),('device', 'netstat_ip', 'netstats', 'IP Statistics', 0),('device', 'netstat_ip_frag', 'netstats', 'IP Fragmentation Statistics', 0),('device', 'netstat_udp', 'netstats', 'UDP Statistics', 0),('device', 'netstat_snmp', 'netstats', 'SNMP Statistics', 0),('device', 'temperatures', 'system', 'Temperatures', 0),('device', 'mempools', 'system', 'Memory Pool Usage', 0),('device', 'processors', 'system', 'Processor Usage', 0),('device', 'storage', 'system', 'Filesystem Usage', 0),('device', 'hr_processes', 'system', 'Running Processes', 0),('device', 'uptime', 'system', 'System Uptime', ''),('device', 'ipsystemstats_ipv4', 'netstats', 'IPv4 Packet Statistics', 0),('device', 'ipsystemstats_ipv6_frag', 'netstats', 'IPv6 Fragmentation Statistics', 0),('device', 'ipsystemstats_ipv6', 'netstats', 'IPv6 Packet Statistics', 0),('device', 'ipsystemstats_ipv4_frag', 'netstats', 'IPv4 Fragmentation Statistics', 0),('device', 'fortigate_sessions', 'firewall', 'Active Sessions', ''), ('device', 'screenos_settings', 'firewall', 'Active Sessions', ''); - diff --git a/discovery.php b/discovery.php index b83401aaf8..0195142757 100755 --- a/discovery.php +++ b/discovery.php @@ -114,12 +114,13 @@ while ($device = mysql_fetch_array($device_query)) include("includes/discovery/mempools.inc.php"); include("includes/discovery/ipv4-addresses.inc.php"); include("includes/discovery/ipv6-addresses.inc.php"); - include("includes/discovery/temperatures.inc.php"); - include("includes/discovery/humidity.inc.php"); - include("includes/discovery/voltages.inc.php"); - include("includes/discovery/frequencies.inc.php"); - include("includes/discovery/current.inc.php"); - include("includes/discovery/fanspeeds.inc.php"); +# include("includes/discovery/temperatures.inc.php"); +# include("includes/discovery/humidity.inc.php"); +# include("includes/discovery/voltages.inc.php"); +# include("includes/discovery/frequencies.inc.php"); +# include("includes/discovery/current.inc.php"); +# include("includes/discovery/fanspeeds.inc.php"); + include("includes/discovery/sensors.inc.php"); include("includes/discovery/storage.inc.php"); include("includes/discovery/hr-device.inc.php"); include("includes/discovery/discovery-protocols.inc.php"); diff --git a/includes/discovery/current.inc.php b/includes/discovery/current.inc.php index 41de5ec9a2..cda5fc03b0 100644 --- a/includes/discovery/current.inc.php +++ b/includes/discovery/current.inc.php @@ -1,12 +1,4 @@ $index\n"); } - if(!$valid_current[$type][$index]) { - echo("-"); - mysql_query("DELETE FROM `current` WHERE current_id = '" . $test_current['current_id'] . "'"); - } - } -} - -unset($valid_current); echo("\n"); +echo("\n"); ?> diff --git a/includes/discovery/fanspeeds.inc.php b/includes/discovery/fanspeeds.inc.php index 4dade209bc..7ad96737f4 100644 --- a/includes/discovery/fanspeeds.inc.php +++ b/includes/discovery/fanspeeds.inc.php @@ -1,30 +1,12 @@ $fan_index\n"); } - if(!$valid_fan[$fan_type][$fan_index]) { - echo("-"); - mysql_query("DELETE FROM `fanspeed` WHERE sensor_id = '" . $test_fan['sensor_id'] . "'"); - } - } -} - -unset($valid_fan); echo("\n"); +echo("\n"); ?> diff --git a/includes/discovery/fanspeeds/areca.inc.php b/includes/discovery/fanspeeds/areca.inc.php index 29bc8ad5b3..617a1243ad 100644 --- a/includes/discovery/fanspeeds/areca.inc.php +++ b/includes/discovery/fanspeeds/areca.inc.php @@ -1,6 +1,6 @@ '0' && $current < '500') { - discover_fan($valid_fan,$device, $oid, $index, $type, $descr, $precision, NULL, NULL, $current); + discover_sensor($valid_sensor, 'fanspeed', $device, $oid, $index, 'lmsensors', $descr, '1', '1', NULL, NULL, NULL, NULL, $current); } } } } -?> \ No newline at end of file +?> diff --git a/includes/discovery/fanspeeds/supermicro.inc.php b/includes/discovery/fanspeeds/supermicro.inc.php index 95bb00f9da..4efa048628 100644 --- a/includes/discovery/fanspeeds/supermicro.inc.php +++ b/includes/discovery/fanspeeds/supermicro.inc.php @@ -1,6 +1,6 @@ 1) $descr .= " Phase $i"; $current = snmp_get($device, $freq_oid, "-Oqv") / 10; $type = "netmanplus"; - $precision = 10; + $divisor = 10; $index = '3.2.0.'.$i; - echo discover_freq($valid_freq, $device, $freq_oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'freq', $device, $freq_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } $freq_oid = "1.3.6.1.2.1.33.1.4.2.0"; $descr = "Output"; $current = snmp_get($device, $freq_oid, "-Oqv") / 10; $type = "netmanplus"; - $precision = 10; + $divisor = 10; $index = '4.2.0'; - echo discover_freq($valid_freq, $device, $freq_oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'freq', $device, $freq_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); $freq_oid = "1.3.6.1.2.1.33.1.5.1.0"; $descr = "Bypass"; $current = snmp_get($device, $freq_oid, "-Oqv") / 10; $type = "netmanplus"; - $precision = 10; + $divisor = 10; $index = '5.1.0'; - echo discover_freq($valid_freq, $device, $freq_oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'freq', $device, $freq_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } ## APC @@ -95,7 +87,7 @@ if ($device['os'] == "apc") $oids = snmp_walk($device, "1.3.6.1.4.1.318.1.1.8.5.3.2.1.4", "-OsqnU", ""); if ($debug) { echo($oids."\n"); } if ($oids) echo("APC In "); - $precision = 1; + $divisor = 1; $type = "apc"; foreach(explode("\n", $oids) as $data) { @@ -107,14 +99,14 @@ if ($device['os'] == "apc") $index = $split_oid[count($split_oid)-1]; $oid = "1.3.6.1.4.1.318.1.1.8.5.3.2.1.4." . $index; $descr = "Input Feed " . chr(64+$index); - discover_freq($valid_freq,$device, $oid, "3.2.1.4.$index", $type, $descr, $precision, NULL, NULL, $current); + discover_sensor($valid_sensor, 'freq', $device, $oid, "3.2.1.4.$index", $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } $oids = snmp_walk($device, "1.3.6.1.4.1.318.1.1.8.5.4.2.1.4", "-OsqnU", ""); if ($debug) { echo($oids."\n"); } if ($oids) echo(" APC Out "); - $precision = 1; + $divisor = 1; $type = "apc"; foreach(explode("\n", $oids) as $data) { @@ -126,7 +118,7 @@ if ($device['os'] == "apc") $index = $split_oid[count($split_oid)-3]; $oid = "1.3.6.1.4.1.318.1.1.8.5.4.2.1.4." . $index; $descr = "Output Feed"; if (count(explode("\n", $oids)) > 1) { $descr .= " $index"; } - discover_freq($valid_freq,$device, $oid, "4.2.1.4.$index", $type, $descr, $precision, NULL, NULL, $current); + discover_sensor($valid_sensor, 'freq', $device, $oid, "4.2.1.4.$index", $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } @@ -136,11 +128,11 @@ if ($device['os'] == "apc") { echo(" APC In "); list($oid,$current) = explode(" ",$oids); - $precision = 1; + $divisor = 1; $type = "apc"; $index = "3.2.4.0"; $descr = "Input"; - discover_freq($valid_freq, $device, $oid, $index, $type, $descr, $precision, NULL, NULL, $current); + discover_sensor($valid_sensor, 'freq', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } $oids = snmp_get($device, "1.3.6.1.4.1.318.1.1.1.4.2.2.0", "-OsqnU", ""); @@ -149,33 +141,18 @@ if ($device['os'] == "apc") { echo(" APC Out "); list($oid,$current) = explode(" ",$oids); - $precision = 1; + $divisor = 1; $type = "apc"; $index = "4.2.2.0"; $descr = "Output"; - discover_freq($valid_freq, $device, $oid, $index, $type, $descr, $precision, NULL, NULL, $current); + discover_sensor($valid_sensor, 'freq', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } -## Delete removed sensors -if($debug) { print_r($valid_freq); } +if($debug) { print_r($valid['freq']); } -$sql = "SELECT * FROM frequency WHERE device_id = '".$device['device_id']."'"; -if ($query = mysql_query($sql)) -{ - while ($test_freq = mysql_fetch_array($query)) - { - $index = $test_freq['freq_index']; - $type = $test_freq['freq_type']; - if($debug) { echo("$type -> $index\n"); } - if(!$valid_freq[$type][$index]) { - echo("-"); - mysql_query("DELETE FROM `frequency` WHERE freq_id = '" . $test_freq['freq_id'] . "'"); - } - } -} - -unset($fan_exists); echo("\n"); +check_valid_sensors($device, 'freq', $valid_sensor); +echo("\n"); ?> diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 9d87dcee07..f797243ddd 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -1,42 +1,61 @@ " . $type . "\n"); } + if(!$valid[$class][$type][$index]) + { + echo("-"); + mysql_query("DELETE FROM `sensors` WHERE sensor_class='humidity' AND sensor_id = '" . $test['sensor_id'] . "'"); + } + unset($oid); unset($type); + } + } +} + + function discover_juniAtmVp(&$valid, $interface_id, $vp_id, $vp_descr) { global $config, $debug; @@ -174,204 +193,6 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = } } -function discover_temperature(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_limit = NULL, $high_limit = NULL, $current) -{ - global $config, $debug; - if($debug) { echo("$oid, $index, $type, $descr, $precision, $current\n"); } - - 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 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 `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['sensor_oid'] && $descr == $entry['sensor_descr'] && $precision == $entry['sensor_precision']) - { - echo("."); - } - else - { - 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"); - } - } - $valid[$type][$index] = 1; - return $return; -} - -function discover_fan(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_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']['fan']; - } - - if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='fanspeed' 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_current`) "; - $query .= " VALUES ('fanspeed','".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$low_limit', '$current')"; - mysql_query($query); - echo("+"); - } - else - { - $fan_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='fanspeed' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'")); - if($oid == $fan_entry['sensor_oid'] && $descr == $fan_entry['sensor_descr'] && $precision == $fan_entry['sensor_precision']) - { - echo("."); - } - else - { - mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class` = 'fanspeed' AND `device_id` = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index' "); - echo("U"); - } - } - $valid[$type][$index] = 1; - return $return; -} - -function discover_volt(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_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']['volt']; - } - - if (mysql_result(mysql_query("SELECT count(sensor_id) FROM `sensors` WHERE sensor_class='voltage' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'"),0) == '0') - { - - if(!$high_limit && isset($current)) { $high_limit = round($current * 1.05, 2); } - if(!$low_limit && isset($current)) { $low_limit = round($current * 0.95, 2); } - - $query = "INSERT INTO sensors (`sensor_class`, `device_id`, `sensor_oid`, `sensor_index`, `sensor_type`, `sensor_descr`, `sensor_precision`, `sensor_limit`, `sensor_limit_low`, `sensor_current`) "; - $query .= " VALUES ('voltage','".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')"; - mysql_query($query); - if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); } - echo("+"); - } - else - { - - $volt_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='voltage' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'")); - - if(!isset($current) && isset($volt_entry['current'])) { $current = $volt_entry['current']; } - - - if(!$high_limit && !$volt_entry['sensor_limit'] && $current) { $high_limit = round($current * 1.05, 2); } elseif (!$high_limit && $volt_entry['sensor_limit']) { $high_limit = $volt_entry['sensor_limit']; } - if(!$low_limit && !$volt_entry['sensor_limit_low'] && $current) { $low_limit = round($current * 0.95, 2); } elseif (!$low_limit && $volt_entry['sensor_limit_low']) { $low_limit = $volt_entry['sensor_limit_low']; } - - if($oid == $volt_entry['sensor_oid'] && $descr == $volt_entry['sensor_descr'] && $precision == $volt_entry['sensor_precision'] && $volt_entry['sensor_limit'] == $high_limit && $volt_entry['sensor_limit_low'] == $low_limit) - { - echo("."); - } - else - { - $sql = "UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision', `sensor_limit_low` = '$low_limit', `sensor_limit` = '$high_limit' WHERE `sensor_class` = 'voltage' AND `device_id` = '" . $device['device_id'] . "' AND sensor_type = '$type' AND `sensor_index` = '$index'"; - $query = mysql_query($sql); - echo("U"); - if($debug) { echo("$sql ". mysql_affected_rows() . " updated"); } - } - } - - $valid[$type][$index] = 1; - return $return; -} - -function discover_freq(&$valid, $device, $oid, $index, $type, $descr, $precision = 1, $low_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']['freq']; - } - - if (mysql_result(mysql_query("SELECT count(freq_id) FROM `frequency` WHERE device_id = '".$device['device_id']."' AND freq_type = '$type' AND `freq_index` = '$index'"),0) == '0') - { - - if(!$high_limit && isset($current)) { $high_limit = round($current * 1.05, 0); } - if(!$low_limit && isset($current)) { $low_limit = round($current * 0.95, 0); } - - $query = "INSERT INTO frequency (`device_id`, `freq_oid`, `freq_index`, `freq_type`, `freq_descr`, `freq_precision`, `freq_limit`, `freq_limit_low`, `freq_current`) "; - $query .= " VALUES ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')"; - mysql_query($query); - if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); } - echo("+"); - } - else - { - $freq_entry = mysql_fetch_array(mysql_query("SELECT * FROM `frequency` WHERE device_id = '".$device['device_id']."' AND freq_type = '$type' AND `freq_index` = '$index'")); - if($oid == $freq_entry['freq_oid'] && $descr == $freq_entry['freq_descr'] && $precision == $freq_entry['freq_precision']) - { - echo("."); - } - else - { - mysql_query("UPDATE frequency SET `freq_descr` = '$descr', `freq_oid` = '$oid', `freq_precision` = '$precision' WHERE `device_id` = '" . $device['device_id'] . "' AND freq_type = '$type' AND `freq_index` = '$index' "); - echo("U"); - if($debug) { echo("$query ". mysql_affected_rows() . " updated"); } - } - } - - $valid[$type][$index] = 1; - return $return; -} - -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) -{ - 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) -{ - 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='current' 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_current`) "; - $query .= " VALUES ('current', '".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$warn_limit', '$low_limit', '$current')"; - mysql_query($query); - if($debug) { echo("$query ". mysql_affected_rows() . " inserted"); } - echo("+"); - } - else - { - $current_entry = mysql_fetch_array(mysql_query("SELECT * FROM `sensors` WHERE sensor_class='current' AND device_id = '".$device['device_id']."' AND sensor_type = '$type' AND `sensor_index` = '$index'")); - if($oid == $current_entry['sensor_oid'] && $descr == $current_entry['sensor_descr'] && $precision == $current_entry['sensor_precision']) - { - echo("."); - } - else - { - mysql_query("UPDATE sensors SET `sensor_descr` = '$descr', `sensor_oid` = '$oid', `sensor_precision` = '$precision' WHERE `sensor_class`='current' 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_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity = NULL, $current = NULL) { global $config, $debug; diff --git a/includes/discovery/humidity.inc.php b/includes/discovery/humidity.inc.php index 9619ad8a91..a59fbdf755 100755 --- a/includes/discovery/humidity.inc.php +++ b/includes/discovery/humidity.inc.php @@ -7,29 +7,12 @@ $port = $device['port']; echo("Humidity : "); -$valid_humidity = array(); - include_dir("includes/discovery/humidity"); -if($debug) { print_r($valid_humidity); } +if($debug) { print_r($valid['humidity']); } -$sql = "SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class='humidity' AND S.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; -if ($query = mysql_query($sql)) -{ - while ($test_humidity = mysql_fetch_array($query)) - { - $humidity_index = $test_humidity['sensor_index']; - $humidity_type = $test_humidity['sensor_type']; - if($debug) { echo($humidity_index . " -> " . $humidity_type . "\n"); } - if(!$valid_humidity[$humidity_type][$humidity_index]) - { - echo("-"); - mysql_query("DELETE FROM `sensors` WHERE sensor_class='humidity' AND sensor_id = '" . $test_humidity['sensor_id'] . "'"); - } - unset($humidity_oid); unset($humidity_type); - } -} +check_valid_sensors($device, 'humidity', $valid_sensor); -unset($valid_humidity); echo("\n"); +echo("\n"); ?> diff --git a/includes/discovery/humidity/akcp.inc.php b/includes/discovery/humidity/akcp.inc.php index a29d5a6c20..c63f65e309 100644 --- a/includes/discovery/humidity/akcp.inc.php +++ b/includes/discovery/humidity/akcp.inc.php @@ -1,6 +1,6 @@ \ No newline at end of file +?> diff --git a/includes/discovery/mempools/cemp.inc.php b/includes/discovery/mempools/cemp.inc.php index e9b6e4f0ca..7326754966 100755 --- a/includes/discovery/mempools/cemp.inc.php +++ b/includes/discovery/mempools/cemp.inc.php @@ -1,5 +1,7 @@ " . $temperature_type . "\n"); } - if(!$valid_temp[$temperature_type][$temperature_index]) - { - echo("-"); - mysql_query("DELETE FROM `sensors` WHERE sensor_class='temperature' AND sensor_id = '" . $test_temperature['sensor_id'] . "'"); - } - unset($temperature_oid); unset($temperature_type); - } -} +check_valid_sensors($device, 'temperature', $valid_sensor); -unset($valid_temp); echo("\n"); +echo("\n"); ?> diff --git a/includes/discovery/temperatures/adva.inc.php b/includes/discovery/temperatures/adva.inc.php index 06c9703a50..6083584139 100755 --- a/includes/discovery/temperatures/adva.inc.php +++ b/includes/discovery/temperatures/adva.inc.php @@ -16,73 +16,73 @@ Disabled needing rewrite $descr_hss1 = "hss1"; $oid_hss2 = "1.3.6.1.4.1.2544.1.9.2.4.1.5.1.1.14"; $descr_hss2 = "hss2"; - $temp_chassis = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_chassis")); - $temp_stm16 = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_stm16")); - $temp_hss1 = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_hss1")); - $temp_hss2 = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_hss2")); + $temperature_chassis = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_chassis")); + $temperature_stm16 = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_stm16")); + $temperature_hss1 = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_hss1")); + $temperature_hss2 = trim(shell_exec($config['snmpget'] . " -M " . $config['mibdir'] . " -O qv -$snmpver -c $community $hostname:$port $oid_hss2")); echo("Adva Chassis "); - if($temp_chassis != "0") + if($temperature_chassis != "0") { - if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$oid_chassis' AND temp_host = '$id'"),0) == '0') + if(mysql_result(mysql_query("SELECT count(temperature_id) FROM `temperature` WHERE temperature_oid = '$oid_chassis' AND temperature_host = '$id'"),0) == '0') { - $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$oid_chassis', '$descr_chassis',1," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp_chassis')"; + $query = "INSERT INTO temperature (`temperature_host`, `temperature_oid`, `temperature_descr`, `temperature_precision`, `temperature_limit`, `temperature_current`) values ('$id', '$oid_chassis', '$descr_chassis',1," . ($config['defaults']['temperature_limit'] ? $config['defaults']['temperature_limit'] : '60') . ", '$temperature_chassis')"; mysql_query($query); echo("+"); - } elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_chassis'"), 0) != $descr_chassis) { + } elseif (mysql_result(mysql_query("SELECT `temperature_descr` FROM temperature WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_chassis'"), 0) != $descr_chassis) { echo("U"); - mysql_query("UPDATE temperature SET `temp_descr` = '$descr_chassis' WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_chassis'"); + mysql_query("UPDATE temperature SET `temperature_descr` = '$descr_chassis' WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_chassis'"); } else { echo("."); } - $temp_exists[] = "$id $oid_chassis"; + $temperature_exists[] = "$id $oid_chassis"; } echo("STM16 "); - if($temp_stm16 != "0") + if($temperature_stm16 != "0") { - if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$oid_stm16' AND temp_host = '$id'"),0) == '0') + if(mysql_result(mysql_query("SELECT count(temperature_id) FROM `temperature` WHERE temperature_oid = '$oid_stm16' AND temperature_host = '$id'"),0) == '0') { - $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$oid_stm16', '$descr_stm16',1," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp_stm16')"; + $query = "INSERT INTO temperature (`temperature_host`, `temperature_oid`, `temperature_descr`, `temperature_precision`, `temperature_limit`, `temperature_current`) values ('$id', '$oid_stm16', '$descr_stm16',1," . ($config['defaults']['temperature_limit'] ? $config['defaults']['temperature_limit'] : '60') . ", '$temperature_stm16')"; mysql_query($query); echo("+"); - } elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_stm16'"), 0) != $descr_stm16) { + } elseif (mysql_result(mysql_query("SELECT `temperature_descr` FROM temperature WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_stm16'"), 0) != $descr_stm16) { echo("U"); - mysql_query("UPDATE temperature SET `temp_descr` = '$descr_stm16' WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_stm16'"); + mysql_query("UPDATE temperature SET `temperature_descr` = '$descr_stm16' WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_stm16'"); } else { echo("."); } - $temp_exists[] = "$id $oid_stm16"; + $temperature_exists[] = "$id $oid_stm16"; } echo("HSS1 "); - if($temp_hss1 != "0") + if($temperature_hss1 != "0") { - if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$oid_hss1' AND temp_host = '$id'"),0) == '0') + if(mysql_result(mysql_query("SELECT count(temperature_id) FROM `temperature` WHERE temperature_oid = '$oid_hss1' AND temperature_host = '$id'"),0) == '0') { - $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$oid_hss1', '$descr_hss1',1," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp_hss1')"; + $query = "INSERT INTO temperature (`temperature_host`, `temperature_oid`, `temperature_descr`, `temperature_precision`, `temperature_limit`, `temperature_current`) values ('$id', '$oid_hss1', '$descr_hss1',1," . ($config['defaults']['temperature_limit'] ? $config['defaults']['temperature_limit'] : '60') . ", '$temperature_hss1')"; mysql_query($query); echo("+"); - } elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_hss1'"), 0) != $descr_hss1) { + } elseif (mysql_result(mysql_query("SELECT `temperature_descr` FROM temperature WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_hss1'"), 0) != $descr_hss1) { echo("U"); - mysql_query("UPDATE temperature SET `temp_descr` = '$descr_hss1' WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_hss1'"); + mysql_query("UPDATE temperature SET `temperature_descr` = '$descr_hss1' WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_hss1'"); } else { echo("."); } - $temp_exists[] = "$id $oid_hss1"; + $temperature_exists[] = "$id $oid_hss1"; } echo("HSS2 "); - if($temp_hss2 != "0") + if($temperature_hss2 != "0") { - if(mysql_result(mysql_query("SELECT count(temp_id) FROM `temperature` WHERE temp_oid = '$oid_hss2' AND temp_host = '$id'"),0) == '0') + if(mysql_result(mysql_query("SELECT count(temperature_id) FROM `temperature` WHERE temperature_oid = '$oid_hss2' AND temperature_host = '$id'"),0) == '0') { - $query = "INSERT INTO temperature (`temp_host`, `temp_oid`, `temp_descr`, `temp_precision`, `temp_limit`, `temp_current`) values ('$id', '$oid_hss2', '$descr_hss2',1," . ($config['defaults']['temp_limit'] ? $config['defaults']['temp_limit'] : '60') . ", '$temp_hss2')"; + $query = "INSERT INTO temperature (`temperature_host`, `temperature_oid`, `temperature_descr`, `temperature_precision`, `temperature_limit`, `temperature_current`) values ('$id', '$oid_hss2', '$descr_hss2',1," . ($config['defaults']['temperature_limit'] ? $config['defaults']['temperature_limit'] : '60') . ", '$temperature_hss2')"; mysql_query($query); echo("+"); - } elseif (mysql_result(mysql_query("SELECT `temp_descr` FROM temperature WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_hss2'"), 0) != $descr_hss2) { + } elseif (mysql_result(mysql_query("SELECT `temperature_descr` FROM temperature WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_hss2'"), 0) != $descr_hss2) { echo("U"); - mysql_query("UPDATE temperature SET `temp_descr` = '$descr_hss2' WHERE `temp_host` = '$id' AND `temp_oid` = '$oid_hss2'"); + mysql_query("UPDATE temperature SET `temperature_descr` = '$descr_hss2' WHERE `temperature_host` = '$id' AND `temperature_oid` = '$oid_hss2'"); } else { echo("."); } - $temp_exists[] = "$id $oid_hss2"; + $temperature_exists[] = "$id $oid_hss2"; } */ ?> diff --git a/includes/discovery/temperatures/akcp.inc.php b/includes/discovery/temperatures/akcp.inc.php index bee0c304e2..10800a61ee 100644 --- a/includes/discovery/temperatures/akcp.inc.php +++ b/includes/discovery/temperatures/akcp.inc.php @@ -1,6 +1,6 @@ $entry) { - $descr = "Slot ".$index; $oid = ".1.3.6.1.4.1.6027.3.8.1.2.1.1.5.".$index; $current = $entry['chSysCardTemp']; - - discover_temperature($valid_temp, $device, $oid, $index, "ftos-cseries", $descr, "1", NULL, NULL, $current); + discover_sensor($valid_sensor, 'temperature', $device, $oid, $index, 'ftos-cseries', $descr, '1', '1', NULL, NULL, NULL, NULL, $current); } } diff --git a/includes/discovery/temperatures/ftos-e-series.inc.php b/includes/discovery/temperatures/ftos-e-series.inc.php index c944dd9b69..ca9fa5eaf4 100644 --- a/includes/discovery/temperatures/ftos-e-series.inc.php +++ b/includes/discovery/temperatures/ftos-e-series.inc.php @@ -1,5 +1,7 @@ $entry) { - $descr = "Slot ".$index; $oid = ".1.3.6.1.4.1.6027.3.1.1.2.3.1.8.".$index; $current = $entry['chSysCardUpperTemp']; - - discover_temperature($valid_temp, $device, $oid, $index, "ftos-eseries", $descr, "1", NULL, NULL, $current); + discover_sensor($valid_sensor, 'temperature', $device, $oid, $index, 'ftos-eseries', $descr, '1', '1', NULL, NULL, NULL, NULL, $current); } } diff --git a/includes/discovery/temperatures/ftos-s-series.inc.php b/includes/discovery/temperatures/ftos-s-series.inc.php index 510f54cadd..6759640de6 100644 --- a/includes/discovery/temperatures/ftos-s-series.inc.php +++ b/includes/discovery/temperatures/ftos-s-series.inc.php @@ -1,12 +1,12 @@ $entry) { - $descr = "Unit ".$index . " " . $entry['chStackUnitSysType']; $oid = ".1.3.6.1.4.1.6027.3.10.1.2.2.1.14.".$index; $current = $entry['chStackUnitTemp']; - - discover_temperature($valid_temp, $device, $oid, $index, "ftos-sseries", $descr, "1", NULL, NULL, $current); + discover_sensor($valid_sensor, 'temperature', $device, $oid, $index, 'ftos-sseries', $descr, '1', '1', NULL, NULL, NULL, NULL, $current); } } diff --git a/includes/discovery/temperatures/ironware.inc.php b/includes/discovery/temperatures/ironware.inc.php index bee118d627..641c8d1a41 100644 --- a/includes/discovery/temperatures/ironware.inc.php +++ b/includes/discovery/temperatures/ironware.inc.php @@ -1,6 +1,6 @@ "0") { - $temp_oid = ".1.3.6.1.4.1.18248.1.1.1.0"; + $temperature_oid = ".1.3.6.1.4.1.18248.1.1.1.0"; $descr = trim(str_replace("\"", "", $descr)); - discover_temperature($valid_temp, $device, $temp_oid, "1", "ironware", $descr, "10", NULL, NULL, $temp); + discover_sensor($valid_sensor, 'temperature', $device, $temperature_oid, "1", 'papouch-tme', $descr, '1', '1', NULL, NULL, NULL, NULL, $temperature); } } diff --git a/includes/discovery/temperatures/powerconnect.inc.php b/includes/discovery/temperatures/powerconnect.inc.php index 595688c20b..514abda9ad 100644 --- a/includes/discovery/temperatures/powerconnect.inc.php +++ b/includes/discovery/temperatures/powerconnect.inc.php @@ -1,7 +1,7 @@ 1) { $descr .= " $index"; } - discover_volt($valid_volt,$device, $oid, "4.3.1.3.$index", $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $oid, "4.3.1.3.$index", $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } @@ -105,11 +99,11 @@ if ($device['os'] == "apc") { echo(" APC In "); list($oid,$current) = explode(" ",$oids); - $precision = 1; + $divisor = 1; $type = "apc"; $index = "3.2.1.0"; $descr = "Input"; - discover_volt($valid_volt, $device, $oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } $oids = snmp_get($device, "1.3.6.1.4.1.318.1.1.1.4.2.1.0", "-OsqnU", ""); @@ -118,11 +112,11 @@ if ($device['os'] == "apc") { echo(" APC Out "); list($oid,$current) = explode(" ",$oids); - $precision = 1; + $divisor = 1; $type = "apc"; $index = "4.2.1.0"; $descr = "Output"; - discover_volt($valid_volt, $device, $oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } @@ -134,7 +128,7 @@ if ($device['os'] == "linux") $oids = trim($oids); if ($oids) echo("Supermicro "); $type = "supermicro"; - $precision = "1000"; + $divisor = "1000"; foreach(explode("\n", $oids) as $data) { $data = trim($data); @@ -152,15 +146,15 @@ if ($device['os'] == "linux") $lowlimit_oid = "1.3.6.1.4.1.10876.2.1.1.1.1.6.".$index; $descr = snmp_get($device, $descr_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB"); - $current = snmp_get($device, $volt_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB") / $precision; - $limit = snmp_get($device, $limit_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB") / $precision; - $lowlimit = snmp_get($device, $lowlimit_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB") / $precision; + $current = snmp_get($device, $volt_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB") / $divisor; + $limit = snmp_get($device, $limit_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB") / $divisor; + $lowlimit = snmp_get($device, $lowlimit_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB") / $divisor; $monitor = snmp_get($device, $monitor_oid, "-Oqv", "SUPERMICRO-HEALTH-MIB"); $descr = trim(str_ireplace("Voltage", "", $descr)); if ($monitor == 'true') { - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, $lowlimit, $limit, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', $lowlimit, NULL, $limit, NULL, $current); } } } @@ -186,9 +180,9 @@ if ($device['os'] == "mgeups") } $current /= 10; $type = "mge-ups"; - $precision = 10; + $divisor = 10; $index = $i; - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, $lowlimit, $limit, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } $oids = trim(snmp_walk($device, "1.3.6.1.4.1.705.1.6.1", "-OsqnU")); if ($debug) { echo($oids."\n"); } @@ -205,9 +199,9 @@ if ($device['os'] == "mgeups") } $current /= 10; $type = "mge-ups"; - $precision = 10; + $divisor = 10; $index = 100+$i; - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, $lowlimit, $limit, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } @@ -228,13 +222,13 @@ if ($device['os'] == "netmanplus") $split_oid = explode('.',$oid); $volt_id = $split_oid[count($split_oid)-1]; $volt_oid = "1.3.6.1.2.1.33.1.2.5.$volt_id"; - $precision = 10; - $volt = snmp_get($device, $volt_oid, "-O vq") / $precision; - #$volt = trim(shell_exec($config['snmpget'] . " -O qv -$snmpver -c $community $hostname:$port $volt_oid")) / $precision; + $divisor = 10; + $volt = snmp_get($device, $volt_oid, "-O vq") / $divisor; + #$volt = trim(shell_exec($config['snmpget'] . " -O qv -$snmpver -c $community $hostname:$port $volt_oid")) / $divisor; $descr = "Battery" . (count(explode("\n",$oids)) == 1 ? '' : ' ' . ($volt_id+1)); $type = "netmanplus"; $index = 500+$volt_id; - discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, NULL, NULL, $volt); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $volt); } } @@ -247,9 +241,9 @@ if ($device['os'] == "netmanplus") $descr = "Output"; if ($numPhase > 1) $descr .= " Phase $i"; $current = snmp_get($device, $volt_oid, "-Oqv"); $type = "netmanplus"; - $precision = 1; + $divisor = 1; $index = $i; - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } $oids = trim(snmp_walk($device, "1.3.6.1.2.1.33.1.3.2.0", "-OsqnU")); @@ -261,9 +255,9 @@ if ($device['os'] == "netmanplus") $descr = "Input"; if ($numPhase > 1) $descr .= " Phase $i"; $current = snmp_get($device, $volt_oid, "-Oqv"); $type = "netmanplus"; - $precision = 1; + $divisor = 1; $index = 100+$i; - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } $oids = trim(snmp_walk($device, "1.3.6.1.2.1.33.1.5.2.0", "-OsqnU")); @@ -275,9 +269,9 @@ if ($device['os'] == "netmanplus") $descr = "Bypass"; if ($numPhase > 1) $descr .= " Phase $i"; $current = snmp_get($device, $volt_oid, "-Oqv"); $type = "netmanplus"; - $precision = 1; + $divisor = 1; $index = 200+$i; - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, NULL, NULL, $current); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $current); } } @@ -289,12 +283,11 @@ if ($device['os'] == "gamatronicups") $descr = "Input Phase $i"; $volt = snmp_get($device, $volt_oid, "-Oqv"); $type = "gamatronicups"; - $precision = 1; + $divisor = 1; $index = $i; $lowlimit = 0; $limit = NULL; - - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, $lowlimit, $limit, $volt); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $volt); } for($i = 1; $i <= 3 ;$i++) @@ -303,36 +296,19 @@ if ($device['os'] == "gamatronicups") $descr = "Output Phase $i"; $volt = snmp_get($device, $volt_oid, "-Oqv"); $type = "gamatronicups"; - $precision = 1; + $divisor = 1; $index = 100+$i; $lowlimit = 0; $limit = NULL; - - echo discover_volt($valid_volt,$device, $volt_oid, $index, $type, $descr, $precision, $lowlimit, $limit, $volt); + echo discover_sensor($valid_sensor, 'volt', $device, $volt_oid, $index, $type, $descr, $divisor, '1', NULL, NULL, NULL, NULL, $volt); } } +if($debug) { print_r($valid['volt']); } -## Delete removed sensors +check_valid_sensors($device, 'volt', $valid_sensor); -if($debug) { print_r($valid_volt); } - -$sql = "SELECT * FROM voltage WHERE device_id = '".$device['device_id']."'"; -if ($query = mysql_query($sql)) -{ - while ($test_volt = mysql_fetch_array($query)) - { - $index = $test_volt['volt_index']; - $type = $test_volt['volt_type']; - if($debug) { echo("$type -> $index\n"); } - if(!$valid_volt[$type][$index]) { - echo("-"); - mysql_query("DELETE FROM `voltage` WHERE volt_id = '" . $test_volt['volt_id'] . "'"); - } - } -} - -unset($valid_volt); echo("\n"); +echo("\n"); ?> diff --git a/includes/polling/current.inc.php b/includes/polling/current.inc.php index 70a81270e7..bb507da4ef 100644 --- a/includes/polling/current.inc.php +++ b/includes/polling/current.inc.php @@ -8,10 +8,9 @@ while($dbcurrent = mysql_fetch_array($current_data)) { $current = snmp_get($device, $dbcurrent['sensor_oid'], "-OUqnv", "SNMPv2-MIB"); - if ($dbcurrent['sensor_precision']) - { - $current = $current / $dbcurrent['sensor_precision']; - } + if ($dbcurrent['sensor_divisor']) { $current = $current / $dbcurrent['sensor_divisor']; } + if ($dbcurrent['sensor_multplier']) { $current = $current * $dbcurrent['sensor_multiplier']; } + $currentrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("current-" . $dbcurrent['sensor_descr'] . ".rrd"); diff --git a/includes/polling/fanspeeds.inc.php b/includes/polling/fanspeeds.inc.php index 9ded04c233..783deadc17 100755 --- a/includes/polling/fanspeeds.inc.php +++ b/includes/polling/fanspeeds.inc.php @@ -8,7 +8,9 @@ while($fanspeed = mysql_fetch_array($fan_data)) { $fan = snmp_get($device, $fanspeed['sensor_oid'], "-OUqnv", "SNMPv2-MIB"); - if ($fanspeed['sensor_precision']) { $fan = $fan / $fanspeed['sensor_precision']; } + if ($fanspeed['sensor_divisor']) { $fan = $fan / $fanspeed['sensor_divisor']; } + if ($fanspeed['sensor_multiplier']) { $fan = $fan * $fanspeed['sensor_multiplier']; } + $fanrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("fan-" . $fanspeed['sensor_descr'] . ".rrd"); diff --git a/includes/polling/humidity.inc.php b/includes/polling/humidity.inc.php index a6a809c076..26b69725ca 100644 --- a/includes/polling/humidity.inc.php +++ b/includes/polling/humidity.inc.php @@ -11,10 +11,9 @@ while($humidity = mysql_fetch_array($hum_data)) { ## fixme snmp_get() - if ($humidity['sensor_precision']) - { - $hum = $hum / $humidity['sensor_precision']; - } + if ($humidity['sensor_divisor']) { $hum = $hum / $humidity['sensor_divisor']; } + if ($humidity['sensor_multiplier']) { $hum = $hum / $humidity['sensor_multiplier']; } + $humrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("humidity-" . $humidity['sensor_descr'] . ".rrd"); diff --git a/includes/polling/temperatures.inc.php b/includes/polling/temperatures.inc.php index 244d771bca..5b75b7870e 100755 --- a/includes/polling/temperatures.inc.php +++ b/includes/polling/temperatures.inc.php @@ -16,7 +16,8 @@ while($temperature = mysql_fetch_array($temp_data)) { sleep(1); # Give the TME some time to reset } - if ($temperature['sensor_precision']) { $temp = $temp / $temperature['sensor_precision']; } + if ($temperature['sensor_divisor']) { $temp = $temp / $temperature['sensor_divisor']; } + if ($temperature['sensor_multiplier']) { $temp = $temp * $temperature['sensor_multiplier']; } $temprrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("temp-" . $temperature['sensor_descr'] . ".rrd"); diff --git a/includes/polling/voltages.inc.php b/includes/polling/voltages.inc.php index cb2df1a46a..5f6a7dc4f7 100755 --- a/includes/polling/voltages.inc.php +++ b/includes/polling/voltages.inc.php @@ -8,10 +8,8 @@ while($voltage = mysql_fetch_array($volt_data)) { $volt = snmp_get($device, $voltage['sensor_oid'], "-OUqnv", "SNMPv2-MIB"); - if ($voltage['sensor_precision']) - { - $volt = $volt / $voltage['sensor_precision']; - } + if ($voltage['sensor_divisor']) { $volt = $volt / $voltage['sensor_divisor']; } + if ($voltage['sensor_multiplier']) { $volt = $volt * $voltage['sensor_multiplier']; } $voltrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("volt-" . $voltage['sensor_descr'] . ".rrd");