Skip to content

Commit 704c4ac

Browse files
committed
Resolving Issue #90
Can not show correct info when choose device filter in Syslog - Alert Log page
1 parent e3ddbb6 commit 704c4ac

5 files changed

Lines changed: 68 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The sylog plugin has been in development for well over a decade with increasing
7878
## ChangeLog
7979

8080
--- develop ---
81+
* issue#90: Can not show correct info when choose device filter in Syslog - Alert Log page
8182
* issue#91: Page become blank after collecting multiple host syslog info
8283
* issue#94: Stored XSS in syslog_removal.php
8384

functions.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ function sql_hosts_where($tab) {
582582

583583
$hostfilter = '';
584584
$hostfilter_log = '';
585+
$hosts_array = array();
585586

586587
if (!isempty_request_var('host') && get_nfilter_request_var('host') != 'null') {
587588
$hostarray = explode(',', trim(get_nfilter_request_var('host')));
@@ -596,11 +597,15 @@ function sql_hosts_where($tab) {
596597
array($host_id));
597598

598599
if (!empty($log_host)) {
599-
$hostfilter_log .= ($hostfilter_log != '' ? ' AND ':'') . 'host = ' . db_qstr($log_host);
600+
$hosts_array[] = db_qstr($log_host);
600601
}
601602
}
602603
}
603604

605+
if (sizeof($hosts_array)) {
606+
$hostfilter_log = ' host IN(' . implode(',', $hosts_array) . ')';
607+
}
608+
604609
$hostfilter .= (strlen($hostfilter) ? ' AND ':'') . ' host_id IN(' . implode(',', $hostarray) . ')';
605610
}
606611
}

