Cacti / plugin_flowview

FlowView Plugin for Cacti
GNU General Public License v2.0
18 stars 10 forks source link

Invalid Index in functions.php line 2697 #140

Closed gcrumb closed 2 weeks ago

gcrumb commented 2 weeks ago

Describe the bug Flowview throws a PHP errror when the plugin is loaded via the Flowview tab in Cacti when the protocol value is missing from a netflow response.

Pulling data from softflowd installed on an OpenWRT router via port 2555.

Listener is configured to listen to 0.0.0.0:2555

To Reproduce Steps to reproduce the behavior:

  1. Load the Flowview tab in Cacti. No data displays.
  2. Check the logs:

024-06-20 11:02:57 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview.php[68]:load_data_for_filter(), /plugins/flowview/functions.php[1634]:run_flow_query(), /plugins/flowview/functions.php[2693]:CactiErrorHandler())

2024-06-20 11:02:57 - ERROR PHP NOTICE in Plugin 'flowview': Undefined index: protocol in file: /srv/websites/slideshows/cacti/plugins/flowview/functions.php on line: 2693 2024-06-20 11:02:57 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview.php[68]:load_data_for_filter(), /plugins/flowview/functions.php[1634]:run_flow_query(), /plugins/flowview/functions.php[2697]:CactiErrorHandler()) 2024-06-20 11:02:57 - ERROR PHP NOTICE in Plugin 'flowview': Undefined index: protocol in file: /srv/websites/slideshows/cacti/plugins/flowview/functions.php on line: 2697

The lines in question are:

if (isset($r['src_port'])) { $table .= '' . get_port_name($r['src_port'], $r['protocol']) . ''; }

and:

if (isset($r['dst_port'])) { $table .= '' . get_port_name($r['src_port'], $r['protocol']) . ''; }

Problem is that $r['protocol'] is undefined.

Testing for a value fixes the problem:

                                    if (isset($r['src_port'])) {
                                            if (isset($r['protocol'])){
                                                    $table .= '<td class="left nowrap">' . get_port_name($r['src_port'], $r['protocol']) . '</td>';
                                            }
                                            else {
                                                    $table .= '<td class="left nowrap">' . get_port_name($r['src_port'], 'unknown') . '</td>';
                                            }
                                    }

                                    if (isset($r['dst_port'])) {
                                            if (isset($r['protocol'])){
                                                    $table .= '<td class="left nowrap">' . get_port_name($r['dst_port'], $r['protocol']) . '</td>';
                                            }
                                            else {
                                                    $table .= '<td class="left nowrap">' . get_port_name($r['dst_port'], 'unknown') . '</td>';
                                            }
                                    }
gcrumb commented 2 weeks ago

Running the debian package of Cacti on PHP 7.2 on Linux Mint 19.3 Tricia.

Flowview installed from source via git pull https://github.com/Cacti/plugin_flowview/

TheWitness commented 2 weeks ago

This is fixed in the latest Cacti develop. It's a big change right now. That bug was just fixed 2 days ago I think.

https://github.com/Cacti/plugin_flowview/commit/0eabfadea1cf64f7f76a1ba431549066d5b471b5

TheWitness commented 2 weeks ago

There is still a bit of work taking place on this plugin. But hop on and come along for the ride. I'm asking for some screen shots of V9 and IPFIX Template output in #111

gcrumb commented 2 weeks ago

Timing is everything, I guess. Thanks!

I'll grab the dev release in a bit and see if I can find more stuff.

TheWitness commented 2 weeks ago

You will want to run "php flowview_upgrade.php --forcever=3.3" which will do a background upgrade. Then, restart flow-capture. Also, we have added a requirement that flow-capture run as the web server account. It's a small change the the systemd units file. After which, you have to run the following:

systemctl stop flow-capture
systemctl daemon-reload
systemctl start flow-capture
gcrumb commented 2 weeks ago

Upgraded as described above. No visible problems, but the following in the Cacti log:

2024-06-20 11:56:05 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[271]:CactiErrorHandler())

2024-06-20 11:56:05 - ERROR PHP NOTICE in Plugin 'flowview': Undefined variable: info in file: /srv/websites/slideshows/cacti/plugins/flowview/flowview_upgrade.php on line: 271 2024-06-20 11:56:05 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[270]:CactiErrorHandler()) 2024-06-20 11:56:05 - ERROR PHP NOTICE in Plugin 'flowview': Undefined variable: info in file: /srv/websites/slideshows/cacti/plugins/flowview/flowview_upgrade.php on line: 270 2024-06-20 11:56:05 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[269]:CactiErrorHandler()) 2024-06-20 11:56:05 - ERROR PHP NOTICE in Plugin 'flowview': Undefined variable: info in file: /srv/websites/slideshows/cacti/plugins/flowview/flowview_upgrade.php on line: 269 2024-06-20 11:56:05 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[268]:CactiErrorHandler()) 2024-06-20 11:56:05 - ERROR PHP NOTICE in Plugin 'flowview': Undefined variable: info in file: /srv/websites/slideshows/cacti/plugins/flowview/flowview_upgrade.php on line: 268 2024-06-20 11:56:05 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[267]:CactiErrorHandler()) 2024-06-20 11:56:05 - ERROR PHP NOTICE in Plugin 'flowview': Undefined variable: info in file: /srv/websites/slideshows/cacti/plugins/flowview/flowview_upgrade.php on line: 267

