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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

--- develop ---

* issue#491: Syslog Status no longer fails with "Undefined constant SYSLOG_COLLECTOR_STALE_SECONDS" (and Cacti no longer disables the plugin) when Collector Staleness Threshold or Collector Backlog Threshold is set to Default; both defaults (300 seconds, 10000 messages) are now defined in `includes/functions.php` before the Status tab is drawn
* issue#484: Mark the syslog search help string in `syslog.php` as `no-php-format` and update `locales/po/cacti.pot` so the literal `%` in `LIKE` syntax is not flagged as a PHP format specifier
* issue#480: Split the syslog upgrade notice in `includes/installer.php` into separate balanced `<p>` translation strings, regenerate `locales/po/cacti.pot`, and remove orphan `locales/LC_MESSAGES/ka.mo`
* feature: Add manually importable recommendation catalogues for Arista, Dell, Fortinet, HPE, Huawei, MikroTik, Nokia, NVIDIA and Palo Alto Networks in docs/<vendor>.json.gz, built from each vendor's public message references
Expand Down
29 changes: 29 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@
require_once $syslog_query_builder;
}

/*
* Collector health defaults for the Syslog Status tab.
*
* These live here rather than in syslog.php because syslog.php dispatches
* to syslog_status() before execution would reach a define() placed further
* down that file; functions are hoisted, constants are not (issue #491).
*/

/**
* Default incoming-backlog age after which the collector looks stale.
*
* Matches the poller interval the Status tab refresh defaults to: one
* missed processing run is worth a warning.
*/
if (!defined('SYSLOG_COLLECTOR_STALE_SECONDS')) {
define('SYSLOG_COLLECTOR_STALE_SECONDS', 300);
}

/**
* Default incoming-backlog count after which the collector looks backed up.
*
* A few thousand unprocessed messages is normal for a busy collector
* between poller runs; far more than that suggests the processing path
* has stopped keeping up.
*/
if (!defined('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD')) {
define('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD', 10000);
}

/*
* Load core's process helpers before the shims below. The function_exists()
* guards only defer to core when lib/poller.php is already loaded; otherwise
Expand Down
17 changes: 0 additions & 17 deletions syslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,23 +517,6 @@ function syslog_status_format_rule_activity(string $value): string {
return cacti_sizeof($items) ? implode(', ', $items) : __('None', 'syslog');
}

/**
* Default incoming-backlog age after which the collector looks stale.
*
* Matches the poller interval the Status tab refresh defaults to: one
* missed processing run is worth a warning.
*/
define('SYSLOG_COLLECTOR_STALE_SECONDS', 300);

/**
* Default incoming-backlog count after which the collector looks backed up.
*
* A few thousand unprocessed messages is normal for a busy collector
* between poller runs; far more than that suggests the processing path
* has stopped keeping up.
*/
define('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD', 10000);

/**
* Read live collector health metrics for the Syslog Status tab.
*
Expand Down
66 changes: 58 additions & 8 deletions tests/Unit/CollectorHealthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ function collector_health_load_functions(): void {
}
}

// The constants live at page scope; declare them for the tests.
if (!defined('SYSLOG_COLLECTOR_STALE_SECONDS')) {
define('SYSLOG_COLLECTOR_STALE_SECONDS', 300);
}

if (!defined('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD')) {
define('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD', 10000);
}
// The default-threshold constants come from includes/functions.php,
// which every test loads first; they are not redeclared here so a
// missing definition fails the suite instead of being masked (#491).
syslog_load_plugin_source('includes/functions.php');

$loaded = true;
}
Expand Down Expand Up @@ -288,3 +284,57 @@ function collector_health_capture_db(array &$calls, array $overrides = []): void
collector_health_capture_db($calls, ['max' => date('Y-m-d H:i:s'), 'min' => date('Y-m-d H:i:s', time() - 600), 'count' => '2']);
expect(syslog_status_collector_health()['warning'])->toBeTrue();
});

it('defines the default threshold constants in includes/functions.php, not after syslog.php dispatches (#491)', function () {
$page = plugin_test_read_source('syslog.php');
$functions = plugin_test_read_source('includes/functions.php');

// A define() in syslog.php runs only when execution reaches it, which is
// after the tab dispatch calls syslog_status(); functions are hoisted,
// constants are not.
expect($page)->not->toContain("define('SYSLOG_COLLECTOR_STALE_SECONDS'")
->and($page)->not->toContain("define('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD'")
->and($functions)->toContain("define('SYSLOG_COLLECTOR_STALE_SECONDS', 300);")
->and($functions)->toContain("define('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD', 10000);");

// syslog_connect() loads includes/functions.php, and the page must call
// it before dispatching to the Status tab.
$connect = strpos($page, "\nsyslog_connect();");
$dispatch = strpos($page, "\tsyslog_status();");

expect($connect)->not->toBeFalse()
->and($dispatch)->not->toBeFalse()
->and($connect)->toBeLessThan($dispatch);

// A fresh PHP process with only includes/functions.php loaded must see
// both constants, independent of anything this test process defined.
$script = 'include ' . var_export(dirname(__DIR__, 2) . '/includes/functions.php', true) . ';'
. ' echo SYSLOG_COLLECTOR_STALE_SECONDS, ",", SYSLOG_COLLECTOR_BACKLOG_THRESHOLD;';
$output = shell_exec(escapeshellarg(PHP_BINARY) . ' -r ' . escapeshellarg($script) . ' 2>&1');

expect(trim((string) $output))->toBe('300,10000');
});

it('falls back to the default thresholds when the settings are "Default" (0) (#491)', function () {
syslog_load_plugin_source('includes/functions.php');
collector_health_load_functions();
collector_health_setup_config();

test_override('read_config_option', function ($name) {
return in_array($name, ['syslog_stale_threshold', 'syslog_backlog_threshold'], true) ? '0' : '';
});

// Over both defaults: 400s old (> 300s) and 10001 rows (> 10000).
$calls = [];
collector_health_capture_db($calls, [
'max' => date('Y-m-d H:i:s', time() - 30),
'min' => date('Y-m-d H:i:s', time() - 400),
'count' => '10001'
]);

$health = syslog_status_collector_health();

expect($health['warning'])->toBeTrue()
->and($health['warning_text'])->toContain('10,001')
->and($health['warning_text'])->toContain('minute');
});
2 changes: 0 additions & 2 deletions tests/Unit/PipelineHealthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,6 @@ function pipeline_health_fixture(): void {
eval(substr($source, $start, $end - $start + 2));
}
}
if (!defined('SYSLOG_COLLECTOR_STALE_SECONDS')) define('SYSLOG_COLLECTOR_STALE_SECONDS', 300);
if (!defined('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD')) define('SYSLOG_COLLECTOR_BACKLOG_THRESHOLD', 10000);
$GLOBALS['pipeline_fixture']['queries'] = [];
syslog_status_card_meta();
expect($GLOBALS['pipeline_fixture']['queries'])->toBeEmpty();
Expand Down