Repository navigation
feat(recommendations): match recommendations by regular expression and program - #497
Open
TheWitness wants to merge 2 commits into
Open
TheWitness wants to merge 2 commits into
TheWitness wants to merge 2 commits into
Conversation
…d program Many messages, most Linux service messages among them, have no stable code to use as an identifier. A recommendation may now carry a PCRE pattern (regex) and an optional syslog program (program); it is then matched by the pattern instead of its identifier. - syslog_recommendations gains regex varchar(1024) and program varchar(64) (NOT NULL DEFAULT ''), added on upgrade with a prefix index on regex. - Patterns are validated on save and import: they must compile, be at most 1,024 characters, contain no control characters and not match an empty message; a program without a pattern is rejected. - Pattern records are loaded once per request (at most 2,000, within PHP's compiled-pattern cache), matched against the first 2,048 characters under a reduced pcre.backtrack_limit, after identifier matches, and apply to every sender except a Cacti device recognised as a different vendor. - Lookups now receive the syslog program: the details flyout, the fallback recommendation action and the batched lightbulb check (System Logs rows resolve program_id in one query). - The Recommendations page gains Pattern and Program fields, a Pattern column and a Match By filter; Can Match counts pattern records as matchable. Import and export carry regex/program only for records that use them, so existing catalogues keep their form. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gram Syslog programs are often prefixed or suffixed variants of a daemon name (postfix/smtpd, sshd-session, systemd-logind), and rule sources such as Wazuh match program names by prefix or substring. A record's program may now start and/or end with *: postfix* matches postfix/smtpd and *systemd* matches systemd-logind. A * anywhere else is rejected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Member
Author
|
Follow-up commit 71130e3: a pattern record's program may now start and/or end with a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Summary
Adds pattern recommendations: a recommendation can be matched by a PCRE regular expression, optionally limited to one syslog program, instead of by an exact identifier word. This is phase 2 of the Linux recommendations work. Most Linux service messages (sshd, kernel, postfix and others) have no stable message code, so identifier matching can't cover them.
A follow-up PR will add a Wazuh-derived (GPL-2.0) Linux catalogue built on this engine.
Behaviour
regexis a pattern record. Its identifier only names it (for examplewazuh-5710), and identifier matching skips it (regex = '').(?i);programthat must equal the message's syslog program, ignoring case.pcre.backtrack_limitlowered to 100,000 and then restored. A catastrophic pattern such as^(a+)+$fails as "no match" in about 1.5 ms instead of stalling.\x01) means patterns never need escaping.Changes
includes/recommendations.php:syslog_recommendation_regex_error,syslog_recommendation_can_match), pattern cache and matcher;lookup(),for_messages(),for_rows()andlookup_json()take the program;syslog_recommendation_program_names()resolvesprogram_idfor System Logs rows in one query;regexandprogram. Those keys appear only when set, so existing catalogues and the bundled.json.gzfiles round-trip unchanged.includes/schema.php,includes/database.php: the new columns and prefix index on install and upgrade, plus asyslog_db_index_exists()wrapper.syslog.php,includes/functions.php,js/functions.js: pass the program to every lookup path.syslog_recommendations.php:locales/po/cacti.pot(xgettext step only; no.po/.mofiles).Testing
add_columncalls have no default is now scoped to the message tables.ProcessHelperCompatTest/procprobe) is also present ondevelop.tests/regression/cli_schema_upgrade_test.phppasses.regexandprogram;regex = '') and the Can Match filter SQL all run.Compatibility
The export format stays at version 1. Plugin versions without this change ignore
regexandprogram, and would import a pattern record as an identifier record. Its identifier, for examplewazuh-5710, does not occur in normal messages.