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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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`
* issue#479: With more than one Syslog Processing Process, the master no longer waits out the full ten second registration window on each phase when its workers have already finished or exited; a worker that finds the processing lock no longer held by its master now records the failure and logs the expected lock owner and the holder `IS_USED_LOCK()` reported
* issue#479: With more than one Syslog Processing Process, the master no longer waits out the full ten second registration window on each phase when its workers have already finished or exited
* issue#479: Replace the GET_LOCK()-based Syslog processing lock with Cacti's process registry so transfer workers no longer stop writing when their database connection is routed to a different cluster node; the master, partition rebuilds and on-demand table repair now coordinate through register_process_start('syslog','master',...) and workers verify the master by process id
* 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
* feature: Recommendations are matched only against the sending device's vendor (and vendor-neutral records) when the syslog host is a Cacti device whose vendor is recognised from its SNMP sysDescr or device template and has records; other hosts match every vendor, except that all-digit identifiers then match only vendor-neutral records
Expand Down
23 changes: 13 additions & 10 deletions syslog_process.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,19 @@ function syslog_worker_main($debug = false) {
if (!syslog_processing_master_alive((int) $master_pid)) {
cacti_log(sprintf('WARNING: Syslog child %s exited; the processing run that launched it (master pid %d) is no longer running', $child, (int) $master_pid), false, 'SYSLOG');

// Report the failure so the master stops waiting for this child
// and counts the phase as failed.
set_config_option('stats_syslog_child_' . $child, json_encode([
'child' => $child,
'run_id' => $run_id,
'phase' => $phase,
'moved' => 0,
'success' => false,
'reason' => 'master',
]));
// A replacement master owns the reusable worker statistics slots.
$registered_pid = db_fetch_cell_prepared("SELECT pid FROM processes
WHERE tasktype = 'syslog' AND taskname = 'master' AND taskid = ?", [$GLOBALS['config']['poller_id']]);
if ($registered_pid !== false && (!$registered_pid || (int) $registered_pid === (int) $master_pid)) {
set_config_option('stats_syslog_child_' . $child, json_encode([
'child' => $child,
'run_id' => $run_id,
'phase' => $phase,
'moved' => 0,
'success' => false,
'reason' => 'master',
]));
}

unregister_process('syslog', 'child', $child);

Expand Down
3 changes: 3 additions & 0 deletions tests/E2E/run-orb-docker-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ docker exec cacti_web sh -lc 'touch /var/www/html/cacti/log/cacti.log && chown w
docker exec cacti_web php cli/install_cacti.php --accept-eula --install --force
docker exec cacti_web php cli/plugin_manage.php --plugin=syslog --install --enable --allperms

docker cp "${ROOT_DIR}/tests/E2E/worker-master-stats.php" cacti_web:/tmp/worker-master-stats.php
docker exec -e SYSLOG_WORKER_E2E=1 cacti_web php /tmp/worker-master-stats.php

docker run --rm \
--network cacti-syslog-e2e_default \
--ipc=host \
Expand Down
75 changes: 75 additions & 0 deletions tests/E2E/worker-master-stats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
*/

// Run from the root of a disposable, installed Cacti instance.
if (PHP_SAPI !== 'cli' || getenv('SYSLOG_WORKER_E2E') !== '1') {
exit(2);
}

require getcwd() . '/include/cli_check.php';

// A failed test is a CLI failure. Cacti treats an uncaught plugin exception as
// a production fault and disables the plugin, which hides subsequent failures.
set_exception_handler(static function (Throwable $error) {
fwrite(STDERR, $error->getMessage() . PHP_EOL);
exit(1);
});

$worker = $config['base_path'] . '/plugins/syslog/syslog_process.php';
$poller = (int) $config['poller_id'];
$child = random_int(10000, 1000000);
$key = 'stats_syslog_child_' . $child;
$run = bin2hex(random_bytes(16));
$master = 99999999;
$where = "tasktype = 'syslog' AND taskname = 'master' AND taskid = ?";

if (db_fetch_cell_prepared("SELECT COUNT(*) FROM processes WHERE $where", [$poller]) ||
db_fetch_cell_prepared('SELECT COUNT(*) FROM settings WHERE name = ?', [$key]) ||
posix_kill($master, 0)) {
throw new RuntimeException('Worker test requires an idle fixture and an unused statistics slot');
}

$run_worker = static function () use ($worker, $child, $run, $master) {
$process = proc_open([PHP_BINARY, $worker, "--child=$child", "--run-id=$run",
'--phase=references', '--seq-start=1', '--seq-end=1', "--master-pid=$master"],
[0 => ['file', '/dev/null', 'r'], 1 => STDOUT, 2 => STDERR], $pipes, dirname($worker));

if (!is_resource($process) || proc_close($process) !== 1) {
throw new RuntimeException('A worker whose master exited must report failure');
}
};

$read_stats = static function () use ($key) {
return json_decode((string) db_fetch_cell_prepared('SELECT value FROM settings WHERE name = ?', [$key]), true);
};

if (!db_execute_prepared("INSERT INTO processes (tasktype, taskname, taskid, pid)
VALUES ('syslog', 'master', ?, ?)", [$poller, $master])) {
throw new RuntimeException('Could not register the test master');
}

try {
$run_worker();
$expected = ['child' => $child, 'run_id' => $run, 'phase' => 'references', 'moved' => 0, 'success' => false, 'reason' => 'master'];
if ($read_stats() !== $expected) {
throw new RuntimeException('The worker did not record the failed run');
}

db_execute_prepared("UPDATE processes SET pid = ? WHERE $where AND pid = ?", [getmypid(), $poller, $master]);
$replacement = ['run_id' => bin2hex(random_bytes(16)), 'child' => $child, 'success' => true, 'moved' => 1];
set_config_option($key, json_encode($replacement, JSON_THROW_ON_ERROR));
$run_worker();

if ($read_stats() !== $replacement || db_fetch_cell_prepared("SELECT COUNT(*) FROM processes
WHERE tasktype = 'syslog' AND taskname = 'child' AND taskid = ?", [$child])) {
throw new RuntimeException('The orphan overwrote replacement statistics or stayed registered');
}
print "Orphan worker and replacement master statistics passed\n";
} finally {
db_execute_prepared("DELETE FROM processes WHERE $where AND pid IN (?, ?)", [$poller, $master, getmypid()]);
db_execute_prepared('DELETE FROM settings WHERE name = ?', [$key]);
}