From 4dcb01cc212470be6239c7fb81622c5d8578796f Mon Sep 17 00:00:00 2001 From: TheWitness Date: Thu, 3 Dec 2026 11:17:55 -0500 Subject: [PATCH 1/6] feat(recommendations): match recommendations by regular expression and 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> --- CHANGELOG.md | 1 + README.md | 52 ++- includes/database.php | 15 + includes/functions.php | 2 +- includes/recommendations.php | 395 ++++++++++++++++--- includes/schema.php | 18 +- js/functions.js | 6 +- locales/po/cacti.pot | 59 ++- syslog.php | 4 +- syslog_recommendations.php | 58 ++- tests/Unit/MessageThresholdBreachTest.php | 6 +- tests/Unit/RecommendationsTest.php | 218 +++++++++- tests/bootstrap-unit.php | 10 + tests/regression/cli_schema_upgrade_test.php | 1 + 14 files changed, 744 insertions(+), 101 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56101ef8..9b85bd7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ --- develop --- +* feature: Add pattern recommendations. A recommendation may carry a PCRE pattern (`regex`) and an optional syslog program (`program`); it is then matched by the pattern instead of its identifier, after identifier matches, and applies to every sender except a Cacti device recognised as a different vendor. Patterns are validated on save and import (they must compile, be at most 1,024 characters and not match an empty message), run under a reduced PCRE backtracking limit, and are loaded once per request (at most 2,000, within PHP's compiled-pattern cache). The Recommendations page gains Pattern and Program fields, a Pattern column and a Match By filter; import and export carry the new fields only for records that use them. Upgrades add the `regex` and `program` columns to `syslog_recommendations` * feature: Add a manually importable Linux recommendation catalogue in docs/linux.json.gz with the 102 entries of systemd's journal message catalog (v262.2), keyed on the journal MESSAGE_ID that rsyslog or syslog-ng forwarders can append to the message; contrib/recommendations/extract_systemd_catalog.py converts the catalog for build_catalogues.py, and devices whose sysDescr or template mentions Linux but no network vendor are now recognised as Linux for recommendation scoping * dev: Sync js/cards.js with the Cacti core Card API controller (Cacti/cacti#8928): defer a card refresh until an in-flight grow or shrink settles so it no longer reverts the resize, target drops by row start so a taller card no longer captures a drop in a later row and a dragged card alone in its row no longer jumps up a row, and bind the add-card control once so a re-initialised grid receives added cards * 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 diff --git a/README.md b/README.md index b93e3860..7eb6fa4f 100644 --- a/README.md +++ b/README.md @@ -774,8 +774,10 @@ which returns JSON. ### How recommendations are matched -* Only the `identifier` column is matched. The vendor, component, severity, - message and explanation are shown but never searched. +* For an identifier recommendation only the `identifier` column is matched. + The vendor, component, severity, message and explanation are shown but never + searched. Pattern recommendations are matched by their pattern instead; see + [Pattern recommendations](#pattern-recommendations). * The first 2,048 characters of the syslog message are split into words. A word is a run of letters, digits and `_ . - /` that may start with `%`; any other character (space, colon, comma, bracket, and so on) ends a word. In @@ -812,7 +814,8 @@ which returns JSON. `Linux ...`) is a Linux device. Many network operating systems run on Linux, so a vendor named in either always wins. * When several recommendations match, the longest identifiers are shown first, - up to three. + up to three, followed by pattern recommendations when fewer than three + identifiers match. * Identifiers containing other characters, such as the `#` slot placeholder or the `|` alternatives in some vendor documentation (`%ASA|PIX-3-331001`), are stored and exported but can never match. The bundled data has 860 of them; @@ -824,10 +827,49 @@ which returns JSON. The same rules are summarised under **How Recommendations Are Matched** on the Recommendations page. +### Pattern recommendations + +Many messages, such as most Linux service messages, carry no stable code to use +as an identifier. A recommendation with a **Pattern** (`regex` in JSON) is +matched by that regular expression instead, and its identifier only names it +(for example `wazuh-5710`). + +* The pattern is a PCRE regular expression without delimiters, such as + `Failed password for (invalid user )?\S+ from`. It is tested against the first + 2,048 characters of the message and is case sensitive unless it starts with + `(?i)`. +* An optional **Program** (`program` in JSON), such as `sshd`, limits the + pattern to messages whose syslog program is equal to it, ignoring case. +* A pattern recommendation applies to every sender except a Cacti device + recognised as a different vendor, so Linux servers that are not Cacti devices + are covered. One with an empty vendor applies to every sender. +* Patterns are checked when a recommendation is saved or imported: a pattern + that does not compile, contains control characters or line breaks, is longer + than 1,024 characters, or matches an empty message (and therefore every + message) is rejected, as is a program without a pattern. +* Pattern recommendations are tried after identifier recommendations, oldest + first. At most 2,000 of them are used, which keeps them within PHP's cache of + compiled patterns. A pattern that needs excessive backtracking on a message is + treated as not matching it. + +```json +{ + "vendor": "Linux", + "identifier": "wazuh-5710", + "regex": "Failed password for invalid user", + "program": "sshd", + "explanation": "An SSH login was attempted with a user name that does not exist." +} +``` + +`regex` and `program` are omitted from exported records that do not use them, +so catalogues without patterns keep their existing form. Older plugin versions +ignore both fields and would import a pattern record as an identifier record. + Manage them under Console > Syslog Settings > Recommendations (the Syslog Administration realm). You can add, edit, and delete records, filter by -vendor and severity, and import or export them as JSON. A recommendation is -identified by its vendor and identifier. +vendor, severity and whether they match by identifier or pattern, and import or +export them as JSON. A recommendation is identified by its vendor and identifier. The bundled Cisco data in `docs/cisco.json.gz` is loaded once, the first time the plugin is installed or upgraded to 5.0 (see diff --git a/includes/database.php b/includes/database.php index e3c93646..a9b840c9 100644 --- a/includes/database.php +++ b/includes/database.php @@ -284,6 +284,21 @@ function syslog_db_add_column($table, $column, $log = true): bool { return db_add_column($table, $column, $log, $syslog_cnn); } +/** + * syslog_db_index_exists - checks whether an index exists on a table + * + * @param string $table The name of the table + * @param string $index The name of the index + * @param bool $log Whether to log error messages, defaults to true + * + * @return bool true if the index exists, false otherwise + */ +function syslog_db_index_exists($table, $index, $log = true): bool { + global $syslog_cnn; + + return db_index_exists($table, $index, $log, $syslog_cnn); +} + /** * syslog_db_affected_rows - return the number of rows affected by the last transaction * diff --git a/includes/functions.php b/includes/functions.php index 69a0f603..e0125746 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -9269,7 +9269,7 @@ function syslog_message_details(string $source, $id, string $logtime = ''): arra $recommendations = []; if (function_exists('syslog_recommendations_lookup')) { - $recommendations = syslog_recommendations_format(syslog_recommendations_lookup($record['message'], 3, $record['device'])); + $recommendations = syslog_recommendations_format(syslog_recommendations_lookup($record['message'], 3, $record['device'], $record['program'])); } return [ diff --git a/includes/recommendations.php b/includes/recommendations.php index 4415dfb5..8e690fe8 100644 --- a/includes/recommendations.php +++ b/includes/recommendations.php @@ -33,9 +33,18 @@ * "vendor": "Cisco", "identifier": "%LINK-3-UPDOWN", "component": "LINK", * "severity": "error", "message": "Interface [chars], changed state to [chars]", * "explanation": "...", "recommended_action": "...", "reference": "https://..." + * }, + * { + * "vendor": "Linux", "identifier": "wazuh-5710", "regex": "Failed password for invalid user", + * "program": "sshd", "explanation": "..." * } * ] * } + * + * A record with a "regex" is a pattern record: it is matched by that PCRE + * pattern (and, when "program" is set, the message's program) instead of by + * its identifier, which then only names it. "regex" and "program" are + * optional and omitted from records that do not use them. */ const SYSLOG_RECOMMENDATIONS_FORMAT = 'syslog-recommendations'; @@ -61,6 +70,19 @@ // and MariaDB all accept (no non-capturing groups or escapes). const SYSLOG_RECOMMENDATIONS_IDENTIFIER_SQL = '^%?[A-Za-z0-9_]([A-Za-z0-9_./-]*[A-Za-z0-9_])?$'; +// Pattern records. A pattern is stored without delimiters and wrapped in a +// control character that validation forbids inside it, so no escaping is needed. +const SYSLOG_RECOMMENDATIONS_REGEX_DELIMITER = "\x01"; +const SYSLOG_RECOMMENDATIONS_MAX_REGEX = 1024; + +// Kept well below PHP's compiled-pattern cache (4,096 entries) so a page +// does not recompile every pattern for every row. +const SYSLOG_RECOMMENDATIONS_MAX_PATTERNS = 2000; + +// Backtracking budget per pattern and message: a catastrophic pattern fails +// quickly as "no match" instead of stalling the page. +const SYSLOG_RECOMMENDATIONS_BACKTRACK_LIMIT = 100000; + /** * Syslog severity names indexed by their RFC 5424 number. * @@ -140,7 +162,8 @@ function syslog_recommendation_text($value, int $max = SYSLOG_RECOMMENDATIONS_MA * * Besides the native field names, the common names used by other catalogues * are accepted (name/code/event_code, description/cause, action/resolution, - * level, references). + * level, references). The optional "regex" and "program" keys are only added + * to the result when they are set. * * @param array $input The raw record. * @param string|null $reason Set to why the record was rejected. @@ -191,9 +214,94 @@ function syslog_recommendation_normalize(array $input, ?string &$reason = null): return null; } + $regex = is_scalar($input['regex'] ?? null) ? trim((string) $input['regex']) : ''; + $program = syslog_recommendation_text($input['program'] ?? '', 65); + + if ($regex !== '') { + $reason = syslog_recommendation_regex_error($regex); + + if ($reason !== null) { + return null; + } + $record['regex'] = $regex; + } + + if ($program !== '') { + if ($regex === '') { + $reason = __('a program is only used together with a pattern', 'syslog'); + } elseif (strlen($program) > 64 || preg_match('/\s/u', $program)) { + $reason = __('the program is longer than 64 characters or contains spaces', 'syslog'); + } + + if ($reason !== null) { + return null; + } + $record['program'] = $program; + } + return $record; } +/** + * Check that a pattern can be stored and matched safely. + * + * @param string $regex The PCRE pattern, without delimiters. + * + * @return string|null Why the pattern is unusable, or null when it is valid. + */ +function syslog_recommendation_regex_error(string $regex): ?string { + if (strlen($regex) > SYSLOG_RECOMMENDATIONS_MAX_REGEX) { + return __('the pattern is longer than %d characters', SYSLOG_RECOMMENDATIONS_MAX_REGEX, 'syslog'); + } + + if (preg_match('/[\x00-\x1f\x7f]/', $regex)) { + return __('the pattern contains control characters or line breaks (write them as escapes such as \t)', 'syslog'); + } + + // Compile errors are expected here; keep them out of the PHP and Cacti logs. + set_error_handler(static fn (): bool => true); + + try { + $result = preg_match(syslog_recommendation_regex($regex), ''); + } finally { + restore_error_handler(); + } + + if ($result === false) { + return __('the pattern is not a valid regular expression', 'syslog'); + } + + if ($result === 1) { + return __('the pattern matches an empty message, so it would match every message', 'syslog'); + } + + return null; +} + +/** + * Wrap a stored pattern in its delimiters. + * + * @param string $regex The PCRE pattern, without delimiters. + * + * @return string The pattern ready for preg_match(). + */ +function syslog_recommendation_regex(string $regex): string { + return SYSLOG_RECOMMENDATIONS_REGEX_DELIMITER . $regex . SYSLOG_RECOMMENDATIONS_REGEX_DELIMITER; +} + +/** + * Whether a stored record can ever match a message: a pattern record always + * can (its pattern was validated), an identifier record only when the + * identifier has the shape of a message word. + * + * @param array $record The normalized record or table row. + * + * @return bool True when the lookup can find it. + */ +function syslog_recommendation_can_match(array $record): bool { + return (string) ($record['regex'] ?? '') !== '' || syslog_recommendation_matchable((string) ($record['identifier'] ?? '')); +} + /** * Whether an identifier can ever match a word of a syslog message. * @@ -299,20 +407,21 @@ function syslog_recommendations_parse(string $payload) { function syslog_recommendations_store(array $records, bool $overwrite): array { $result = ['imported' => 0, 'updated' => 0, 'skipped' => 0, 'failed' => 0]; - $columns = 'vendor, identifier, component, severity, message, explanation, recommended_action, reference'; - $sql = "INSERT INTO syslog_recommendations ($columns) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; + $columns = 'vendor, identifier, component, severity, message, explanation, recommended_action, reference, regex, program'; + $sql = "INSERT INTO syslog_recommendations ($columns) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; if ($overwrite) { $sql .= ' ON DUPLICATE KEY UPDATE component = VALUES(component), severity = VALUES(severity), message = VALUES(message), explanation = VALUES(explanation), - recommended_action = VALUES(recommended_action), reference = VALUES(reference)'; + recommended_action = VALUES(recommended_action), reference = VALUES(reference), + regex = VALUES(regex), program = VALUES(program)'; } else { $sql = str_replace('INSERT INTO', 'INSERT IGNORE INTO', $sql); } foreach ($records as $r) { $params = [$r['vendor'], $r['identifier'], $r['component'], $r['severity'], $r['message'], - $r['explanation'], $r['recommended_action'], $r['reference']]; + $r['explanation'], $r['recommended_action'], $r['reference'], $r['regex'] ?? '', $r['program'] ?? '']; if (!syslog_db_execute_prepared($sql, $params)) { $result['failed']++; @@ -345,7 +454,7 @@ function syslog_recommendations_store(array $records, bool $overwrite): array { * @return array The exported record. */ function syslog_recommendation_export_record(array $row): array { - return [ + $record = [ 'vendor' => (string) $row['vendor'], 'identifier' => (string) $row['identifier'], 'component' => (string) $row['component'], @@ -355,6 +464,14 @@ function syslog_recommendation_export_record(array $row): array { 'recommended_action' => (string) $row['recommended_action'], 'reference' => (string) $row['reference'] ]; + + foreach (['regex', 'program'] as $field) { + if ((string) ($row[$field] ?? '') !== '') { + $record[$field] = (string) $row[$field]; + } + } + + return $record; } /** @@ -741,68 +858,206 @@ function syslog_recommendation_scope_sql(string $scope, string $column): array { return [" AND $column IN (?, '')", [$scope]]; } +/** + * Load the pattern records once per request. + * + * Only what matching needs is loaded; the matched rows are fetched in full + * afterwards. At most SYSLOG_RECOMMENDATIONS_MAX_PATTERNS patterns are used. + * + * @param bool $reset Forget the loaded patterns (used by tests). + * + * @return list The patterns, oldest first. + */ +function syslog_recommendation_patterns(bool $reset = false): array { + static $patterns = null; + + if ($reset) { + $patterns = null; + + return []; + } + + if ($patterns === null) { + $rows = syslog_db_fetch_assoc_prepared('SELECT id, vendor, regex, program + FROM syslog_recommendations + WHERE regex > ? + ORDER BY id + LIMIT ' . SYSLOG_RECOMMENDATIONS_MAX_PATTERNS, + [''], + false + ); + + $patterns = []; + + foreach (is_array($rows) ? $rows : [] as $row) { + if ((string) ($row['regex'] ?? '') === '') { + continue; + } + + $patterns[] = [ + 'id' => (int) $row['id'], + 'vendor' => (string) $row['vendor'], + 'regex' => syslog_recommendation_regex((string) $row['regex']), + 'program' => strtolower((string) ($row['program'] ?? '')) + ]; + } + } + + return $patterns; +} + +/** + * Find the pattern records that match a message. + * + * A pattern record applies to a sender unless the sender is a Cacti device + * recognised as another vendor, and, when it names a program, only to + * messages from that program (ignoring case). + * + * @param string $message The syslog message text. + * @param string $program The syslog program of the message, if known. + * @param string $vendor The recognised vendor of the sender, or ''. + * @param int $limit The maximum number of matches to return. + * + * @return list The ids of the matching records, oldest first. + */ +function syslog_recommendation_pattern_ids(string $message, string $program, string $vendor, int $limit): array { + $patterns = syslog_recommendation_patterns(); + + if (!$patterns || $limit < 1) { + return []; + } + + $message = substr($message, 0, 2048); + $program = strtolower(trim($program)); + $previous = ini_get('pcre.backtrack_limit'); + $budget = min(SYSLOG_RECOMMENDATIONS_BACKTRACK_LIMIT, max(1, (int) $previous)); + $out = []; + + ini_set('pcre.backtrack_limit', (string) $budget); + + try { + foreach ($patterns as $pattern) { + if ($pattern['program'] !== '' && $pattern['program'] !== $program) { + continue; + } + + if ($pattern['vendor'] !== '' && $vendor !== '' && strcasecmp($pattern['vendor'], $vendor) !== 0) { + continue; + } + + if (@preg_match($pattern['regex'], $message) === 1) { + $out[] = $pattern['id']; + + if (count($out) >= $limit) { + break; + } + } + } + } finally { + ini_set('pcre.backtrack_limit', (string) $previous); + } + + return $out; +} + /** * Find the recommendations that apply to a syslog message. * * Candidates are matched under syslog_recommendation_scope(): when the sending * device's vendor is recognised and has records, only that vendor's records and - * vendor-neutral records (an empty vendor) are considered. + * vendor-neutral records (an empty vendor) are considered. Pattern records are + * then tried under syslog_recommendation_pattern_ids(). * * @param string $message The syslog message text. * @param int $limit The maximum number of recommendations to return. * @param string $host The syslog host that sent the message, if known. + * @param string $program The syslog program of the message, if known. * - * @return list> The matching rows, longest identifier first. + * @return list> The matching rows: identifier matches, + * longest identifier first, then pattern matches. */ -function syslog_recommendations_lookup(string $message, int $limit = 3, string $host = ''): array { +function syslog_recommendations_lookup(string $message, int $limit = 3, string $host = '', string $program = ''): array { + $limit = max(1, $limit); $candidates = syslog_recommendation_candidates($message); + $recognised = $host === '' ? '' : (syslog_recommendation_host_vendors([$host])[$host] ?? ''); + $columns = 'id, vendor, identifier, component, severity, message, explanation, recommended_action, reference, regex, program'; + $rows = []; - if (!$candidates) { - return []; - } + if ($candidates) { + $vendor = syslog_recommendation_scoped_vendor($recognised); + $groups = []; - $vendor = $host === '' ? '' : syslog_recommendation_scoped_vendor(syslog_recommendation_host_vendors([$host])[$host] ?? ''); - $groups = []; + foreach ($candidates as $candidate) { + $groups[syslog_recommendation_scope($vendor, $candidate)][] = $candidate; + } - foreach ($candidates as $candidate) { - $groups[syslog_recommendation_scope($vendor, $candidate)][] = $candidate; - } + $where = []; + $params = []; - $where = []; - $params = []; + foreach ($groups as $scope => $identifiers) { + [$condition, $extra] = syslog_recommendation_scope_sql((string) $scope, 'vendor'); - foreach ($groups as $scope => $identifiers) { - [$condition, $extra] = syslog_recommendation_scope_sql((string) $scope, 'vendor'); + $where[] = '(identifier IN (' . implode(',', array_fill(0, count($identifiers), '?')) . ')' . $condition . ')'; + $params = array_merge($params, $identifiers, $extra); + } - $where[] = '(identifier IN (' . implode(',', array_fill(0, count($identifiers), '?')) . ')' . $condition . ')'; - $params = array_merge($params, $identifiers, $extra); + $rows = syslog_db_fetch_assoc_prepared( + "SELECT $columns + FROM syslog_recommendations + WHERE regex = '' AND (" . implode(' OR ', $where) . ') + ORDER BY CHAR_LENGTH(identifier) DESC, vendor + LIMIT ' . $limit, + $params, + false + ); + $rows = is_array($rows) ? $rows : []; } - $rows = syslog_db_fetch_assoc_prepared( - 'SELECT vendor, identifier, component, severity, message, explanation, recommended_action, reference - FROM syslog_recommendations - WHERE ' . implode(' OR ', $where) . ' - ORDER BY CHAR_LENGTH(identifier) DESC, vendor - LIMIT ' . max(1, $limit), - $params, - false - ); + $ids = syslog_recommendation_pattern_ids($message, $program, $recognised, $limit - count($rows)); + + if ($ids) { + $matched = syslog_db_fetch_assoc_prepared( + "SELECT $columns + FROM syslog_recommendations + WHERE id IN (" . implode(',', array_fill(0, count($ids), '?')) . ')', + $ids, + false + ); + $by_id = []; + + foreach (is_array($matched) ? $matched : [] as $row) { + $by_id[(int) $row['id']] = $row; + } - return is_array($rows) ? $rows : []; + foreach ($ids as $id) { + if (isset($by_id[$id])) { + $rows[] = $by_id[$id]; + } + } + } + + return $rows; } /** * Check the displayed messages for recommendations using bounded, shared queries. * - * Candidates are matched under the same scopes as syslog_recommendations_lookup(). + * Candidates are matched under the same scopes as syslog_recommendations_lookup(), + * and messages without an identifier match are then tried against the pattern records. * * @param array $messages The messages keyed by their display row. * @param array $hosts The syslog host of each message, keyed like $messages. + * @param array $programs The syslog program of each message, keyed like $messages. * * @return array Whether each message has a matching recommendation. */ -function syslog_recommendations_for_messages(array $messages, array $hosts = []): array { +function syslog_recommendations_for_messages(array $messages, array $hosts = [], array $programs = []): array { $available = array_fill_keys(array_keys($messages), false); + + if (!$messages) { + return $available; + } + $vendors = $hosts ? syslog_recommendation_host_vendors(array_values($hosts)) : []; $candidates = []; @@ -825,7 +1080,7 @@ function syslog_recommendations_for_messages(array $messages, array $hosts = []) WHERE EXISTS ( SELECT 1 FROM syslog_recommendations AS recommendations - WHERE recommendations.identifier = candidates.identifier' . $condition . ' + WHERE recommendations.identifier = candidates.identifier AND recommendations.regex = \'\'' . $condition . ' )', array_merge($batch, $extra) ); @@ -844,27 +1099,78 @@ function syslog_recommendations_for_messages(array $messages, array $hosts = []) } } + $checked = []; + + foreach ($messages as $key => $message) { + if (!$available[$key]) { + $vendor = $vendors[(string) ($hosts[$key] ?? '')] ?? ''; + $program = (string) ($programs[$key] ?? ''); + $seen = $vendor . "\0" . strtolower($program) . "\0" . $message; + + if (!isset($checked[$seen])) { + $checked[$seen] = syslog_recommendation_pattern_ids($message, $program, $vendor, 1) !== []; + } + + $available[$key] = $checked[$seen]; + } + } + return $available; } +/** + * Resolve the program names of displayed rows that carry only a program_id. + * + * @param array> $rows The displayed rows. + * + * @return array Program names keyed by syslog_programs id. + */ +function syslog_recommendation_program_names(array $rows): array { + $ids = []; + + foreach ($rows as $row) { + if (!isset($row['program']) && isset($row['program_id']) && $row['program_id'] !== '') { + $ids[(int) $row['program_id']] = true; + } + } + + if (!$ids) { + return []; + } + + $ids = array_keys($ids); + $names = syslog_db_fetch_assoc_prepared('SELECT program_id, program FROM syslog_programs + WHERE program_id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')', $ids, false); + $out = []; + + foreach (is_array($names) ? $names : [] as $name) { + $out[(int) $name['program_id']] = (string) $name['program']; + } + + return $out; +} + /** * Flag the displayed log rows that have a recommendation. * * Stored messages carry a syslog_hosts id, resolved through $hosts; alert log - * rows carry the host name and message text (logmsg) directly. + * rows carry the host name and message text (logmsg) directly. A row's program + * is its program column or, failing that, its program_id resolved through $programs. * - * @param array> $rows The displayed rows. - * @param string $tab 'syslog' for stored messages, otherwise the alert log. - * @param array $hosts Host names keyed by syslog_hosts id, for the syslog tab. + * @param array> $rows The displayed rows. + * @param string $tab 'syslog' for stored messages, otherwise the alert log. + * @param array $hosts Host names keyed by syslog_hosts id, for the syslog tab. + * @param array $programs Program names keyed by syslog_programs id. * * @return array Whether each row has a matching recommendation. */ -function syslog_recommendations_for_rows(array $rows, string $tab, array $hosts = []): array { +function syslog_recommendations_for_rows(array $rows, string $tab, array $hosts = [], array $programs = []): array { $stored = $tab === 'syslog'; return syslog_recommendations_for_messages( array_map(static fn (array $row): string => (string) ($row[$stored ? 'message' : 'logmsg'] ?? ''), $rows), - array_map(static fn (array $row): string => (string) ($stored ? ($hosts[$row['host_id'] ?? ''] ?? '') : ($row['host'] ?? '')), $rows) + array_map(static fn (array $row): string => (string) ($stored ? ($hosts[$row['host_id'] ?? ''] ?? '') : ($row['host'] ?? '')), $rows), + array_map(static fn (array $row): string => (string) ($row['program'] ?? ($programs[$row['program_id'] ?? ''] ?? '')), $rows) ); } @@ -936,12 +1242,13 @@ function syslog_recommendations_labels(): array { * * @param string $message The syslog message text. * @param string $host The syslog host that sent the message, if known. + * @param string $program The syslog program of the message, if known. * * @return string The JSON document. It always carries the localized labels so * the browser needs no translation catalogue of its own. */ -function syslog_recommendations_lookup_json(string $message, string $host = ''): string { - $matches = syslog_recommendations_format(syslog_recommendations_lookup($message, 3, $host)); +function syslog_recommendations_lookup_json(string $message, string $host = '', string $program = ''): string { + $matches = syslog_recommendations_format(syslog_recommendations_lookup($message, 3, $host, $program)); return (string) json_encode([ 'found' => $matches !== [], diff --git a/includes/schema.php b/includes/schema.php index f921b0cc..453d57c0 100644 --- a/includes/schema.php +++ b/includes/schema.php @@ -250,10 +250,13 @@ function syslog_create_recommendations_table(): void { `explanation` text, `recommended_action` text, `reference` text, + `regex` varchar(1024) NOT NULL DEFAULT '', + `program` varchar(64) NOT NULL DEFAULT '', `last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `vendor_identifier` (`vendor`, `identifier`), - KEY `identifier` (`identifier`)) + KEY `identifier` (`identifier`), + KEY `regex` (`regex`(1))) ENGINE=InnoDB ROW_FORMAT=Dynamic COMMENT='Syslog message recommendations'"); @@ -1186,6 +1189,19 @@ function syslog_ensure_table_structures(): bool { return false; } + // Pattern recommendations; existing records stay identifier records. + foreach ([['name' => 'regex', 'type' => 'varchar(1024)', 'NULL' => false, 'default' => ''], + ['name' => 'program', 'type' => 'varchar(64)', 'NULL' => false, 'default' => '']] as $column) { + if (!syslog_db_add_column('syslog_recommendations', $column)) { + return false; + } + } + + if (!syslog_db_index_exists('syslog_recommendations', 'regex', false) + && !syslog_db_execute("ALTER TABLE `$syslogdb_default`.`syslog_recommendations` ADD INDEX `regex` (`regex`(1))")) { + return false; + } + // Repair these columns even when the installed plugin version is unchanged. if (syslog_db_update_table('syslog_alert', ['columns' => [ ['name' => 'threshold_window', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0', 'after' => 'num'], diff --git a/js/functions.js b/js/functions.js index 70396367..dccf7975 100644 --- a/js/functions.js +++ b/js/functions.js @@ -273,7 +273,7 @@ function initSyslogWorkspace() { note(recSection.dataset.loading); var call = data.source && data.id ? $.ajax({url: 'syslog.php', type: 'GET', dataType: 'json', data: {action: 'message_details', source: data.source, id: data.id, logtime: data.received || ''}}) - : $.ajax({url: 'syslog.php', type: 'POST', dataType: 'json', data: {action: 'recommendation', message: data.message || '', host: data.device || '', __csrf_magic: csrfMagicToken}}); + : $.ajax({url: 'syslog.php', type: 'POST', dataType: 'json', data: {action: 'recommendation', message: data.message || '', host: data.device || '', program: data.program || '', __csrf_magic: csrfMagicToken}}); call.done(function(result) { if (token !== request) return; if (result && result.record) render($.extend({}, result.record, {rules: result.rules || {}})); @@ -1737,7 +1737,7 @@ function initSyslogReports() { function syslogRecommendationsUrl(extra) { var params = $.extend({ filter: $('#filter').val(), vendor: $('#vendor').val(), severity: $('#severity').val(), - matchable: $('#matchable').val(), rows: $('#rows').val(), page: $('#page').val() + match_type: $('#match_type').val(), matchable: $('#matchable').val(), rows: $('#rows').val(), page: $('#page').val() }, extra || {}); return 'syslog_recommendations.php?' + $.param(params); @@ -1757,7 +1757,7 @@ function initSyslogRecommendations() { loadPageNoHeader('syslog_recommendations.php?clear=1&header=false'); }); - $('#vendor, #severity, #matchable, #rows').off('change').on('change', function() { + $('#vendor, #severity, #match_type, #matchable, #rows').off('change').on('change', function() { loadPageNoHeader(syslogRecommendationsUrl({page: 1, header: 'false'})); }); diff --git a/locales/po/cacti.pot b/locales/po/cacti.pot index b38d6243..419c7691 100644 --- a/locales/po/cacti.pot +++ b/locales/po/cacti.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Cacti \n" "Report-Msgid-Bugs-To: developers@cacti.net\n" -"POT-Creation-Date: 2026-11-20 14:13-0500\n" +"POT-Creation-Date: 2026-12-03 11:11-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Cacti Developers >\n" "Language-Team: Cacti Developers \n" @@ -819,6 +819,31 @@ msgstr "" msgid "it has neither an explanation nor a recommended action" msgstr "" +#: includes/recommendations.php +msgid "a program is only used together with a pattern" +msgstr "" + +#: includes/recommendations.php +msgid "the program is longer than 64 characters or contains spaces" +msgstr "" + +#: includes/recommendations.php +#, php-format +msgid "the pattern is longer than %d characters" +msgstr "" + +#: includes/recommendations.php +msgid "the pattern contains control characters or line breaks (write them as escapes such as \\t)" +msgstr "" + +#: includes/recommendations.php +msgid "the pattern is not a valid regular expression" +msgstr "" + +#: includes/recommendations.php +msgid "the pattern matches an empty message, so it would match every message" +msgstr "" + #: includes/recommendations.php msgid "it is not a JSON object" msgstr "" @@ -1710,8 +1735,8 @@ msgstr "" msgid "Field" msgstr "" -#: lib/syslog_dashboard.php syslog.php syslog_alerts.php syslog_removal.php -#: syslog_reports.php +#: lib/syslog_dashboard.php syslog.php syslog_alerts.php +#: syslog_recommendations.php syslog_removal.php syslog_reports.php msgid "Program" msgstr "" @@ -3464,7 +3489,7 @@ msgstr "" #: syslog_recommendations.php #, php-format -msgid "The recommendation was not saved because %s. Enter an identifier without spaces and at least an explanation or a recommended action." +msgid "The recommendation was not saved because %s. Enter an identifier without spaces, at least an explanation or a recommended action, and, for a pattern recommendation, a valid pattern." msgstr "" #: syslog_recommendations.php @@ -3517,7 +3542,7 @@ msgid "Import Recommendations from Local File" msgstr "" #: syslog_recommendations.php -msgid "Select a .json or .json.gz file on your local machine. Use the Export function to see the expected format: a list of records with vendor, identifier, component, severity, message, explanation, recommended_action and reference." +msgid "Select a .json or .json.gz file on your local machine. Use the Export function to see the expected format: a list of records with vendor, identifier, component, severity, message, explanation, recommended_action and reference, plus regex and program for pattern recommendations." msgstr "" #: syslog_recommendations.php @@ -3573,7 +3598,19 @@ msgid "Identifier" msgstr "" #: syslog_recommendations.php -msgid "The message code to look for, for example %LINK-3-UPDOWN, RPD_OSPF_NBRDOWN or 4625. It must equal a whole word of the syslog message (letters, digits and _ . - /); a leading % is literal and must match as written. The match is not case sensitive. See How Recommendations Are Matched on the list page." +msgid "The message code to look for, for example %LINK-3-UPDOWN, RPD_OSPF_NBRDOWN or 4625. It must equal a whole word of the syslog message (letters, digits and _ . - /); a leading % is literal and must match as written. The match is not case sensitive. For a pattern recommendation it only names the record. See How Recommendations Are Matched on the list page." +msgstr "" + +#: syslog_recommendations.php +msgid "Optional. A PCRE regular expression, without delimiters, that the message must match, for example Failed password for (invalid user )?\\S+ from. When set, the recommendation is matched by this pattern instead of by its identifier. The match is case sensitive unless the pattern starts with (?i), and the pattern must not match an empty message." +msgstr "" + +#: syslog_recommendations.php +msgid "Pattern" +msgstr "" + +#: syslog_recommendations.php +msgid "Optional, and only used with a pattern. The syslog program the message must come from, for example sshd. The match is not case sensitive." msgstr "" #: syslog_recommendations.php @@ -3617,7 +3654,7 @@ msgid "A lightbulb before the message marks matching recommendations on the Syst msgstr "" #: syslog_recommendations.php -msgid "Only the Identifier column is used for matching. The vendor, component, severity, message and explanation are shown in the details flyout but are never searched." +msgid "For an identifier recommendation only the Identifier column is used for matching; a pattern recommendation is matched by its Pattern instead (see the last item). The vendor, component, severity, message and explanation are shown in the details flyout but are never searched." msgstr "" #: syslog_recommendations.php @@ -3640,10 +3677,18 @@ msgstr "" msgid "Identifiers that contain other characters, such as the # slot placeholder or the | alternatives in some vendor documentation (for example %ASA|PIX-3-331001), are kept and exported but can never match. Set Can Match to No to list them, and edit them into the exact code, for example %ASA-3-331001." msgstr "" +#: syslog_recommendations.php +msgid "A recommendation with a Pattern is matched by that regular expression instead of by its identifier, and only against messages from its Program when one is set. It applies to every sender except a Cacti device recognised as a different vendor. Pattern recommendations are tried after identifier recommendations, oldest first, when fewer than three identifiers match." +msgstr "" + #: syslog_recommendations.php msgid "How Recommendations Are Matched" msgstr "" +#: syslog_recommendations.php +msgid "Match By" +msgstr "" + #: syslog_recommendations.php msgid "Can Match" msgstr "" diff --git a/syslog.php b/syslog.php index 2e8a8ee7..16ea7df1 100644 --- a/syslog.php +++ b/syslog.php @@ -137,7 +137,7 @@ if (get_request_var('action') == 'recommendation') { header('Content-Type: application/json; charset=UTF-8'); - print syslog_recommendations_lookup_json((string) get_nfilter_request_var('message'), (string) get_nfilter_request_var('host')); + print syslog_recommendations_lookup_json((string) get_nfilter_request_var('message'), (string) get_nfilter_request_var('host'), (string) get_nfilter_request_var('program')); exit; } @@ -2746,7 +2746,7 @@ function syslog_messages(string $tab = 'syslog'): void { } } - $recommendations = syslog_recommendations_for_rows($syslog_messages, $tab, $hosts); + $recommendations = syslog_recommendations_for_rows($syslog_messages, $tab, $hosts, syslog_recommendation_program_names($syslog_messages)); $recommendation_header = [ 'display' => '', 'align' => 'center', diff --git a/syslog_recommendations.php b/syslog_recommendations.php index 14c188bf..a23e1db6 100644 --- a/syslog_recommendations.php +++ b/syslog_recommendations.php @@ -92,6 +92,7 @@ function recommendation_filters(): array { 'filter' => ['filter' => FILTER_DEFAULT, 'pageset' => true, 'default' => ''], 'vendor' => ['filter' => FILTER_DEFAULT, 'pageset' => true, 'default' => '-1'], 'severity' => ['filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'], + 'match_type' => ['filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'], 'matchable' => ['filter' => FILTER_VALIDATE_INT, 'pageset' => true, 'default' => '-1'], 'sort_column' => ['filter' => FILTER_CALLBACK, 'default' => 'identifier', 'options' => ['options' => 'sanitize_search_string']], 'sort_direction' => ['filter' => FILTER_CALLBACK, 'default' => 'ASC', 'options' => ['options' => 'sanitize_search_string']] @@ -109,8 +110,8 @@ function recommendation_where(): array { if ((string) get_request_var('filter') !== '') { $like = '%' . get_request_var('filter') . '%'; - $where[] = '(identifier LIKE ? OR vendor LIKE ? OR component LIKE ? OR message LIKE ? OR explanation LIKE ? OR recommended_action LIKE ?)'; - $params = array_merge($params, array_fill(0, 6, $like)); + $where[] = '(identifier LIKE ? OR vendor LIKE ? OR component LIKE ? OR message LIKE ? OR explanation LIKE ? OR recommended_action LIKE ? OR regex LIKE ? OR program LIKE ?)'; + $params = array_merge($params, array_fill(0, 8, $like)); } if ((string) get_request_var('vendor') !== '-1') { @@ -123,10 +124,15 @@ function recommendation_where(): array { $params[] = (int) get_request_var('severity'); } + if ((string) get_request_var('match_type') !== '-1') { + $where[] = (string) get_request_var('match_type') === '1' ? "regex <> ''" : "regex = ''"; + } + // The same word shape the message lookup uses, so "No" lists exactly the - // identifiers that can never match a message. + // identifiers that can never match a message. Stored patterns were + // validated, so pattern records can always match. if ((string) get_request_var('matchable') !== '-1') { - $where[] = 'identifier ' . ((string) get_request_var('matchable') === '1' ? '' : 'NOT ') . 'REGEXP ?'; + $where[] = (string) get_request_var('matchable') === '1' ? "(regex <> '' OR identifier REGEXP ?)" : "(regex = '' AND identifier NOT REGEXP ?)"; $params[] = SYSLOG_RECOMMENDATIONS_IDENTIFIER_SQL; } @@ -164,14 +170,14 @@ function recommendation_save(): void { $return = 'syslog_recommendations.php?action=edit&id=' . $id; $input = []; - foreach (['vendor', 'identifier', 'component', 'severity', 'message', 'explanation', 'recommended_action', 'reference'] as $field) { + foreach (['vendor', 'identifier', 'component', 'severity', 'message', 'explanation', 'recommended_action', 'reference', 'regex', 'program'] as $field) { $input[$field] = trim((string) get_nfilter_request_var($field)); } $reason = null; $record = syslog_recommendation_normalize($input, $reason); if ($record === null) { - raise_message('syslog_recommendation_invalid', __esc('The recommendation was not saved because %s. Enter an identifier without spaces and at least an explanation or a recommended action.', $reason, 'syslog'), MESSAGE_LEVEL_ERROR); + raise_message('syslog_recommendation_invalid', __esc('The recommendation was not saved because %s. Enter an identifier without spaces, at least an explanation or a recommended action, and, for a pattern recommendation, a valid pattern.', $reason, 'syslog'), MESSAGE_LEVEL_ERROR); header('Location: ' . $return); return; @@ -188,21 +194,21 @@ function recommendation_save(): void { } $values = [$record['vendor'], $record['identifier'], $record['component'], $record['severity'], $record['message'], - $record['explanation'], $record['recommended_action'], $record['reference']]; + $record['explanation'], $record['recommended_action'], $record['reference'], $record['regex'] ?? '', $record['program'] ?? '']; if ($id > 0) { $ok = syslog_db_execute_prepared('UPDATE syslog_recommendations SET vendor = ?, identifier = ?, component = ?, severity = ?, - message = ?, explanation = ?, recommended_action = ?, reference = ? WHERE id = ?', array_merge($values, [$id])); + message = ?, explanation = ?, recommended_action = ?, reference = ?, regex = ?, program = ? WHERE id = ?', array_merge($values, [$id])); } else { $ok = syslog_db_execute_prepared('INSERT INTO syslog_recommendations - (vendor, identifier, component, severity, message, explanation, recommended_action, reference) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)', $values); + (vendor, identifier, component, severity, message, explanation, recommended_action, reference, regex, program) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $values); } if ($ok) { raise_message(1); - if (!syslog_recommendation_matchable($record['identifier'])) { + if (!syslog_recommendation_can_match($record)) { raise_message('syslog_recommendation_unmatchable', __esc('NOTE: The identifier %s contains characters other than letters, digits, _ . - / and an optional literal leading %%, so it can never match a syslog message. Replace placeholders such as # or alternatives such as A|B with the exact code.', $record['identifier'], 'syslog'), MESSAGE_LEVEL_INFO); } @@ -373,7 +379,7 @@ function recommendation_import(): void { syslog_recommendations_log_rejected($parsed['rejected']); $result = syslog_recommendations_store($parsed['records'], get_nfilter_request_var('duplicates') === 'overwrite'); - $unmatchable = count(array_filter($parsed['records'], static fn ($r) => !syslog_recommendation_matchable($r['identifier']))); + $unmatchable = count(array_filter($parsed['records'], static fn ($r) => !syslog_recommendation_can_match($r))); cacti_log(sprintf('NOTE: Recommendation import: %d added, %d updated, %d unchanged, %d rejected, %d failed to store, %d with identifiers that cannot match a message', $result['imported'], $result['updated'], $result['skipped'], $parsed['invalid'], $result['failed'], $unmatchable), false, 'SYSLOG'); @@ -410,7 +416,7 @@ function recommendation_import_form(): void { $fields = [ 'import_file' => [ 'friendly_name' => __('Import Recommendations from Local File', 'syslog'), - 'description' => __('Select a .json or .json.gz file on your local machine. Use the Export function to see the expected format: a list of records with vendor, identifier, component, severity, message, explanation, recommended_action and reference.', 'syslog'), + 'description' => __('Select a .json or .json.gz file on your local machine. Use the Export function to see the expected format: a list of records with vendor, identifier, component, severity, message, explanation, recommended_action and reference, plus regex and program for pattern recommendations.', 'syslog'), 'method' => 'file', 'accept' => '.json,.json.gz' ], @@ -461,7 +467,7 @@ function recommendation_edit(): void { if (!cacti_sizeof($row)) { $id = 0; $row = ['vendor' => '', 'identifier' => '', 'component' => '', 'severity' => '', 'message' => '', - 'explanation' => '', 'recommended_action' => '', 'reference' => '']; + 'explanation' => '', 'recommended_action' => '', 'reference' => '', 'regex' => '', 'program' => '']; } $severities = ['' => __('Not specified', 'syslog')]; @@ -478,7 +484,9 @@ function recommendation_edit(): void { $fields = [ 'spacer0' => ['method' => 'spacer', 'friendly_name' => __('Recommendation', 'syslog')], 'vendor' => ['method' => 'textbox', 'friendly_name' => __('Vendor', 'syslog'), 'description' => __('The supplier of the device or software that logs this message, for example Cisco or Juniper.', 'syslog'), 'value' => '|arg1:vendor|', 'size' => 40, 'max_length' => 64], - 'identifier' => ['method' => 'textbox', 'friendly_name' => __('Identifier', 'syslog'), 'description' => __('The message code to look for, for example %LINK-3-UPDOWN, RPD_OSPF_NBRDOWN or 4625. It must equal a whole word of the syslog message (letters, digits and _ . - /); a leading % is literal and must match as written. The match is not case sensitive. See How Recommendations Are Matched on the list page.', 'syslog'), 'value' => '|arg1:identifier|', 'size' => 60, 'max_length' => 190], + 'identifier' => ['method' => 'textbox', 'friendly_name' => __('Identifier', 'syslog'), 'description' => __('The message code to look for, for example %LINK-3-UPDOWN, RPD_OSPF_NBRDOWN or 4625. It must equal a whole word of the syslog message (letters, digits and _ . - /); a leading % is literal and must match as written. The match is not case sensitive. For a pattern recommendation it only names the record. See How Recommendations Are Matched on the list page.', 'syslog'), 'value' => '|arg1:identifier|', 'size' => 60, 'max_length' => 190], + 'regex' => ['method' => 'textbox', 'friendly_name' => __('Pattern', 'syslog'), 'description' => __('Optional. A PCRE regular expression, without delimiters, that the message must match, for example Failed password for (invalid user )?\S+ from. When set, the recommendation is matched by this pattern instead of by its identifier. The match is case sensitive unless the pattern starts with (?i), and the pattern must not match an empty message.', 'syslog'), 'value' => '|arg1:regex|', 'size' => 80, 'max_length' => SYSLOG_RECOMMENDATIONS_MAX_REGEX], + 'program' => ['method' => 'textbox', 'friendly_name' => __('Program', 'syslog'), 'description' => __('Optional, and only used with a pattern. The syslog program the message must come from, for example sshd. The match is not case sensitive.', 'syslog'), 'value' => '|arg1:program|', 'size' => 40, 'max_length' => 64], 'component' => ['method' => 'textbox', 'friendly_name' => __('Component', 'syslog'), 'description' => __('The facility, module or subsystem that raises the message.', 'syslog'), 'value' => '|arg1:component|', 'size' => 40, 'max_length' => 64], 'severity' => ['method' => 'drop_array', 'friendly_name' => __('Severity', 'syslog'), 'description' => __('The severity the vendor documents for this message.', 'syslog'), 'array' => $severities, 'value' => '|arg1:severity|', 'default' => ''], 'message' => $text('message', __('Message', 'syslog'), __('The message format as documented, including its variable placeholders.', 'syslog'), 3), @@ -514,12 +522,13 @@ function recommendation_edit(): void { function recommendation_matching_help(): void { $items = [ __('A lightbulb before the message marks matching recommendations on the System Logs and Alert Logs tabs. Click the message to read them in the details flyout. Hovering never requests the server.', 'syslog'), - __('Only the Identifier column is used for matching. The vendor, component, severity, message and explanation are shown in the details flyout but are never searched.', 'syslog'), + __('For an identifier recommendation only the Identifier column is used for matching; a pattern recommendation is matched by its Pattern instead (see the last item). The vendor, component, severity, message and explanation are shown in the details flyout but are never searched.', 'syslog'), __('The first 2,048 characters of the message are split into words. A word is a run of letters, digits and the characters _ . - / that may start with %. Every other character, such as a space, colon, comma or bracket, ends a word. In %LINK-3-UPDOWN: Interface Gi0/1, changed state to down the words are %LINK-3-UPDOWN, Interface, Gi0/1, changed, state, to and down.', 'syslog'), __('An identifier matches when it is exactly equal to one whole word, ignoring case. It is not a "contains", "starts with" or "ends with" search, and there are no wildcards: LINK-3-UPDOWN does not match the word LINK-3-UPDOWN-EXT, and UPDOWN does not match %LINK-3-UPDOWN.', 'syslog'), __('A leading % is literal, not a wildcard, and must match the message word as written. An identifier %LINK-3-UPDOWN matches the message word %LINK-3-UPDOWN, not LINK-3-UPDOWN; an identifier without the prefix matches only the unprefixed word.', 'syslog'), __('When the syslog host is a Cacti device whose vendor is recognised from its SNMP system description or device template, and recommendations exist for that vendor, only that vendor\'s recommendations and those without a vendor are checked. Otherwise all vendors are checked, but an identifier made only of digits matches only recommendations without a vendor. When several recommendations match, the longest identifiers are shown first, up to three.', 'syslog'), - __('Identifiers that contain other characters, such as the # slot placeholder or the | alternatives in some vendor documentation (for example %ASA|PIX-3-331001), are kept and exported but can never match. Set Can Match to No to list them, and edit them into the exact code, for example %ASA-3-331001.', 'syslog') + __('Identifiers that contain other characters, such as the # slot placeholder or the | alternatives in some vendor documentation (for example %ASA|PIX-3-331001), are kept and exported but can never match. Set Can Match to No to list them, and edit them into the exact code, for example %ASA-3-331001.', 'syslog'), + __('A recommendation with a Pattern is matched by that regular expression instead of by its identifier, and only against messages from its Program when one is set. It applies to every sender except a Cacti device recognised as a different vendor. Pattern recommendations are tried after identifier recommendations, oldest first, when fewer than three identifiers match.', 'syslog') ]; print "
" . __('How Recommendations Are Matched', 'syslog') . '
    '; @@ -574,6 +583,12 @@ function recommendation_list(): void { + +