From 875ac9f7c32c80d2c388f9d44d8f5b446327a9e6 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 13 Jan 2026 21:02:02 +0100 Subject: [PATCH] log-forward: use comparison for ids This was introduced with RouterOS 7.22beta1. Initializing $LogForwardLast with boolean value looks odd, but this is reuqired to match the very first message. --- doc/log-forward.md | 2 +- log-forward.rsc | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/doc/log-forward.md b/doc/log-forward.md index 25991fba..f51d61a5 100644 --- a/doc/log-forward.md +++ b/doc/log-forward.md @@ -4,7 +4,7 @@ Forward log messages via notification [![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers) [![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network) [![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers) -[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.17-yellow?style=flat)](https://mikrotik.com/download/changelogs/) +[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.22beta1-yellow?style=flat)](https://mikrotik.com/download/changelogs/) [![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts) [![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J) diff --git a/log-forward.rsc b/log-forward.rsc index ed2226f0..7a40a7a9 100644 --- a/log-forward.rsc +++ b/log-forward.rsc @@ -3,7 +3,7 @@ # Copyright (c) 2020-2026 Christian Hesse # https://rsc.eworm.de/COPYING.md # -# requires RouterOS, version=7.17 +# requires RouterOS, version=7.22beta1 # # forward log messages via notification # https://rsc.eworm.de/doc/log-forward.md @@ -24,7 +24,6 @@ :global LogForwardRateLimit; :global EitherOr; - :global HexToNum; :global IfThenElse; :global LogForwardFilterLogForwarding; :global LogPrint; @@ -38,6 +37,10 @@ :error false; } + :if ([ :typeof $LogForwardLast ] = "nothing") do={ + :set LogForwardLast false; + } + :if ([ :typeof $LogForwardRateLimit ] = "nothing") do={ :set LogForwardRateLimit 0; } @@ -51,7 +54,6 @@ :local Count 0; :local Duplicates false; - :local Last [ $IfThenElse ([ :len $LogForwardLast ] > 0) [ $HexToNum $LogForwardLast ] -1 ]; :local Messages ""; :local Warning false; :local MessageVal; @@ -63,19 +65,16 @@ :set LogForwardIncludeMessage [ $EitherOr $LogForwardIncludeMessage [] ]; :local LogAll [ /log/find ]; - :local MaxId ($LogAll->([ :len $LogAll ] - 1)); - :local MaxNum [ $HexToNum $MaxId ]; + :local Max ($LogAll->([ :len $LogAll ] - 1)); :local LogForwardFilterLogForwardingCached [ $EitherOr [ $LogForwardFilterLogForwarding ] ("\$^") ]; - :foreach Message in=[ /log/find where (!(message="") and \ - !(message~$LogForwardFilterLogForwardingCached) and \ - !(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \ - topics~$LogForwardInclude or message~$LogForwardIncludeMessage ] do={ + :foreach Message in=[ /log/find where .id>$LogForwardLast and .id<=$Max and \ + ((!(message="") and !(message~$LogForwardFilterLogForwardingCached) and \ + !(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \ + topics~$LogForwardInclude or message~$LogForwardIncludeMessage) ] do={ :set MessageVal [ /log/get $Message ]; :local Bullet "information"; - :local Current [ $HexToNum ($MessageVal->".id") ]; - :if ($Last < $Current && $Current <= $MaxNum) do={ :local DupCount ($MessageDups->($MessageVal->"message")); :if ($MessageVal->"topics" ~ "(warning)") do={ :set Warning true; @@ -93,7 +92,6 @@ } :set ($MessageDups->($MessageVal->"message")) ($DupCount + 1); :set Count ($Count + 1); - } } :if ($Count > 0) do={ @@ -111,7 +109,7 @@ :set LogForwardRateLimit [ $MAX 0 ($LogForwardRateLimit - 1) ]; } - :set LogForwardLast $MaxId; + :set LogForwardLast $Max; } do={ :global ExitError; $ExitError $ExitOK [ :jobname ] $Err; }