setup.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,13 +1176,34 @@ function syslog_utilities_action($action) {
11761176
if ($action == 'purge_syslog_hosts') {
11771177
$records = 0;
11781178

1179-
syslog_db_execute('DELETE FROM syslog_hosts WHERE host_id NOT IN (SELECT DISTINCT host_id FROM syslog UNION SELECT DISTINCT host_id FROM syslog_removed)');
1179+
syslog_db_execute('DELETE FROM syslog_hosts
1180+
WHERE host_id NOT IN (
1181+
SELECT DISTINCT host_id
1182+
FROM syslog
1183+
UNION
1184+
SELECT DISTINCT host_id
1185+
FROM syslog_removed
1186+
)');
11801187
$records += db_affected_rows($syslog_cnn);
11811188

1182-
syslog_db_execute('DELETE FROM syslog_host_facilities WHERE host_id NOT IN (SELECT DISTINCT host_id FROM syslog UNION SELECT DISTINCT host_id FROM syslog_removed)');
1189+
syslog_db_execute('DELETE FROM syslog_host_facilities
1190+
WHERE host_id NOT IN (
1191+
SELECT DISTINCT host_id
1192+
FROM syslog
1193+
UNION
1194+
SELECT DISTINCT host_id
1195+
FROM syslog_removed
1196+
)');
11831197
$records += db_affected_rows($syslog_cnn);
11841198

1185-
syslog_db_execute('DELETE FROM syslog_statistics WHERE host_id NOT IN (SELECT DISTINCT host_id FROM syslog UNION SELECT DISTINCT host_id FROM syslog_removed)');
1199+
syslog_db_execute('DELETE FROM syslog_statistics
1200+
WHERE host_id NOT IN (
1201+
SELECT DISTINCT host_id
1202+
FROM syslog
1203+
UNION
1204+
SELECT DISTINCT host_id
1205+
FROM syslog_removed
1206+
)');
11861207
$records += db_affected_rows($syslog_cnn);
11871208

11881209
raise_message('syslog_info', __('There were %s Device records removed from the Syslog database', $records, 'syslog'), MESSAGE_LEVEL_INFO);

syslog.php

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -774,31 +774,40 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {
774774

775775
$sql_where = '';
776776

777-
if (get_request_var('host') == 0 && $tab != 'syslog') {
778-
// Show all hosts
779-
} elseif (strpos(get_request_var('host'), '-1') !== false && $tab != 'syslog') {
780-
// Show threshold type only plus matching hosts if any
781-
$hosts = explode(',', get_request_var('host'));
777+
if ($tab == 'alerts') {
778+
if (get_request_var('host') == 0) {
779+
// Show all hosts
780+
} else {
781+
$hosts = explode(',', get_request_var('host'));
782782

783-
if (cacti_sizeof($hosts) > 1) {
784-
sql_hosts_where($tab);
783+
$thold_pos = array_search('-1', $hosts, true);
785784

786-
if (strlen($hostfilter_log)) {
787-
$sql_where .= 'WHERE ' . $hostfilter_log;
785+
if ($thold_pos !== false) {
786+
unset($hosts[$thold_pos]);
788787
}
789-
}
790788

791-
$ids = array_rekey(
792-
syslog_db_fetch_assoc('SELECT id
793-
FROM syslog_alert
794-
WHERE method = 1'),
795-
'id', 'id'
796-
);
789+
if (sizeof($hosts)) {
790+
sql_hosts_where($tab);
797791

798-
if (cacti_sizeof($ids)) {
799-
$sql_where .= ($sql_where == '' ? 'WHERE ':' AND ') . 'alert_id IN (' . implode(', ', $ids) . ')';
800-
} else {
801-
$sql_where .= ($sql_where == '' ? 'WHERE ':' AND ') . '0 = 1';
792+
if (strlen($hostfilter_log)) {
793+
$sql_where .= 'WHERE ' . $hostfilter_log;
794+
}
795+
}
796+
797+
if ($thold_pos !== false) {
798+
$ids = array_rekey(
799+
syslog_db_fetch_assoc('SELECT id
800+
FROM syslog_alert
801+
WHERE method = 1'),
802+
'id', 'id'
803+
);
804+
805+
if (cacti_sizeof($ids)) {
806+
$sql_where .= ($sql_where == '' ? 'WHERE ':' OR ') . 'alert_id IN (' . implode(', ', $ids) . ')';
807+
} elseif ($sql_where == '') {
808+
$sql_where .= 'WHERE 0 = 1';
809+
}
810+
}
802811
}
803812
} elseif ($tab == 'syslog') {
804813
if (!isempty_request_var('host')) {
@@ -808,8 +817,6 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {
808817
$sql_where .= 'WHERE ' . $hostfilter;
809818
}
810819
}
811-
} elseif (!isempty_request_var('host') && $hostfilter_log != '') {
812-
$sql_where .= 'WHERE ' . $hostfilter_log;
813820
}
814821

815822
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') .
@@ -823,18 +830,18 @@ function get_syslog_messages(&$sql_where, $rows, $tab) {
823830

824831
if (!isempty_request_var('filter')) {
825832
if ($tab == 'syslog') {
826-
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "message LIKE " . db_qstr('%' . get_request_var('filter') . '%');
833+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'message LIKE ' . db_qstr('%' . get_request_var('filter') . '%');
827834
} else {
828-
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "logmsg LIKE " . db_qstr('%' . get_request_var('filter') . '%');
835+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'logmsg LIKE ' . db_qstr('%' . get_request_var('filter') . '%');
829836
}
830837
}
831838

832839
if (get_request_var('eprogram') != '-1') {
833-
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "syslog.program_id = " . db_qstr(get_request_var('eprogram'));
840+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'syslog.program_id = ' . db_qstr(get_request_var('eprogram'));
834841
}
835842

836843
if (get_request_var('efacility') != '-1') {
837-
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . "syslog.facility_id = " . db_qstr(get_request_var('efacility'));
844+
$sql_where .= ($sql_where == '' ? 'WHERE ' : ' AND ') . 'syslog.facility_id = ' . db_qstr(get_request_var('efacility'));
838845
}
839846

840847
if (isset_request_var('epriority') && get_request_var('epriority') != '-1') {

syslog_process.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@
164164
/* get a uniqueID to allow moving of records to done table */
165165
while (1) {
166166
$uniqueID = rand(1, 127);
167-
$count = syslog_db_fetch_cell('SELECT count(*) FROM `' . $syslogdb_default . '`.`syslog_incoming` WHERE status=' . $uniqueID);
167+
168+
$count = syslog_db_fetch_cell('SELECT count(*)
169+
FROM `' . $syslogdb_default . '`.`syslog_incoming`
170+
WHERE status=' . $uniqueID);
168171

169172
if ($count == 0) {
170173
break;

0 commit comments

Comments
 (0)