Skip to content

feat(recommendations): add a curated Linux catalogue with recommended actions - #499

Merged
TheWitness merged 2 commits into
developfrom
feat/linux-curated-catalogue
Dec 3, 2026
Merged

TheWitness merged 2 commits into
developfrom
feat/linux-curated-catalogue

Conversation

@TheWitness

@TheWitness TheWitness commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Stacked on #498 (→ #497 → #496). This PR targets feat/linux-wazuh-catalogue. Retarget it after those merge.

Summary

This is phase 3 of the Linux recommendations work: hand-written recommendations with real recommended actions, which Wazuh and the systemd catalog don't provide.

docs/linux-curated.json.gz holds 70 pattern recommendations. Every record has an explanation, a concrete recommended action and a reference to the Linux kernel documentation, man page or project documentation it relies on.

Area Records
Memory: system and cgroup OOM kills, OOM with nothing to kill, page allocation failures 4
CPU and crashes: soft and hard lockups, hung tasks, RCU stalls, panics, oopses, segfaults 7
Hardware: thermal throttling and critical temperature, machine checks, EDAC corrected and uncorrected 5
Storage: block, buffer, SATA, SCSI medium and NVMe errors, SMART, multipath, NFS, iSCSI 12
Filesystems and RAID: ext4, XFS, Btrfs, read-only remounts, full filesystems, md and mdadm 8
Network: link down, bonding, transmit timeouts, NIC hangs, conntrack, SYN floods, neighbour and TCP memory, duplicate addresses, martians 11
Time: chrony, ntpd, unstable clock source 4
Security: sshd, sudo, pam_faillock, SELinux, AppArmor, audit backlog 9
Services and logging: systemd failures, restart loops and crashes, core dumps, journald and rsyslog message loss (which affects what reaches Cacti), file and process limits 10

Source and licensing

  • Source: contrib/recommendations/linux-curated.json, built with build_catalogues.py linux-curated; the build is byte-reproducible.
  • License: the text was written for this plugin and is covered by its GPL-2.0-or-later.
  • References: each record links to the documentation it relies on (docs.kernel.org, man7.org, manpages.debian.org, chrony, ntp.org, rsyslog, btrfs). All links returned HTTP 200 on 2026-12-03.
  • Docs: the README licensing table and RECOMMENDATION_SOURCES.md include the new catalogue.

Engine changes

  • Action-first ordering: among matching pattern recommendations, the details flyout now shows those with a recommended action first, then the oldest. Without this, importing the Wazuh catalogue first would put its description-only records ahead of the curated advice. The batched lightbulb check is unchanged.
  • All applicable patterns are evaluated for the details view: to rank action-first, the flyout lookup now evaluates every applicable pattern instead of stopping after three matches. The batched lightbulb check keeps its 200,000-evaluation page budget.
  • Duplicate key includes the action: a pattern match is skipped as a duplicate only when its vendor, message, explanation and recommended action equal an earlier match's, so a record that differs only by having an action is not dropped before the action-first ordering.
  • Patterns kept exactly as written: surrounding spaces in a regular expression are significant, so the importer and the edit form no longer trim patterns. A whitespace-only pattern still counts as empty.

