mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-01-21 08:29:33 +00:00
Merge branch 'compare-ids' into next
This commit is contained in:
commit
33fb1ae7eb
3 changed files with 28 additions and 44 deletions
|
|
@ -4,7 +4,7 @@ Forward log messages via notification
|
||||||
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
||||||
[](https://github.com/eworm-de/routeros-scripts/network)
|
[](https://github.com/eworm-de/routeros-scripts/network)
|
||||||
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||||
[](https://mikrotik.com/download/changelogs/)
|
[](https://mikrotik.com/download/changelogs/)
|
||||||
[](https://t.me/routeros_scripts)
|
[](https://t.me/routeros_scripts)
|
||||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,6 @@
|
||||||
:global GetRandom20CharHex;
|
:global GetRandom20CharHex;
|
||||||
:global GetRandomNumber;
|
:global GetRandomNumber;
|
||||||
:global Grep;
|
:global Grep;
|
||||||
:global HexToNum;
|
|
||||||
:global HumanReadableNum;
|
:global HumanReadableNum;
|
||||||
:global IfThenElse;
|
:global IfThenElse;
|
||||||
:global IsDefaultRouteReachable;
|
:global IsDefaultRouteReachable;
|
||||||
|
|
@ -717,19 +716,6 @@
|
||||||
:return [];
|
:return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert from hex (string) to num
|
|
||||||
:set HexToNum do={
|
|
||||||
:local Input [ :tostr $1 ];
|
|
||||||
|
|
||||||
:global HexToNum;
|
|
||||||
|
|
||||||
:if ([ :pick $Input 0 ] = "*") do={
|
|
||||||
:return [ $HexToNum [ :pick $Input 1 [ :len $Input ] ] ];
|
|
||||||
}
|
|
||||||
|
|
||||||
:return [ :tonum ("0x" . $Input) ];
|
|
||||||
}
|
|
||||||
|
|
||||||
# return human readable number
|
# return human readable number
|
||||||
:set HumanReadableNum do={
|
:set HumanReadableNum do={
|
||||||
:local Input [ :tonum $1 ];
|
:local Input [ :tonum $1 ];
|
||||||
|
|
|
||||||
|
|
@ -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.19
|
# 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,37 +65,33 @@
|
||||||
: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") ];
|
:local DupCount ($MessageDups->($MessageVal->"message"));
|
||||||
:if ($Last < $Current && $Current <= $MaxNum) do={
|
:if ($MessageVal->"topics" ~ "(warning)") do={
|
||||||
:local DupCount ($MessageDups->($MessageVal->"message"));
|
:set Warning true;
|
||||||
:if ($MessageVal->"topics" ~ "(warning)") do={
|
:set Bullet "large-orange-circle";
|
||||||
:set Warning true;
|
|
||||||
:set Bullet "large-orange-circle";
|
|
||||||
}
|
|
||||||
:if ($MessageVal->"topics" ~ "(emergency|alert|critical|error)") do={
|
|
||||||
:set Warning true;
|
|
||||||
:set Bullet "large-red-circle";
|
|
||||||
}
|
|
||||||
:if ($DupCount < 3) do={
|
|
||||||
:set Messages ($Messages . "\n" . [ $SymbolForNotification $Bullet ] . \
|
|
||||||
$MessageVal->"time" . " " . [ :tostr ($MessageVal->"topics") ] . " " . $MessageVal->"message");
|
|
||||||
} else={
|
|
||||||
:set Duplicates true;
|
|
||||||
}
|
|
||||||
:set ($MessageDups->($MessageVal->"message")) ($DupCount + 1);
|
|
||||||
:set Count ($Count + 1);
|
|
||||||
}
|
}
|
||||||
|
:if ($MessageVal->"topics" ~ "(emergency|alert|critical|error)") do={
|
||||||
|
:set Warning true;
|
||||||
|
:set Bullet "large-red-circle";
|
||||||
|
}
|
||||||
|
:if ($DupCount < 3) do={
|
||||||
|
:set Messages ($Messages . "\n" . [ $SymbolForNotification $Bullet ] . \
|
||||||
|
$MessageVal->"time" . " " . [ :tostr ($MessageVal->"topics") ] . " " . $MessageVal->"message");
|
||||||
|
} else={
|
||||||
|
:set Duplicates true;
|
||||||
|
}
|
||||||
|
:set ($MessageDups->($MessageVal->"message")) ($DupCount + 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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue