diff options
author | Christian Hesse <mail@eworm.de> | 2021-06-09 14:32:52 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2021-06-09 14:42:43 +0200 |
commit | de61c14c6087cc181b057843649147e76b2304eb (patch) | |
tree | 50ec29f7e96a457a74985c9fc61b460f8e036496 | |
parent | d5f43aa26daa77d4211a3a71c2d8c6f765489891 (diff) |
log-forward: implement reverse logic to include messages...change-55
... even if a filter matches to exclude them. Let's have an example:
:global LogForwardFilter "(debug|info)";
:global LogForwardInclude "account";
This will forward everything about topic *account* (login, logout,
failed login, ...) - even with topic *info*.
-rw-r--r-- | doc/log-forward.md | 3 | ||||
-rw-r--r-- | global-config | 12 | ||||
-rw-r--r-- | global-config-overlay | 2 | ||||
-rw-r--r-- | global-config.changes | 1 | ||||
-rw-r--r-- | global-functions | 2 | ||||
-rw-r--r-- | log-forward | 7 |
6 files changed, 20 insertions, 7 deletions
diff --git a/doc/log-forward.md b/doc/log-forward.md index 570516e..8f1c3f0 100644 --- a/doc/log-forward.md +++ b/doc/log-forward.md @@ -38,6 +38,9 @@ The configuration goes to `global-config-overlay`, these are the parameters: * `LogForwardFilter`: define topics *not* to be forwarded * `LogForwardFilterMessage`: define message text *not* to be forwarded +* `LogForwardInclude`: define topics to be forwarded (even if filter matches) +* `LogForwardIncludeMessage`: define message text to be forwarded (even if + filter matches) Also notification settings are required for e-mail, matrix and/or telegram. diff --git a/global-config b/global-config index b22a05a..05197cf 100644 --- a/global-config +++ b/global-config @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! -:global GlobalConfigVersion 54; +:global GlobalConfigVersion 55; # This is used for DNS and backup file. :global Domain "example.com"; @@ -69,14 +69,20 @@ :global BackupUploadUser "mikrotik"; :global BackupUploadPass "v3ry-s3cr3t"; -# This defines what log messages to filter by topic or message +# This defines what log messages to filter or include by topic or message # text. Regular expressions are supported. Do *NOT* set an empty string, -# that will filter everything! +# that will filter or include everything! # These are filters, so excluding messages from forwarding. :global LogForwardFilter "(debug|info)"; :global LogForwardFilterMessage []; #:global LogForwardFilterMessage "message text"; #:global LogForwardFilterMessage "(message text|another text|...)"; +# ... and another setting with reverse logic. This includes messages even +# if filtered above. +:global LogForwardInclude []; +:global LogForwardIncludeMessage []; +#:global LogForwardInclude "account"; +#:global LogForwardIncludeMessage "message text"; # Specify an address to enable auto update to version assumed safe. # The configured channel (bugfix, current, release-candidate) is appended. diff --git a/global-config-overlay b/global-config-overlay index 1466a4d..e3f3fd7 100644 --- a/global-config-overlay +++ b/global-config-overlay @@ -8,7 +8,7 @@ # Make sure all configuration properties are up to date and this # value is in sync with value in script 'global-functions'! # Comment or remove to disable news and change notifications. -:global GlobalConfigVersion 54; +:global GlobalConfigVersion 55; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index 1721ab0..c4ccb69 100644 --- a/global-config.changes +++ b/global-config.changes @@ -58,6 +58,7 @@ 52="Updated Let's Encrypt trust chain to use root certificate 'ISRG Root X1'. Do not re-import the old chain!"; 53="Added support to send notifications via Matrix."; 54="Support for Telegram notifications moved to a module. It is installed automatically if required."; + 55="Added reverse logic in 'log-forward', so messages can be included even if filtered before."; }; # Migration steps to be applied on script updates diff --git a/global-functions b/global-functions index 02afd8f..273a6aa 100644 --- a/global-functions +++ b/global-functions @@ -8,7 +8,7 @@ # https://git.eworm.de/cgit/routeros-scripts/about/ # expected configuration version -:global ExpectedConfigVersion 54; +:global ExpectedConfigVersion 55; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/log-forward b/log-forward index 8f72893..2e66089 100644 --- a/log-forward +++ b/log-forward @@ -13,6 +13,8 @@ :global Identity; :global LogForwardFilter; :global LogForwardFilterMessage; +:global LogForwardInclude; +:global LogForwardIncludeMessage; :global LogForwardLast; :global LogForwardRateLimit; :global NotificationsWithSymbols; @@ -48,8 +50,9 @@ $WaitFullyConnected; :local LogForwardFilterLogForwarding ("^" . [ $EscapeForRegEx ("Error sending e-mail <" . \ [ $QuotedPrintable ("[" . $Identity . "] " . [ $SymbolForNotification "warning-sign" ] . \ "Log Forwarding") ] . ">:") ]); -:foreach Message in=[ / log find where !(topics~$LogForwardFilter) !(message="") \ - !(message~$LogForwardFilterLogForwarding) !(message~$LogForwardFilterMessage) ] do={ +:foreach Message in=[ / log find where (!(message="") and !(message~$LogForwardFilterLogForwarding) and \ + !(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \ + topics~$LogForwardInclude or message~$LogForwardIncludeMessage ] do={ :set MessageVal [ / log get $Message ]; :if ($LogForwardLast = ($MessageVal->".id")) do={ |