Cacti/plugin_syslog

Wrong column specification on cleanup query

Closed this issue · 1 comments

One line is missing from function.php, and give this error:

31/05/2022 13:29:06 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_process.php[156]:syslog_preprocess_incoming_records(), /plugins/syslog/functions.php[1683]:syslog_strip_incoming_domains(), /plugins/syslog/functions.php[1707]:syslog_db_execute(), /plugins/syslog/database.php[69]:db_execute(), /lib/database.php[272]:db_execute_prepared())
31/05/2022 13:29:06 - CMDPHP ERROR: A DB Exec Failed!, Error: Incorrect database name ''
31/05/2022 13:29:06 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/syslog/syslog_process.php[156]:syslog_preprocess_incoming_records(), /plugins/syslog/functions.php[1683]:syslog_strip_incoming_domains(), /plugins/syslog/functions.php[1704]:CactiErrorHandler())
31/05/2022 13:29:06 - ERROR PHP NOTICE in Plugin 'syslog': Undefined variable: syslogdb_default in file: /usr/share/cacti/plugins/syslog/functions.php on line: 1704
31/05/2022 13:29:06 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_process.php[156]:syslog_preprocess_incoming_records(), /plugins/syslog/functions.php[1683]:syslog_strip_incoming_domains(), /plugins/syslog/functions.php[1707]:syslog_db_execute(), /plugins/syslog/database.php[69]:db_execute(), /lib/database.php[272]:db_execute_prepared())
31/05/2022 13:29:06 - CMDPHP ERROR: A DB Exec Failed!, Error: Incorrect database name ''
31/05/2022 13:29:06 - CMDPHP PHP ERROR NOTICE Backtrace: (/plugins/syslog/syslog_process.php[156]:syslog_preprocess_incoming_records(), /plugins/syslog/functions.php[1683]:syslog_strip_incoming_domains(), /plugins/syslog/functions.php[1704]:CactiErrorHandler())
31/05/2022 13:29:06 - ERROR PHP NOTICE in Plugin 'syslog': Undefined variable: syslogdb_default in file: /usr/share/cacti/plugins/syslog/functions.php on line: 1704

You should add this on 1699:
global $syslogdb_default;

it's missing on the
function syslog_strip_incoming_domains($uniqueID)

And you have a mistake on the table you try to reach in line 1707 (before the change I propose)

function syslog_strip_incoming_domains($uniqueID) {
$syslog_domains = read_config_option('syslog_domains');
if ($syslog_domains != '') {
$domains = explode(',', trim($syslog_domains));
foreach($domains as $domain) {
syslog_db_execute('UPDATE ' . $syslogdb_default . ".syslog_incoming
SET host = SUBSTRING_INDEX(host, '.', 1)
WHERE host LIKE '%$domain'
AND uniqueID = $uniqueID");
}
}
}

You try to access the field uniqueID in syslog_incoming table, but that field didn't exist.

If I look on setup.php, the creation of the table contain only the following field:

        facility_id int(10) unsigned default NULL,
	priority_id int(10) unsigned default NULL,
	program varchar(40) default NULL,
	logtime TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
	host varchar(64) default NULL,
	message varchar(2048) NOT NULL DEFAULT '',
	seq bigint unsigned NOT NULL auto_increment,
	`status` tinyint(4) NOT NULL default '0',

And that give this error:

31/05/2022 13:47:06 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_process.php[156]:syslog_preprocess_incoming_records(), /plugins/syslog/functions.php[1683]:syslog_strip_incoming_domains(), /plugins/syslog/functions.php[1708]:syslog_db_execute(), /plugins/syslog/database.php[69]:db_execute(), /lib/database.php[272]:db_execute_prepared())
31/05/2022 13:47:06 - CMDPHP ERROR: A DB Exec Failed!, Error: Unknown column 'uniqueID' in 'where clause'
31/05/2022 13:47:06 - CMDPHP SQL Backtrace: (/plugins/syslog/syslog_process.php[156]:syslog_preprocess_incoming_records(), /plugins/syslog/functions.php[1683]:syslog_strip_incoming_domains(), /plugins/syslog/functions.php[1708]:syslog_db_execute(), /plugins/syslog/database.php[69]:db_execute(), /lib/database.php[272]:db_execute_prepared())
31/05/2022 13:47:06 - CMDPHP ERROR: A DB Exec Failed!, Error: Unknown column 'uniqueID' in 'where clause'

For what I saw, you are using the status field of the table to store the uniqueID of the record, is that correct ?

PS: I try to use the 'add code' on this git hub page, but it screw the paging, sorry if the code is not easy to read!

Fixed now