Cacti / plugin_syslog

Syslog Plugin for Cacti
GNU General Public License v2.0
21 stars 16 forks source link

Wrong database connection is used resulting in missing table errors #155

Closed bmfmancini closed 2 years ago

bmfmancini commented 3 years ago

Hey Guys,

I found the following issue today

When you are importing a XML template to syslog the following error pops up

image

Logs show that the plugin is looking for cacti.syslog instead of the actual DB name

2021-07-13 10:48:24 - DBCALL ERROR: SQL Save on table 'syslog_remove': Table does not exist, unable to save!
2021-07-13 10:48:24 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.syslog_remove' doesn't exist
2021-07-13 10:48:24 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.syslog_remove' doesn't exist
2021-07-13 10:48:24 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.syslog_remove' doesn't exist
2021-07-13 10:48:24 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.syslog_remove' doesn't exist
2021-07-13 10:48:24 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_removal.php[50]:removal_import(), /plugins/syslog/syslog_removal.php[839]:sql_save())
2021-07-13 10:48:24 - DBCALL ERROR: SQL Save on table 'syslog_remove': Table does not exist, unable to save!
2021-07-13 10:48:24 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_removal.php[50]:removal_import(), /plugins/syslog/syslog_removal.php[829]:db_column_exists(), /lib/database.php[852]:db_fetch_cell(), /lib/database.php[411]:db_fetch_cell_prepared(), /lib/database.php[427]:db_execute_prepared())
2021-07-13 10:48:24 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_removal.php[50]:removal_import(), /plugins/syslog/syslog_removal.php[829]:db_column_exists(), /lib/database.php[852]:db_fetch_cell(), /lib/database.php[411]:db_fetch_cell_prepared(), /lib/database.php[427]:db_execute_prepared())
2021-07-13 10:48:24 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_removal.php[50]:removal_import(), /plugins/syslog/syslog_removal.php[829]:db_column_exists(), /lib/database.php[852]:db_fetch_cell(), /lib/database.php[411]:db_fetch_cell_prepared(), /lib/database.php[427]:db_execute_prepared())
2021-07-13 10:48:24 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_removal.php[50]:removal_import(), /plugins/syslog/syslog_removal.php[829]:db_column_exists(), /lib/database.php[852]:db_fetch_cell(), /lib/database.php[411]:db_fetch_cell_prepared(), /lib/database.php[427]:db_execute_prepared())
bmfmancini commented 3 years ago

same type of issue here

https://github.com/Cacti/plugin_syslog/issues/154

bmfmancini commented 3 years ago

Added cacti_debug_backtrace();

to the following function

function api_syslog_removal_save($id, $name, $type, $message, $rmethod, $notes, $enabled) {

got the below output in the logs


2021-07-21 11:22:28 - CMDPHP Backtrace:  (/plugins/syslog/syslog_removal.php[54]:cacti_debug_backtrace())
--
2021-07-21 11:22:28 - CMDPHP SQL Backtrace:   (/plugins/syslog/syslog_removal.php[50]:removal_import(),  /plugins/syslog/syslog_removal.php[842]:sql_save())
2021-07-21 11:22:28 - DBCALL ERROR: SQL Save on table 'syslog_remove': Table does not exist, unable to save!
2021-07-21 11:22:28 - CMDPHP SQL Backtrace:   (/plugins/syslog/syslog_removal.php[50]:removal_import(),  /plugins/syslog/syslog_removal.php[832]:db_column_exists(),  /lib/database.php[852]:db_fetch_cell(),  /lib/database.php[411]:db_fetch_cell_prepared(),  /lib/database.php[427]:db_execute_prepared())
2021-07-21 11:22:28 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.syslog_remove' doesn't exist
2021-07-21 11:22:28 - CMDPHP SQL Backtrace:   (/plugins/syslog/syslog_removal.php[50]:removal_import(),  /plugins/syslog/syslog_removal.php[832]:db_column_exists(),  /lib/database.php[852]:db_fetch_cell(),  /lib/database.php[411]:db_fetch_cell_prepared(),  /lib/database.php[427]:db_execute_prepared())
2021-07-21 11:22:28 - CMDPHP ERROR: A DB Cell Failed!, Error: Table 'cacti.syslog_remove' doesn't exist
2021-07-21 11:22:28 - CMDPHP SQL Backtrace:   (/plugins/syslog/syslog_removal.php[50]:removal_import(),  /plugins/syslog/syslog_removal.php[832]:db_column_exists(),  /lib/database.php[852]:db_fetch_cell(),  /lib/database.php[411]:db_fetch_cell_prepared(),  /lib/database.php[427]:db_execute_prepared())
netniV commented 2 years ago

So I think i've patched this now as

grep db_ * -R | grep -v syslog_db | grep -v db_qstr | grep -v \$syslogdb | grep -v db_affected_rows | grep -v \$syslog_cnn

shows me just stuff that either should be against the default database or works with it.