Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

--- 5.0 ---

* issue#458: Initialize and validate the active tab before saving view defaults, avoiding a TypeError that disables Syslog and stops processing
* issue#459: Explain that SQL Expression rule previews search only queued incoming messages, so an empty preview is not mistaken for an alert-processing failure

* issue#456: Avoid PHP 8.6 deprecation warnings during schema checks by using object IDs for the connection cache key

* issue#440: Remember only a successful table creation (not updates of existing tables) when avoiding repeated schema operations, so schema drift on an existing table, such as a narrowed owner column, is still detected and repaired within the same request
Expand Down
3 changes: 3 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3840,6 +3840,9 @@ function syslog_rule_preview(array $rule, string $rule_type = 'alert', int $rows
}

$result = ['error' => '', 'count' => (int) $count, 'rows' => $out];
if ($rule_type === 'alert' && $type === 'sql') {
$result['notice'] = __('SQL Expression previews check only queued incoming messages. Already processed messages are not searched. Testing does not send alarms.', 'syslog');
}
if ($history) {
$result['history_limit'] = SYSLOG_RULE_PREVIEW_HISTORY_ROWS;
}
Expand Down
4 changes: 4 additions & 0 deletions js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,10 @@ function testSyslogRule(formSelector, dialogSelector, title) {
(result.count === 1 ? '1 matching message' : result.count + ' matching messages')
)));

if (result.notice) {
container.append($('<p/>').text(result.notice));
}

if (result.history_limit) {
container.append($('<p/>').text('No matches in incoming data. Results are from the most recent ' + result.history_limit + ' stored messages. Testing does not send alarms.'));
}
Expand Down
4 changes: 4 additions & 0 deletions locales/po/cacti.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3582,3 +3582,7 @@ msgstr ""
#: syslog_saved_searches.php
msgid "Choose a field, operator, and value. Use AND, OR, NOT, or Group to build the query. Changes apply to this shared template for all users."
msgstr ""

#: includes/functions.php
msgid "SQL Expression previews check only queued incoming messages. Already processed messages are not searched. Testing does not send alarms."
msgstr ""
12 changes: 5 additions & 7 deletions syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@
exit;
}

if (get_request_var('action') == 'save') {
save_settings();
exit;
}

if (get_request_var('action') == 'saved_search_save') {
header('Content-Type: application/json; charset=UTF-8');
print saved_search_save();
Expand Down Expand Up @@ -154,6 +149,11 @@
$_SESSION['sess_syslog_tab'] = $current_tab;
}

if (get_request_var('action') == 'save') {
save_settings();
exit;
}

// validate the syslog post/get/request information
syslog_request_validation($current_tab);

Expand Down Expand Up @@ -2824,8 +2824,6 @@ function syslog_messages(string $tab = 'syslog'): void {
function save_settings(): void {
global $current_tab;

// syslog_request_validation($current_tab);

$variables = [
'rows',
'refresh',
Expand Down
40 changes: 40 additions & 0 deletions tests/E2E/playwright/browser-save-defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Exercise the authenticated save action that used to disable the plugin.
const { withSession, fail, url } = require('./session');

withSession(async (page) => {
const target = url('plugins/syslog/syslog.php');
await page.goto(`${target}?tab=syslog&removal=-1&rows=30&refresh=60`, { waitUntil: 'networkidle' });
await page.locator('#syslog_view_options summary').click();

const saved = page.waitForResponse((response) => response.url() === target && response.request().method() === 'POST');
await page.locator('#save').click();
const response = await saved;

if (response.status() !== 200 || (await response.text()).trim() !== '') {
fail(`Saving view defaults failed: ${response.status()} ${await response.text()}`);
}

// Old clients can omit the tab; the save must use the active session tab.
await page.goto(`${target}?tab=alerts`, { waitUntil: 'networkidle' });
const fallback = await page.evaluate(async (target) => {
const response = await fetch(target, {
method: 'POST',
body: new URLSearchParams({ action: 'save', rows: '30', refresh: '60', removal: '-1', __csrf_magic: csrfMagicToken })
});
return { status: response.status, body: await response.text() };
}, target);

if (fallback.status !== 200 || fallback.body.trim() !== '') {
fail(`Saving without a tab failed: ${JSON.stringify(fallback)}`);
}

await page.goto(`${target}?tab=syslog`, { waitUntil: 'networkidle' });
if (await page.locator('#save').count() !== 1) {
fail('Syslog is unavailable after saving view defaults');
}

console.log('Save view defaults and session-tab fallback passed');
}).catch((error) => {
console.error(error.stack || String(error));
process.exit(1);
});
7 changes: 7 additions & 0 deletions tests/E2E/playwright/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ test_syslog_empty_page() {
browser_check "plugins/syslog/syslog.php" "Syslog" "No Syslog Messages" "Unprocessed Messages: 0"
}

test_save_view_defaults() {
node_check browser-save-defaults.js
assert_equals "$(db_scalar "SELECT value FROM settings_user WHERE user_id=1 AND name='syslog_removal'")" "-1" "main-record defaults should persist"
assert_equals "$(db_scalar "SELECT status FROM plugin_config WHERE directory='syslog'")" "1" "saving defaults must leave Syslog enabled"
}

test_alerts_page() {
browser_check "plugins/syslog/syslog_alerts.php" "Console > Syslog Alerts" "No Syslog Alerts Defined"
}
Expand Down Expand Up @@ -328,6 +334,7 @@ normalize_admin

run_test "1 login console" test_login_console
run_test "2 syslog empty page" test_syslog_empty_page
run_test "Save view defaults" test_save_view_defaults
run_test "3 alerts page" test_alerts_page
run_test "4 removal page" test_removal_page
run_test "5 reports page" test_reports_page
Expand Down
21 changes: 20 additions & 1 deletion tests/Unit/RulePreviewShapeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,23 @@ function preview_setup(): void {
// The hand written expression is embedded as-is; that is the
// existing trusted-admin model for stored rules.
expect(str_contains($calls[0]['sql'], "LIKE '%keepalive%'"))->toBeTrue();
});
});

it('explains the incoming-only scope of SQL alert previews', function ($count) {
syslog_load_plugin_source('includes/functions.php');
preview_setup();

$calls = [];
preview_capture($calls, ['count' => (string) $count]);

$preview = syslog_rule_preview(['type' => 'sql', 'message' => "message LIKE '%SYS-5-CONFIG_I: Configured from%'"], 'alert');

expect($preview['error'])->toBe('')
->and($preview['count'])->toBe($count)
->and($preview['notice'])->toBe('SQL Expression previews check only queued incoming messages. Already processed messages are not searched. Testing does not send alarms.')
->and($calls)->toHaveCount(2);

foreach ($calls as $call) {
expect($call['sql'])->toContain('`syslogdb`.`syslog_incoming`');
}
})->with([0, 1]);
Loading