From 55c05c78660dc4cfc45aa13cd8f7d416815b9180 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Tue, 24 Nov 2015 16:14:07 -0700 Subject: [PATCH 01/10] Allow users to keep more statistics in the db * Add $config['enable_extended_port_metrics'] to enable feature * Add a new table to store stuff in * Update data from the poller --- includes/defaults.inc.php | 1 + includes/polling/ports.inc.php | 59 ++++++++++++++++++++++++++++++---- sql-schema/079.sql | 42 ++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 sql-schema/079.sql diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 0e936861b7..1c0664ad8d 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -77,6 +77,7 @@ $config['memcached']['host'] = 'localhost'; $config['memcached']['port'] = 11211; $config['memcached']['ttl'] = 240; +$config['enable_extended_port_metrics'] = false; $config['slow_statistics'] = true; // THIS WILL CHANGE TO FALSE IN FUTURE // RRD Format Settings diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 01a8e09aa1..9b51606adc 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -51,6 +51,21 @@ $stat_oids_db = array( 'ifInUcastPkts', 'ifOutUcastPkts', ); + +$stat_oids_db_extended = array( + 'ifInErrors', + 'ifOutErrors', + 'ifInNUcastPkts', + 'ifOutNUcastPkts', + 'ifInDiscards', + 'ifOutDiscards', + 'ifInUnknownProtos', + 'ifInBroadcastPkts', + 'ifOutBroadcastPkts', + 'ifInMulticastPkts', + 'ifOutMulticastPkts', +); + // From above for DB $etherlike_oids = array( 'dot3StatsAlignmentErrors', @@ -203,7 +218,14 @@ d_echo($port_stats); // FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :> // -- i can make it a function, so that you don't know what it's doing. // -- $ports = adamasMagicFunction($ports_db); ? -$ports_db = dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); +if ($config['enable_extended_port_metrics']) { + // select * doesn't do what we want if multiple tables have the same column name -- last one wins :/ + $ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id'])); +} +else { + $ports_db = dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); +} + foreach ($ports_db as $port) { $ports[$port['ifIndex']] = $port; } @@ -214,6 +236,9 @@ foreach ($port_stats as $ifIndex => $port) { echo 'valid'; if (!is_array($ports[$port['ifIndex']])) { $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports'); + if ($config['enable_extended_port_metrics']) { + dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics'); + } $ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id)); echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports[$port['ifIndex']]['port_id'].')'; // print_r($ports); @@ -222,6 +247,11 @@ foreach ($port_stats as $ifIndex => $port) { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id'])); $ports[$ifIndex]['deleted'] = '0'; } + if ($config['enable_extended_port_metrics'] && + $ports[$ifIndex]['ports_statistics_port_id'] === null) { + // in case someone enabled the option after the port was already created + dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics'); + } } else { if ($ports[$port['ifIndex']]['deleted'] != '1') { @@ -247,6 +277,7 @@ foreach ($ports as $port) { $polled_period = ($polled - $port['poll_time']); $port['update'] = array(); + $port['update_extended'] = array(); $port['state'] = array(); if ($config['slow_statistics'] == true) { @@ -401,10 +432,22 @@ foreach ($ports as $port) { // End parse ifAlias // Update IF-MIB metrics - foreach ($stat_oids_db as $oid) { + $_stat_oids = $stat_oids_db; + if ($config['enable_extended_port_metrics']) { + $_stat_oids = $_stat_oids + $stat_oids_db_extended; + } + foreach ($_stat_oids as $oid) { + $port_update = 'update'; + if ($config['enable_extended_port_metrics']) { + $extended_metric = !in_array($oid, $stat_oids_db, true); + if ($extended_metric) { + $port_update = 'update_extended'; + } + } + if ($config['slow_statistics'] == true) { - $port['update'][$oid] = $this_port[$oid]; - $port['update'][$oid.'_prev'] = $port[$oid]; + $port[$port_update][$oid] = $this_port[$oid]; + $port[$port_update][$oid.'_prev'] = $port[$oid]; } $oid_prev = $oid.'_prev'; @@ -420,8 +463,8 @@ foreach ($ports as $port) { $port['stats'][$oid.'_diff'] = $oid_diff; if ($config['slow_statistics'] == true) { - $port['update'][$oid.'_rate'] = $oid_rate; - $port['update'][$oid.'_delta'] = $oid_diff; + $port[$port_update][$oid.'_rate'] = $oid_rate; + $port[$port_update][$oid.'_delta'] = $oid_diff; } d_echo("\n $oid ($oid_diff B) $oid_rate Bps $polled_period secs\n"); @@ -546,6 +589,10 @@ foreach ($ports as $port) { // Update Database if (count($port['update'])) { $updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id'])); + if ($config['enable_extended_port_metrics'] and count($port['update_extended'])) { + // do we want to do something else with this? + $updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id'])); + } d_echo("$updated updated"); } diff --git a/sql-schema/079.sql b/sql-schema/079.sql new file mode 100644 index 0000000000..a6a7e48f24 --- /dev/null +++ b/sql-schema/079.sql @@ -0,0 +1,42 @@ +create table ports_statistics ( + port_id int(11) NOT NULL, + ifInNUcastPkts bigint(20) DEFAULT NULL, + ifInNUcastPkts_prev bigint(20) DEFAULT NULL, + ifInNUcastPkts_delta bigint(20) DEFAULT NULL, + ifInNUcastPkts_rate int(11) DEFAULT NULL, + ifOutNUcastPkts bigint(20) DEFAULT NULL, + ifOutNUcastPkts_prev bigint(20) DEFAULT NULL, + ifOutNUcastPkts_delta bigint(20) DEFAULT NULL, + ifOutNUcastPkts_rate int(11) DEFAULT NULL, + ifInDiscards bigint(20) DEFAULT NULL, + ifInDiscards_prev bigint(20) DEFAULT NULL, + ifInDiscards_delta bigint(20) DEFAULT NULL, + ifInDiscards_rate int(11) DEFAULT NULL, + ifOutDiscards bigint(20) DEFAULT NULL, + ifOutDiscards_prev bigint(20) DEFAULT NULL, + ifOutDiscards_delta bigint(20) DEFAULT NULL, + ifOutDiscards_rate int(11) DEFAULT NULL, + ifInUnknownProtos bigint(20) DEFAULT NULL, + ifInUnknownProtos_prev bigint(20) DEFAULT NULL, + ifInUnknownProtos_delta bigint(20) DEFAULT NULL, + ifInUnknownProtos_rate int(11) DEFAULT NULL, + ifInBroadcastPkts bigint(20) DEFAULT NULL, + ifInBroadcastPkts_prev bigint(20) DEFAULT NULL, + ifInBroadcastPkts_delta bigint(20) DEFAULT NULL, + ifInBroadcastPkts_rate int(11) DEFAULT NULL, + ifOutBroadcastPkts bigint(20) DEFAULT NULL, + ifOutBroadcastPkts_prev bigint(20) DEFAULT NULL, + ifOutBroadcastPkts_delta bigint(20) DEFAULT NULL, + ifOutBroadcastPkts_rate int(11) DEFAULT NULL, + ifInMulticastPkts bigint(20) DEFAULT NULL, + ifInMulticastPkts_prev bigint(20) DEFAULT NULL, + ifInMulticastPkts_delta bigint(20) DEFAULT NULL, + ifInMulticastPkts_rate int(11) DEFAULT NULL, + ifOutMulticastPkts bigint(20) DEFAULT NULL, + ifOutMulticastPkts_prev bigint(20) DEFAULT NULL, + ifOutMulticastPkts_delta bigint(20) DEFAULT NULL, + ifOutMulticastPkts_rate int(11) DEFAULT NULL, + PRIMARY KEY(port_id), + FOREIGN KEY(port_id) REFERENCES ports(port_id) +); + From 3f689045d9ddc41f3b388bad3375f1af07ea5cbb Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Tue, 24 Nov 2015 16:25:21 -0700 Subject: [PATCH 02/10] Remove a couple of stray OIDs --- includes/polling/ports.inc.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 9b51606adc..1bb8791082 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -53,8 +53,6 @@ $stat_oids_db = array( ); $stat_oids_db_extended = array( - 'ifInErrors', - 'ifOutErrors', 'ifInNUcastPkts', 'ifOutNUcastPkts', 'ifInDiscards', From fcaf3d49abbe03d85238738d6deccf0008f574a3 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Tue, 24 Nov 2015 16:34:57 -0700 Subject: [PATCH 03/10] Fix reference to non-existent variable Use $port_id since $ports[$ifIndex]['port_id'] doesn't exist yet --- includes/polling/ports.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 1bb8791082..da7a2c6df5 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -235,7 +235,7 @@ foreach ($port_stats as $ifIndex => $port) { if (!is_array($ports[$port['ifIndex']])) { $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports'); if ($config['enable_extended_port_metrics']) { - dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics'); + dbInsert(array('port_id' => $port_id), 'ports_statistics'); } $ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id)); echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports[$port['ifIndex']]['port_id'].')'; From 26be6c6d74dc8c920a5e1a4b4c74fa7dbaff5b02 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Mon, 30 Nov 2015 11:14:10 -0700 Subject: [PATCH 04/10] Add schema --- sql-schema/079.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql-schema/079.sql b/sql-schema/079.sql index a6a7e48f24..718c4005a6 100644 --- a/sql-schema/079.sql +++ b/sql-schema/079.sql @@ -36,7 +36,6 @@ create table ports_statistics ( ifOutMulticastPkts_prev bigint(20) DEFAULT NULL, ifOutMulticastPkts_delta bigint(20) DEFAULT NULL, ifOutMulticastPkts_rate int(11) DEFAULT NULL, - PRIMARY KEY(port_id), - FOREIGN KEY(port_id) REFERENCES ports(port_id) + PRIMARY KEY(port_id) ); From 612a4b3cad9df0ee423fef40858208f179c8e01e Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Wed, 2 Dec 2015 14:12:53 -0700 Subject: [PATCH 05/10] Bump schema version Use version 081 due to other pending PR's with schema updates --- sql-schema/{079.sql => 081.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sql-schema/{079.sql => 081.sql} (100%) diff --git a/sql-schema/079.sql b/sql-schema/081.sql similarity index 100% rename from sql-schema/079.sql rename to sql-schema/081.sql From cdc6bb3bb8d5b826192153c44008c014a0d44dfc Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Thu, 3 Dec 2015 09:34:11 -0700 Subject: [PATCH 06/10] Update schema change to a single line --- sql-schema/081.sql | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/sql-schema/081.sql b/sql-schema/081.sql index 718c4005a6..c8218e2322 100644 --- a/sql-schema/081.sql +++ b/sql-schema/081.sql @@ -1,41 +1 @@ -create table ports_statistics ( - port_id int(11) NOT NULL, - ifInNUcastPkts bigint(20) DEFAULT NULL, - ifInNUcastPkts_prev bigint(20) DEFAULT NULL, - ifInNUcastPkts_delta bigint(20) DEFAULT NULL, - ifInNUcastPkts_rate int(11) DEFAULT NULL, - ifOutNUcastPkts bigint(20) DEFAULT NULL, - ifOutNUcastPkts_prev bigint(20) DEFAULT NULL, - ifOutNUcastPkts_delta bigint(20) DEFAULT NULL, - ifOutNUcastPkts_rate int(11) DEFAULT NULL, - ifInDiscards bigint(20) DEFAULT NULL, - ifInDiscards_prev bigint(20) DEFAULT NULL, - ifInDiscards_delta bigint(20) DEFAULT NULL, - ifInDiscards_rate int(11) DEFAULT NULL, - ifOutDiscards bigint(20) DEFAULT NULL, - ifOutDiscards_prev bigint(20) DEFAULT NULL, - ifOutDiscards_delta bigint(20) DEFAULT NULL, - ifOutDiscards_rate int(11) DEFAULT NULL, - ifInUnknownProtos bigint(20) DEFAULT NULL, - ifInUnknownProtos_prev bigint(20) DEFAULT NULL, - ifInUnknownProtos_delta bigint(20) DEFAULT NULL, - ifInUnknownProtos_rate int(11) DEFAULT NULL, - ifInBroadcastPkts bigint(20) DEFAULT NULL, - ifInBroadcastPkts_prev bigint(20) DEFAULT NULL, - ifInBroadcastPkts_delta bigint(20) DEFAULT NULL, - ifInBroadcastPkts_rate int(11) DEFAULT NULL, - ifOutBroadcastPkts bigint(20) DEFAULT NULL, - ifOutBroadcastPkts_prev bigint(20) DEFAULT NULL, - ifOutBroadcastPkts_delta bigint(20) DEFAULT NULL, - ifOutBroadcastPkts_rate int(11) DEFAULT NULL, - ifInMulticastPkts bigint(20) DEFAULT NULL, - ifInMulticastPkts_prev bigint(20) DEFAULT NULL, - ifInMulticastPkts_delta bigint(20) DEFAULT NULL, - ifInMulticastPkts_rate int(11) DEFAULT NULL, - ifOutMulticastPkts bigint(20) DEFAULT NULL, - ifOutMulticastPkts_prev bigint(20) DEFAULT NULL, - ifOutMulticastPkts_delta bigint(20) DEFAULT NULL, - ifOutMulticastPkts_rate int(11) DEFAULT NULL, - PRIMARY KEY(port_id) -); - +CREATE TABLE `ports_statistics` ( `port_id` int(11) NOT NULL, `ifInNUcastPkts` bigint(20) DEFAULT NULL, `ifInNUcastPkts_prev` bigint(20) DEFAULT NULL, `ifInNUcastPkts_delta` bigint(20) DEFAULT NULL, `ifInNUcastPkts_rate` int(11) DEFAULT NULL, `ifOutNUcastPkts` bigint(20) DEFAULT NULL, `ifOutNUcastPkts_prev` bigint(20) DEFAULT NULL, `ifOutNUcastPkts_delta` bigint(20) DEFAULT NULL, `ifOutNUcastPkts_rate` int(11) DEFAULT NULL, `ifInDiscards` bigint(20) DEFAULT NULL, `ifInDiscards_prev` bigint(20) DEFAULT NULL, `ifInDiscards_delta` bigint(20) DEFAULT NULL, `ifInDiscards_rate` int(11) DEFAULT NULL, `ifOutDiscards` bigint(20) DEFAULT NULL, `ifOutDiscards_prev` bigint(20) DEFAULT NULL, `ifOutDiscards_delta` bigint(20) DEFAULT NULL, `ifOutDiscards_rate` int(11) DEFAULT NULL, `ifInUnknownProtos` bigint(20) DEFAULT NULL, `ifInUnknownProtos_prev` bigint(20) DEFAULT NULL, `ifInUnknownProtos_delta` bigint(20) DEFAULT NULL, `ifInUnknownProtos_rate` int(11) DEFAULT NULL, `ifInBroadcastPkts` bigint(20) DEFAULT NULL, `ifInBroadcastPkts_prev` bigint(20) DEFAULT NULL, `ifInBroadcastPkts_delta` bigint(20) DEFAULT NULL, `ifInBroadcastPkts_rate` int(11) DEFAULT NULL, `ifOutBroadcastPkts` bigint(20) DEFAULT NULL, `ifOutBroadcastPkts_prev` bigint(20) DEFAULT NULL, `ifOutBroadcastPkts_delta` bigint(20) DEFAULT NULL, `ifOutBroadcastPkts_rate` int(11) DEFAULT NULL, `ifInMulticastPkts` bigint(20) DEFAULT NULL, `ifInMulticastPkts_prev` bigint(20) DEFAULT NULL, `ifInMulticastPkts_delta` bigint(20) DEFAULT NULL, `ifInMulticastPkts_rate` int(11) DEFAULT NULL, `ifOutMulticastPkts` bigint(20) DEFAULT NULL, `ifOutMulticastPkts_prev` bigint(20) DEFAULT NULL, `ifOutMulticastPkts_delta` bigint(20) DEFAULT NULL, `ifOutMulticastPkts_rate` int(11) DEFAULT NULL, PRIMARY KEY (`port_id`)) ENGINE=InnoDB; From 1ee481ff6ebd8163bc9536d88c7a43f69313cb90 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Thu, 3 Dec 2015 09:40:30 -0700 Subject: [PATCH 07/10] Rename option to extended_port_metrics --- includes/defaults.inc.php | 2 +- includes/polling/ports.inc.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 1c0664ad8d..65918f2954 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -77,7 +77,7 @@ $config['memcached']['host'] = 'localhost'; $config['memcached']['port'] = 11211; $config['memcached']['ttl'] = 240; -$config['enable_extended_port_metrics'] = false; +$config['extended_port_metrics'] = false; $config['slow_statistics'] = true; // THIS WILL CHANGE TO FALSE IN FUTURE // RRD Format Settings diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index da7a2c6df5..b0e11fa248 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -216,7 +216,7 @@ d_echo($port_stats); // FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :> // -- i can make it a function, so that you don't know what it's doing. // -- $ports = adamasMagicFunction($ports_db); ? -if ($config['enable_extended_port_metrics']) { +if ($config['extended_port_metrics']) { // select * doesn't do what we want if multiple tables have the same column name -- last one wins :/ $ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id'])); } @@ -234,7 +234,7 @@ foreach ($port_stats as $ifIndex => $port) { echo 'valid'; if (!is_array($ports[$port['ifIndex']])) { $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports'); - if ($config['enable_extended_port_metrics']) { + if ($config['extended_port_metrics']) { dbInsert(array('port_id' => $port_id), 'ports_statistics'); } $ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id)); @@ -245,7 +245,7 @@ foreach ($port_stats as $ifIndex => $port) { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id'])); $ports[$ifIndex]['deleted'] = '0'; } - if ($config['enable_extended_port_metrics'] && + if ($config['extended_port_metrics'] && $ports[$ifIndex]['ports_statistics_port_id'] === null) { // in case someone enabled the option after the port was already created dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics'); @@ -431,12 +431,12 @@ foreach ($ports as $port) { // End parse ifAlias // Update IF-MIB metrics $_stat_oids = $stat_oids_db; - if ($config['enable_extended_port_metrics']) { + if ($config['extended_port_metrics']) { $_stat_oids = $_stat_oids + $stat_oids_db_extended; } foreach ($_stat_oids as $oid) { $port_update = 'update'; - if ($config['enable_extended_port_metrics']) { + if ($config['extended_port_metrics']) { $extended_metric = !in_array($oid, $stat_oids_db, true); if ($extended_metric) { $port_update = 'update_extended'; @@ -587,7 +587,7 @@ foreach ($ports as $port) { // Update Database if (count($port['update'])) { $updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id'])); - if ($config['enable_extended_port_metrics'] and count($port['update_extended'])) { + if ($config['extended_port_metrics'] and count($port['update_extended'])) { // do we want to do something else with this? $updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id'])); } From 81d84e0f8b0d47ba84d4800c364b840b81770942 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Tue, 8 Dec 2015 09:54:31 -0700 Subject: [PATCH 08/10] Always add 'extended' metrics to db and remove option --- includes/defaults.inc.php | 1 - includes/polling/ports.inc.php | 37 ++++++++++------------------------ 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 65918f2954..0e936861b7 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -77,7 +77,6 @@ $config['memcached']['host'] = 'localhost'; $config['memcached']['port'] = 11211; $config['memcached']['ttl'] = 240; -$config['extended_port_metrics'] = false; $config['slow_statistics'] = true; // THIS WILL CHANGE TO FALSE IN FUTURE // RRD Format Settings diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index b0e11fa248..6b382bf68b 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -216,13 +216,8 @@ d_echo($port_stats); // FIXME -- this stuff is a little messy, looping the array to make an array just seems wrong. :> // -- i can make it a function, so that you don't know what it's doing. // -- $ports = adamasMagicFunction($ports_db); ? -if ($config['extended_port_metrics']) { - // select * doesn't do what we want if multiple tables have the same column name -- last one wins :/ - $ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id'])); -} -else { - $ports_db = dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); -} +// select * doesn't do what we want if multiple tables have the same column name -- last one wins :/ +$ports_db = dbFetchRows('SELECT *, `ports_statistics`.`port_id` AS `ports_statistics_port_id`, `ports`.`port_id` AS `port_id` FROM `ports` LEFT OUTER JOIN `ports_statistics` ON `ports`.`port_id` = `ports_statistics`.`port_id` WHERE `ports`.`device_id` = ?', array($device['device_id'])); foreach ($ports_db as $port) { $ports[$port['ifIndex']] = $port; @@ -234,9 +229,7 @@ foreach ($port_stats as $ifIndex => $port) { echo 'valid'; if (!is_array($ports[$port['ifIndex']])) { $port_id = dbInsert(array('device_id' => $device['device_id'], 'ifIndex' => $ifIndex), 'ports'); - if ($config['extended_port_metrics']) { - dbInsert(array('port_id' => $port_id), 'ports_statistics'); - } + dbInsert(array('port_id' => $port_id), 'ports_statistics'); $ports[$port['ifIndex']] = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', array($port_id)); echo 'Adding: '.$port['ifName'].'('.$ifIndex.')('.$ports[$port['ifIndex']]['port_id'].')'; // print_r($ports); @@ -245,9 +238,8 @@ foreach ($port_stats as $ifIndex => $port) { dbUpdate(array('deleted' => '0'), 'ports', '`port_id` = ?', array($ports[$ifIndex]['port_id'])); $ports[$ifIndex]['deleted'] = '0'; } - if ($config['extended_port_metrics'] && - $ports[$ifIndex]['ports_statistics_port_id'] === null) { - // in case someone enabled the option after the port was already created + if ($ports[$ifIndex]['ports_statistics_port_id'] === null) { + // in case the port was created before we created the table dbInsert(array('port_id' => $ports[$ifIndex]['port_id']), 'ports_statistics'); } } @@ -430,17 +422,12 @@ foreach ($ports as $port) { // End parse ifAlias // Update IF-MIB metrics - $_stat_oids = $stat_oids_db; - if ($config['extended_port_metrics']) { - $_stat_oids = $_stat_oids + $stat_oids_db_extended; - } + $_stat_oids = $stat_oids_db + $stat_oids_db_extended; foreach ($_stat_oids as $oid) { $port_update = 'update'; - if ($config['extended_port_metrics']) { - $extended_metric = !in_array($oid, $stat_oids_db, true); - if ($extended_metric) { - $port_update = 'update_extended'; - } + $extended_metric = !in_array($oid, $stat_oids_db, true); + if ($extended_metric) { + $port_update = 'update_extended'; } if ($config['slow_statistics'] == true) { @@ -587,10 +574,8 @@ foreach ($ports as $port) { // Update Database if (count($port['update'])) { $updated = dbUpdate($port['update'], 'ports', '`port_id` = ?', array($port['port_id'])); - if ($config['extended_port_metrics'] and count($port['update_extended'])) { - // do we want to do something else with this? - $updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id'])); - } + // do we want to do something else with this? + $updated += dbUpdate($port['update_extended'], 'ports_statistics', '`port_id` = ?', array($port['port_id'])); d_echo("$updated updated"); } From bd23d9e56aa8c43259cde4f5e22be85c548062e7 Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Wed, 9 Dec 2015 15:28:13 -0700 Subject: [PATCH 09/10] This isn't the operator you are looking for. Move along. --- includes/polling/ports.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/polling/ports.inc.php b/includes/polling/ports.inc.php index 6b382bf68b..0435bfb6e4 100644 --- a/includes/polling/ports.inc.php +++ b/includes/polling/ports.inc.php @@ -422,7 +422,7 @@ foreach ($ports as $port) { // End parse ifAlias // Update IF-MIB metrics - $_stat_oids = $stat_oids_db + $stat_oids_db_extended; + $_stat_oids = array_merge($stat_oids_db, $stat_oids_db_extended); foreach ($_stat_oids as $oid) { $port_update = 'update'; $extended_metric = !in_array($oid, $stat_oids_db, true); From bf501c66673d90c4452c4325f8319288ac212b6f Mon Sep 17 00:00:00 2001 From: Eldon Koyle Date: Wed, 9 Dec 2015 15:33:15 -0700 Subject: [PATCH 10/10] Bump schema to 082 as 081 has been used --- sql-schema/{081.sql => 082.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sql-schema/{081.sql => 082.sql} (100%) diff --git a/sql-schema/081.sql b/sql-schema/082.sql similarity index 100% rename from sql-schema/081.sql rename to sql-schema/082.sql