gcrumb commented 2 weeks ago

And further down:

024-06-20 11:56:00 - CMDPHP SQL Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[225]:flowview_db_execute(), /plugins/flowview/database.php[69]:db_execute(), /lib/database.php[385]:db_execute_prepared())

2024-06-20 11:56:00 - CMDPHP ERROR: A DB Exec Failed!, Error: Duplicate column name 'last_updated' 2024-06-20 11:56:00 - DBCALL ERROR: A DB Exec Failed!, Error: 1060, SQL: 'ALTER TABLE plugin_flowview_devices ADD COLUMN last_updated TIMESTAMP NOT NULL default CURRENT_TIMESTAMP' 2024-06-20 11:56:00 - CMDPHP SQL Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[224]:flowview_db_column_exists(), /plugins/flowview/database.php[334]:db_column_exists(), /lib/database.php[1124]:db_fetch_cell(), /lib/database.php[576]:db_fetch_cell_prepared(), /lib/database.php[598]:db_execute_prepared()) 2024-06-20 11:56:00 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.plugin_flowview_deivces' doesn't exist 2024-06-20 11:56:00 - DBCALL ERROR: A DB Cell Failed!, Error: 1146, SQL: 'SHOW columns FROM plugin_flowview_deivces LIKE 'last_updated'' 2024-06-20 11:56:00 - CMDPHP SQL Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[220]:flowview_db_execute(), /plugins/flowview/database.php[69]:db_execute(), /lib/database.php[385]:db_execute_prepared()) 2024-06-20 11:56:00 - CMDPHP ERROR: A DB Exec Failed!, Error: Table 'cacti.plugin_flowview_deivce_templates' doesn't exist 2024-06-20 11:56:00 - DBCALL ERROR: A DB Exec Failed!, Error: 1146, SQL: 'ALTER TABLE plugin_flowview_deivce_templates ADD COLUMN supported tinyint unsigned NOT NULL default "0" AFTER template_id' 2024-06-20 11:56:00 - CMDPHP SQL Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[219]:flowview_db_column_exists(), /plugins/flowview/database.php[334]:db_column_exists(), /lib/database.php[1124]:db_fetch_cell(), /lib/database.php[576]:db_fetch_cell_prepared(), /lib/database.php[598]:db_execute_prepared()) 2024-06-20 11:56:00 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.plugin_flowview_deivce_templates' doesn't exist 2024-06-20 11:56:00 - DBCALL ERROR: A DB Cell Failed!, Error: 1146, SQL: 'SHOW columns FROM plugin_flowview_deivce_templates LIKE 'supported'' 2024-06-20 11:56:00 - CMDPHP SQL Backtrace: (/plugins/flowview/flowview_upgrade.php[88]:flowview_upgrade(), /plugins/flowview/flowview_upgrade.php[207]:flowview_db_execute(), /plugins/flowview/database.php[69]:db_execute(), /lib/database.php[385]:db_execute_prepared()) 2024-06-20 11:56:00 - CMDPHP ERROR: A DB Exec Failed!, Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'column_spec blob default '', last_updated timestamp NOT NULL default CURRENT_TIM' at line 1 2024-06-20 11:56:00 - DBCALL ERROR: A DB Exec Failed!, Error: 1064, SQL: 'CREATE TABLE IF NOT EXISTS cacti.plugin_flowview_device_templates ( device_id int(11) unsigned NOT NULL default '0', ext_addr varchar(32) NOT NULL default '', template_id int(11) unsigned NOT NULL default '0', supported tinyint unsigned NOT NULL default '0' column_spec blob default '', last_updated timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (device_id, ext_addr, template_id)) ENGINE=InnoDB, ROW_FORMAT=DYNAMIC, COMMENT='Plugin Flowview - List of Stream Templates coming into each of the listeners''

TheWitness commented 2 weeks ago

Working on that INFO issue. What version of MariaDB/MySQL are you running.

gcrumb commented 2 weeks ago

mysql Ver 14.14 Distrib 5.7.42, for Linux (x86_64) using EditLine wrapper

TheWitness commented 2 weeks ago

Have you considered upgrading MySQL or switching to MariaDB? I'm thinking it should work. Edit the setup.php file and try to manually create the missing tables. Let me know if there are any errors.

TheWitness commented 2 weeks ago

@gcrumb anything?

gcrumb commented 2 weeks ago

Sorry, traveling at the moment. Everything seems to be fine. The flows are being captured and no further errors generated.

I won't get a chance to review the whole config or make further changes for a couple of weeks.

TheWitness commented 2 weeks ago

Yea, I was pretty sure that this was an issue with upgrading while streams were collecting. So, I've added some process interlocks. Commit that on Saturday as there will be more schema changes before I'm done. Closing this now.