diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac99919..48cc1456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `

` 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/.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 diff --git a/syslog_process.php b/syslog_process.php index c433f12c..2e1a6ede 100644 --- a/syslog_process.php +++ b/syslog_process.php @@ -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); diff --git a/tests/E2E/run-orb-docker-e2e.sh b/tests/E2E/run-orb-docker-e2e.sh index c6b491fb..49c1c2ec 100755 --- a/tests/E2E/run-orb-docker-e2e.sh +++ b/tests/E2E/run-orb-docker-e2e.sh @@ -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 \ diff --git a/tests/E2E/worker-master-stats.php b/tests/E2E/worker-master-stats.php new file mode 100644 index 00000000..c92b03fd --- /dev/null +++ b/tests/E2E/worker-master-stats.php @@ -0,0 +1,75 @@ +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]); +}