Skip to content

Commit be8ba75

Browse files
committed
Fixing Issue #107
Removal rule not using correct DB when using $use_cacti_db = false;
1 parent b195157 commit be8ba75

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ that.
160160
* issue#104: When filtering, syslog incorrectly thinks the Cacti hosts table
161161
does not exist
162162

163+
* issue#107: Removal rule not using correct DB when using $use_cacti_db = false;
164+
163165
--- 2.5 ---
164166

165167
* issue#103: Allow syslog to use rsyslog new tizezone sensitive timestamps

functions.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,17 @@ function sql_hosts_where($tab) {
578578
$hostfilter_log = '';
579579
$hosts_array = array();
580580

581+
include(dirname(__FILE__) . '/config.php');
582+
581583
if (!isempty_request_var('host') && get_nfilter_request_var('host') != 'null') {
582584
$hostarray = explode(',', trim(get_nfilter_request_var('host')));
583585
if ($hostarray[0] != '0') {
584586
foreach($hostarray as $host_id) {
585587
input_validate_input_number($host_id);
586588

587589
if ($host_id > 0) {
588-
$log_host = db_fetch_cell_prepared('SELECT host
589-
FROM syslog_hosts
590+
$log_host = syslog_db_fetch_cell_prepared('SELECT host
591+
FROM `' . $syslogdb_default . '`.`syslog_hosts`
590592
WHERE host_id = ?',
591593
array($host_id));
592594

@@ -802,12 +804,12 @@ function syslog_manage_items($from_table, $to_table) {
802804
if ($remove['method'] != 'del') {
803805
$sql_sel = "SELECT seq FROM `" . $syslogdb_default . "`. $from_table
804806
WHERE facility_id IN
805-
(SELECT distinct facility_id from `". $syslogdb_default . "`syslog_facilities
807+
(SELECT distinct facility_id FROM `". $syslogdb_default . "`syslog_facilities
806808
WHERE facility ='". $remove['message']."')";
807809
} else {
808810
$sql_dlt = "DELETE FROM `" . $syslogdb_default . "`. $from_table
809811
WHERE facility_id IN
810-
(SELECT distinct facility_id from `". $syslogdb_default . "`syslog_facilities
812+
(SELECT distinct facility_id FROM `". $syslogdb_default . "`syslog_facilities
811813
WHERE facility ='". $remove['message']."')";
812814
}
813815

@@ -816,12 +818,12 @@ function syslog_manage_items($from_table, $to_table) {
816818
$sql_sel = "SELECT seq
817819
FROM `" . $syslogdb_default . "`. $from_table
818820
WHERE host_id in
819-
(SELECT distinct host_id from `". $syslogdb_default . "`syslog_hosts
821+
(SELECT distinct host_id FROM `". $syslogdb_default . "`syslog_hosts
820822
WHERE host ='". $remove['message']."')";
821823
} else {
822824
$sql_dlt = "DELETE FROM `" . $syslogdb_default . "`. $from_table
823825
WHERE host_id in
824-
(SELECT distinct host_id from `". $syslogdb_default . "`syslog_hosts
826+
(SELECT distinct host_id FROM `". $syslogdb_default . "`syslog_hosts
825827
WHERE host ='". $remove['message']."')";
826828
}
827829
} elseif ($remove['type'] == 'messageb') {

syslog.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ function get_stats_records(&$sql_where, &$sql_groupby, $rows) {
420420

421421
function syslog_stats_filter() {
422422
global $config, $item_rows;
423+
424+
include(dirname(__FILE__) . '/config.php');
425+
423426
?>
424427
<tr class='even'>
425428
<td>
@@ -435,7 +438,7 @@ function syslog_stats_filter() {
435438
<option value='-2'<?php if (get_request_var('host') == '-2') { ?> selected<?php } ?>><?php print __('None', 'syslog');?></option>
436439
<?php
437440
$hosts = syslog_db_fetch_assoc('SELECT DISTINCT sh.host_id, sh.host, h.id
438-
FROM syslog_hosts AS sh
441+
FROM `' . $syslogdb_default . '`.`syslog_hosts` AS sh
439442
LEFT JOIN host AS h
440443
ON sh.host = h.hostname
441444
OR sh.host = h.description
@@ -466,7 +469,7 @@ function syslog_stats_filter() {
466469
<option value='-2'<?php if (get_request_var('facility') == '-2') { ?> selected<?php } ?>><?php print __('None', 'syslog');?></option>
467470
<?php
468471
$facilities = syslog_db_fetch_assoc('SELECT DISTINCT facility_id, facility
469-
FROM syslog_facilities AS sf
472+
FROM `' . $syslogdb_default . '`.`syslog_facilities` AS sf
470473
ORDER BY facility');
471474

472475
if (cacti_sizeof($facilities)) {
@@ -486,7 +489,7 @@ function syslog_stats_filter() {
486489
<option value='-2'<?php if (get_request_var('priority') == '-2') { ?> selected<?php } ?>><?php print __('None', 'syslog');?></option>
487490
<?php
488491
$priorities = syslog_db_fetch_assoc('SELECT DISTINCT priority_id, priority
489-
FROM syslog_priorities AS sp
492+
FROM `' . $syslogdb_default . '`.`syslog_priorities` AS sp
490493
ORDER BY priority');
491494

492495
if (cacti_sizeof($priorities)) {
@@ -820,7 +823,7 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {
820823
if ($thold_pos !== false) {
821824
$ids = array_rekey(
822825
syslog_db_fetch_assoc('SELECT id
823-
FROM syslog_alert
826+
FROM `' . $syslogdb_default . '`.`syslog_alert`
824827
WHERE method = 1'),
825828
'id', 'id'
826829
);
@@ -981,7 +984,7 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {
981984
}
982985

983986
function syslog_filter($sql_where, $tab) {
984-
global $config, $graph_timespans, $graph_timeshifts, $reset_multi, $page_refresh_interval, $item_rows, $trimvals, $syslogdb_default, $database_default;
987+
global $config, $graph_timespans, $graph_timeshifts, $reset_multi, $page_refresh_interval, $item_rows, $trimvals;
985988

986989
include(dirname(__FILE__) . '/config.php');
987990

@@ -1318,8 +1321,8 @@ function timeshiftFilterRight() {
13181321
$hosts_where = api_plugin_hook_function('syslog_hosts_where', $hosts_where);
13191322

13201323
$hosts = syslog_db_fetch_assoc("SELECT sh.host_id, sh.host, h.id
1321-
FROM `$syslogdb_default`.`syslog_hosts` AS sh
1322-
LEFT JOIN `$database_default`.host AS h
1324+
FROM `" . $syslogdb_default . "`.`syslog_hosts` AS sh
1325+
LEFT JOIN host AS h
13231326
ON sh.host = h.hostname
13241327
OR sh.host = h.description
13251328
OR sh.host LIKE substring_index(h.hostname, '.', 1)

0 commit comments

Comments
 (0)