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.
This commit is contained in:
Christian Hesse 2026-01-13 21:02:02 +01:00
parent 49d3a448c6
commit 875ac9f7c3
2 changed files with 12 additions and 14 deletions

View file

@ -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 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 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) [![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) [![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) [![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)

View file

@ -3,7 +3,7 @@
# Copyright (c) 2020-2026 Christian Hesse <mail@eworm.de> # Copyright (c) 2020-2026 Christian Hesse <mail@eworm.de>
# https://rsc.eworm.de/COPYING.md # https://rsc.eworm.de/COPYING.md
# #
# requires RouterOS, version=7.17 # requires RouterOS, version=7.22beta1
# #
# forward log messages via notification # forward log messages via notification
# https://rsc.eworm.de/doc/log-forward.md # https://rsc.eworm.de/doc/log-forward.md
@ -24,7 +24,6 @@
:global LogForwardRateLimit; :global LogForwardRateLimit;
:global EitherOr; :global EitherOr;
:global HexToNum;
:global IfThenElse; :global IfThenElse;
:global LogForwardFilterLogForwarding; :global LogForwardFilterLogForwarding;
:global LogPrint; :global LogPrint;
@ -38,6 +37,10 @@
:error false; :error false;
} }
:if ([ :typeof $LogForwardLast ] = "nothing") do={
:set LogForwardLast false;
}
:if ([ :typeof $LogForwardRateLimit ] = "nothing") do={ :if ([ :typeof $LogForwardRateLimit ] = "nothing") do={
:set LogForwardRateLimit 0; :set LogForwardRateLimit 0;
} }
@ -51,7 +54,6 @@
:local Count 0; :local Count 0;
:local Duplicates false; :local Duplicates false;
:local Last [ $IfThenElse ([ :len $LogForwardLast ] > 0) [ $HexToNum $LogForwardLast ] -1 ];
:local Messages ""; :local Messages "";
:local Warning false; :local Warning false;
:local MessageVal; :local MessageVal;
@ -63,19 +65,16 @@
:set LogForwardIncludeMessage [ $EitherOr $LogForwardIncludeMessage [] ]; :set LogForwardIncludeMessage [ $EitherOr $LogForwardIncludeMessage [] ];
:local LogAll [ /log/find ]; :local LogAll [ /log/find ];
:local MaxId ($LogAll->([ :len $LogAll ] - 1)); :local Max ($LogAll->([ :len $LogAll ] - 1));
:local MaxNum [ $HexToNum $MaxId ];
:local LogForwardFilterLogForwardingCached [ $EitherOr [ $LogForwardFilterLogForwarding ] ("\$^") ]; :local LogForwardFilterLogForwardingCached [ $EitherOr [ $LogForwardFilterLogForwarding ] ("\$^") ];
:foreach Message in=[ /log/find where (!(message="") and \ :foreach Message in=[ /log/find where .id>$LogForwardLast and .id<=$Max and \
!(message~$LogForwardFilterLogForwardingCached) and \ ((!(message="") and !(message~$LogForwardFilterLogForwardingCached) and \
!(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \ !(topics~$LogForwardFilter) and !(message~$LogForwardFilterMessage)) or \
topics~$LogForwardInclude or message~$LogForwardIncludeMessage ] do={ topics~$LogForwardInclude or message~$LogForwardIncludeMessage) ] do={
:set MessageVal [ /log/get $Message ]; :set MessageVal [ /log/get $Message ];
:local Bullet "information"; :local Bullet "information";
:local Current [ $HexToNum ($MessageVal->".id") ];
:if ($Last < $Current && $Current <= $MaxNum) do={
:local DupCount ($MessageDups->($MessageVal->"message")); :local DupCount ($MessageDups->($MessageVal->"message"));
:if ($MessageVal->"topics" ~ "(warning)") do={ :if ($MessageVal->"topics" ~ "(warning)") do={
:set Warning true; :set Warning true;
@ -93,7 +92,6 @@
} }
:set ($MessageDups->($MessageVal->"message")) ($DupCount + 1); :set ($MessageDups->($MessageVal->"message")) ($DupCount + 1);
:set Count ($Count + 1); :set Count ($Count + 1);
}
} }
:if ($Count > 0) do={ :if ($Count > 0) do={
@ -111,7 +109,7 @@
:set LogForwardRateLimit [ $MAX 0 ($LogForwardRateLimit - 1) ]; :set LogForwardRateLimit [ $MAX 0 ($LogForwardRateLimit - 1) ];
} }
:set LogForwardLast $MaxId; :set LogForwardLast $Max;
} do={ } do={
:global ExitError; $ExitError $ExitOK [ :jobname ] $Err; :global ExitError; $ExitError $ExitOK [ :jobname ] $Err;
} }