Review and testing

  • Independent technical review: a reviewer checked every record, which led to fixes for current message formats and for several pieces of advice:
    • NVMe I/O tag timeouts, the newer NETDEV WATCHDOG: CPU: format, RAID5/6 md/raid:, and tg3/bnx2 link-down wording;
    • XFS "Shutting down filesystem", chrony 4's other Can't synchronise variants, and rsyslog 8's begin to drop messages wording and rsyslogd-NNNN program tags;
    • task and process names that contain spaces;
    • ntpd's no_sys_peer (the earlier text was ntpdate's);
    • separating EMFILE from ENFILE;
    • correct rate-limit and retry advice for journald and rsyslog;
    • removal of the obsolete UserTasksMax=;
    • not treating SMART attribute changes as failures.
  • Sample messages: every record carries realistic sample messages, 113 in total, including the format variants above. A new test replays each one through the plugin's real matcher and requires its own record to come first. It also checks that the shipped .gz equals the source without its samples.
  • Other new tests:
    • the catalogue load check;
    • curated advice ranking ahead of a description-only Wazuh record that was imported earlier (linux-oom-kill before wazuh-5108);
    • surrounding spaces kept in a pattern.
  • Review follow-up (63c516e):
    • linux-kernel-oops matches only the oops form of a general protection fault (general protection fault[, probably for non-canonical address 0x...]: 0000 [#1]), not user-space traps: app[pid] general protection fault ... in libc.so.6 lines;
    • records can list non_matches, messages that must not find them, and the sample test checks them; the traps: line is the first;
    • linux-systemd-unit-failed anchors its unit name, avoiding quadratic backtracking on long runs without spaces;
    • a new test keeps a record that differs from an earlier match only by its action.
  • Full suite against Cacti 1.2.x: 934 passed. The one warning (ProcessHelperCompatTest /proc probe) is also present on develop.

xmacan
xmacan previously approved these changes Dec 3, 2026
@TheWitness
TheWitness force-pushed the feat/linux-curated-catalogue branch from 26dd49d to 5824f39 Compare December 3, 2026 19:11
Copilot AI balanced review requested due to automatic review settings December 3, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Deduplication can discard actionable recommendations, while an overly broad fault pattern misclassifies user-space crashes as kernel oopses and recommends unnecessary reboots.

2 open issues
What changed in this PR

Adds curated Linux troubleshooting advice to the existing recommendation engine, complementing the systemd and Wazuh catalogues.

Changes:

  • Adds 70 recommendations with actions, references and sample messages.
  • Prioritizes actionable pattern matches and preserves regex whitespace.
  • Adds catalogue regression tests and updates documentation and licensing.
File Description
tests/​Unit/​RecommendationsTest.php Tests catalogue loading, samples, ranking and whitespace.
syslog_recommendations.php Preserves patterns on save and updates matching help.
README.md Documents the catalogue, ordering and licensing.
NOTICE Adds curated catalogue attribution.
locales/​po/​cacti.pot Updates translatable matching help.
includes/​recommendations.php Preserves regex whitespace and prioritizes actions.
docs/​RECOMMENDATION_SOURCES.md Documents coverage, references and build instructions.
docs/​linux-curated.json.gz.license Adds SPDX licensing metadata.
contrib/​recommendations/​linux-curated.json Defines recommendations and sample messages.
contrib/​recommendations/​build_catalogues.py Adds curated catalogue build support.
CHANGELOG.md Records catalogue and matching changes.

Review effort: Balanced

Comment thread includes/recommendations.php Resolved

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: linux-kernel-oops matches user-space crashes. Its pattern has an unqualified general protection fault alternative (contrib/recommendations/linux-curated.json:197), and the kernel logs user-space faults under the same program: traps: myapp[1234] general protection fault ip:... sp:... error:0 in libc.so.6[...]. That line gets the oops explanation and "Plan a reboot". Exclude the traps: form, or require the oops form (general protection fault, probably for non-canonical address or general protection fault: 0000), and add a sample that must not match. The 113 samples are all positive, so the test cannot catch this.

Suggestion: syslog_recommendation_pattern_ids() drops a later match whose vendor, message and explanation equal an earlier one (includes/recommendations.php:1002), and the action is not part of that key. A record that differs only by having an action is skipped before the action-first sort runs. The shipped catalogues do not hit this; an imported or edited record can. Add the action to the key, or prefer the record that has one.

Suggestion: linux-systemd-unit-failed starts with an unanchored \S+\., which is quadratic on a long run without spaces. It is bounded by the 2,048 byte cut, but it runs on every systemd message. \b[\w@:-]+\.(?:service|...) or a length bound avoids it.

Nit: the lookup now evaluates every applicable pattern for a details view, not just until three match. Worth a line in the description.

Both Copilot threads on this PR are still open at bd6ec0e. CI on this head was cancelled, and it inherits the PHP 8.3 memory failure described on #498.

@TheWitness
TheWitness force-pushed the feat/linux-curated-catalogue branch from bd6ec0e to 310deb9 Compare December 3, 2026 20:16
@bmfmancini
bmfmancini force-pushed the feat/linux-curated-catalogue branch from 63c516e to 9a7a21d Compare December 3, 2026 20:27
@TheWitness

Copy link
Copy Markdown
Member Author

@somethingwithproof thanks, addressed in "fix(recommendations): keep kernel oops advice off user-space faults":

  • Blocker: linux-kernel-oops now matches only the oops form, general protection fault(?:, probably for non-canonical address 0x[0-9a-f]+)?: [0-9a-f]{4} \[#\d+\]. Records can list non_matches, and the sample test checks that your traps: myapp[1234] general protection fault ... in libc.so.6[...] line does not find the record. I also added a general protection fault: 0000 [#1] SMP PTI positive sample.
  • Suggestion (dedupe key): the key now includes recommended_action, with a new test.
  • Suggestion (linux-systemd-unit-failed): the unit name is anchored, ^[^\s:]+\.(?:service|...), so it no longer backtracks quadratically.
  • Nit: the description now says the details lookup evaluates every applicable pattern.

docs/linux-curated.json.gz is rebuilt; the old source still rebuilds byte-identically. Both Copilot threads are answered and resolved. CI is green. Please re-review.

@TheWitness
TheWitness force-pushed the feat/linux-curated-catalogue branch from 9a7a21d to e1c60d4 Compare December 3, 2026 20:34

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers found at e1c60d4.

  • linux-kernel-oops now needs the oops form: general protection fault: 0000 [#1] or the non-canonical address variant. A traps: myapp[1234] general protection fault ip:... line no longer matches, and the new non_matches sample covers it.
  • The duplicate key includes recommended_action.
  • The systemd unit pattern is anchored.

CI is green on PHP 8.2 to 8.6.

Base automatically changed from feat/linux-wazuh-catalogue to develop December 3, 2026 20:46
TheWitness and others added 2 commits December 3, 2026 15:46
… actions

Add docs/linux-curated.json.gz: 70 hand-written pattern recommendations,
each with an explanation and a recommended action, for the most important
Linux kernel and service messages (memory and OOM, lockups, hung tasks and
crashes, machine-check and EDAC errors, thermal events, block, SATA, SCSI
and NVMe errors, ext4, XFS and Btrfs, software RAID, SMART, multipath, NFS,
iSCSI, links, bonding, NICs, conntrack, SYN floods, time synchronisation,
sshd, sudo, PAM, SELinux, AppArmor, audit, systemd unit failures and
crashes, and journald and rsyslog message loss). The source is
contrib/recommendations/linux-curated.json, written for this plugin under
its GPL; each record carries sample messages that the unit tests replay
through the plugin matcher, and references kernel, man page or project
documentation.

Among matching pattern recommendations, the details flyout now shows those
with a recommended action first, so curated advice wins over the
description-only Wazuh records whichever catalogue was imported first.
Patterns are now stored exactly as written instead of having surrounding
spaces trimmed, because whitespace is significant in a regular expression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Review follow-up for the curated Linux catalogue:

- linux-kernel-oops matched any "general protection fault", so a
  user-space crash logged by the kernel (traps: app[pid] general
  protection fault ip:... in libc.so.6) got the oops explanation and
  "Plan a reboot". Match only the oops form ("general protection
  fault[, probably for non-canonical address 0x...]: 0000 [#1]").
- Records may now list "non_matches", messages they must not match,
  and the unit test checks them; the traps line is the first.
- Anchor linux-systemd-unit-failed's unit name, so a long run without
  spaces no longer costs quadratic backtracking on every systemd line.
- Include the recommended action in the duplicate pattern match key, so
  a record that differs from an earlier match only by having an action
  is no longer skipped before the action-first ordering.

docs/linux-curated.json.gz is rebuilt with build_catalogues.py.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness force-pushed the feat/linux-curated-catalogue branch from e1c60d4 to d2357c8 Compare December 3, 2026 20:46
@TheWitness
TheWitness merged commit da28892 into develop Dec 3, 2026
9 checks passed
@TheWitness
TheWitness deleted the feat/linux-curated-catalogue branch December 3, 2026 20:47
@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants