Skip to content

Commit 0b1d564

Browse files
fix: correct host/program alert status placeholders
Refs Cacti#266 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 869c035 commit 0b1d564

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

.github/workflows/plugin-ci-workflow.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ jobs:
187187
echo "Syntax errors found!"
188188
exit 1
189189
fi
190+
191+
- name: Run Plugin Regression Tests
192+
run: |
193+
cd ${{ github.workspace }}/cacti/plugins/syslog
194+
if [ -d tests/regression ]; then
195+
for test in tests/regression/*.php; do
196+
[ -f "$test" ] || continue
197+
php "$test"
198+
done
199+
fi
190200
191201

192202
- name: Run Cacti Poller

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
--- develop ---
44

55
* issue#250: Fix date filter persistence by validating before shift_span detection
6+
* issue#253: Correct host/program alert SQL placeholder handling
67
* issue: Making changes to support Cacti 1.3
78
* issue: Don't use MyISAM for non-analytical tables
89
* issue: The install advisor for Syslog was broken in current Cacti releases

functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,15 +1667,15 @@ function syslog_get_alert_sql(&$alert, $uniqueID) {
16671667
$sql = 'SELECT *
16681668
FROM `' . $syslogdb_default . '`.`syslog_incoming`
16691669
WHERE `' . $syslog_incoming_config['hostField'] . '` = ?
1670-
AND `status` = ?' . $uniqueID;
1670+
AND `status` = ?';
16711671

16721672
$params[] = $alert['message'];
16731673
$params[] = $uniqueID;
16741674
} elseif ($alert['type'] == 'program') {
16751675
$sql = 'SELECT *
16761676
FROM `' . $syslogdb_default . '`.`syslog_incoming`
16771677
WHERE `' . $syslog_incoming_config['programField'] . '` = ?
1678-
AND `status` = ?' . $uniqueID;
1678+
AND `status` = ?';
16791679

16801680
$params[] = $alert['message'];
16811681
$params[] = $uniqueID;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
$GLOBALS['syslogdb_default'] = 'syslogdb';
4+
$GLOBALS['syslog_incoming_config'] = array(
5+
'hostField' => 'host',
6+
'programField' => 'program',
7+
'facilityField'=> 'facility',
8+
'textField' => 'message'
9+
);
10+
11+
require_once dirname(__DIR__, 2) . '/functions.php';
12+
13+
function issue253_assert($condition, $message) {
14+
if (!$condition) {
15+
fwrite(STDERR, $message . "\n");
16+
exit(1);
17+
}
18+
}
19+
20+
$hostAlert = array(
21+
'type' => 'host',
22+
'message' => 'router1'
23+
);
24+
25+
$programAlert = array(
26+
'type' => 'program',
27+
'message' => 'sshd'
28+
);
29+
30+
$hostSql = syslog_get_alert_sql($hostAlert, 55);
31+
$progSql = syslog_get_alert_sql($programAlert, 66);
32+
33+
issue253_assert(strpos($hostSql['sql'], "AND `status` = ?") !== false, 'Host alert SQL must keep status as a placeholder.');
34+
issue253_assert(strpos($hostSql['sql'], '?55') === false, 'Host alert SQL must not concatenate uniqueID into SQL text.');
35+
issue253_assert(count($hostSql['params']) === 2, 'Host alert SQL must pass two prepared parameters.');
36+
issue253_assert($hostSql['params'][1] === 55, 'Host alert status param should be the uniqueID.');
37+
38+
issue253_assert(strpos($progSql['sql'], "AND `status` = ?") !== false, 'Program alert SQL must keep status as a placeholder.');
39+
issue253_assert(strpos($progSql['sql'], '?66') === false, 'Program alert SQL must not concatenate uniqueID into SQL text.');
40+
issue253_assert(count($progSql['params']) === 2, 'Program alert SQL must pass two prepared parameters.');
41+
issue253_assert($progSql['params'][1] === 66, 'Program alert status param should be the uniqueID.');
42+
43+
echo "issue253_alert_sql_placeholder_test passed\n";

0 commit comments

Comments
 (0)