|
| 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