diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2441859f..51395e34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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 `
` 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/.json.gz, built from each vendor's public message references
diff --git a/includes/functions.php b/includes/functions.php
index b5a17f9a..4f1055ff 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -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
diff --git a/syslog.php b/syslog.php
index 3365699b..2e8a8ee7 100644
--- a/syslog.php
+++ b/syslog.php
@@ -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.
*
diff --git a/tests/Unit/CollectorHealthTest.php b/tests/Unit/CollectorHealthTest.php
index 3cde9eca..18b70ffb 100644
--- a/tests/Unit/CollectorHealthTest.php
+++ b/tests/Unit/CollectorHealthTest.php
@@ -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;
}
@@ -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');
+});
diff --git a/tests/Unit/PipelineHealthTest.php b/tests/Unit/PipelineHealthTest.php
index 0238874d..3c9c52b6 100644
--- a/tests/Unit/PipelineHealthTest.php
+++ b/tests/Unit/PipelineHealthTest.php
@@ -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();