mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-01-20 16:09:32 +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/network)
|
||||
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||
[](https://mikrotik.com/download/changelogs/)
|
||||
[](https://mikrotik.com/download/changelogs/)
|
||||
[](https://t.me/routeros_scripts)
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@
|
|||
:global GetRandom20CharHex;
|
||||
:global GetRandomNumber;
|
||||
:global Grep;
|
||||
:global HexToNum;
|
||||
:global HumanReadableNum;
|
||||
:global IfThenElse;
|
||||
:global IsDefaultRouteReachable;
|
||||
|
|
@ -717,19 +716,6 @@
|
|||
: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
|
||||
:set HumanReadableNum do={
|
||||
:local Input [ :tonum $1 ];
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# Copyright (c) 2020-2026 Christian Hesse <mail@eworm.de>
|
||||
# https://rsc.eworm.de/COPYING.md
|
||||
#
|
||||
# requires RouterOS, version=7.19
|
||||
# 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,37 +65,33 @@
|
|||
: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;
|
||||
: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);
|
||||
:local DupCount ($MessageDups->($MessageVal->"message"));
|
||||
:if ($MessageVal->"topics" ~ "(warning)") do={
|
||||
: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 ($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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue