Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

--- develop ---

* feature: Add pattern recommendations. A recommendation may carry a PCRE pattern (`regex`) and an optional syslog program (`program`, which may start or end with a `*` wildcard); 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
Expand Down
55 changes: 50 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -812,7 +814,8 @@ which returns JSON.
`Linux <hostname> <kernel> ...`) 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;
Expand All @@ -824,10 +827,52 @@ 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 `*`
at the start or end matches any text there: `postfix*` matches
`postfix/smtpd`, and `*systemd*` matches `systemd-logind`. A `*` anywhere
else is rejected.
* 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
Expand Down
15 changes: 15 additions & 0 deletions includes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,21 @@
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);

Check warning on line 299 in includes/database.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

"db_index_exists" expects 3 arguments, but 4 were provided. Reduce provided arguments or add more parameters.

See more on https://sonarcloud.io/project/issues?id=Cacti_plugin_syslog&issues=AaI8s4FpghtB1TOOxLll&open=AaI8s4FpghtB1TOOxLll&pullRequest=497
}

/**
* syslog_db_affected_rows - return the number of rows affected by the last transaction
*
Expand Down
2 changes: 1 addition & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
Loading