mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
log-forward: move code into function
This commit is contained in:
@@ -8,10 +8,12 @@
|
||||
# forward log messages via notification
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/log-forward.md
|
||||
|
||||
:local 0 [ :jobname ];
|
||||
:global GlobalFunctionsReady;
|
||||
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||
|
||||
:local Main do={
|
||||
:local ScriptName [ :tostr $1 ];
|
||||
|
||||
:global Identity;
|
||||
:global LogForwardFilter;
|
||||
:global LogForwardFilterMessage;
|
||||
@@ -30,7 +32,7 @@
|
||||
:global SendNotification2;
|
||||
:global SymbolForNotification;
|
||||
|
||||
$ScriptLock $0;
|
||||
$ScriptLock $ScriptName;
|
||||
|
||||
:if ([ :typeof $LogForwardRateLimit ] = "nothing") do={
|
||||
:set LogForwardRateLimit 0;
|
||||
@@ -38,7 +40,7 @@ $ScriptLock $0;
|
||||
|
||||
:if ($LogForwardRateLimit > 30) do={
|
||||
:set LogForwardRateLimit ($LogForwardRateLimit - 1);
|
||||
$LogPrintExit2 info $0 ("Rate limit in action, not forwarding logs, if any!") true;
|
||||
$LogPrintExit2 info $ScriptName ("Rate limit in action, not forwarding logs, if any!") true;
|
||||
}
|
||||
|
||||
:local Count 0;
|
||||
@@ -81,7 +83,7 @@ $ScriptLock $0;
|
||||
:if ($Count > 0) do={
|
||||
:set LogForwardRateLimit ($LogForwardRateLimit + 10);
|
||||
|
||||
$SendNotification2 ({ origin=$0; \
|
||||
$SendNotification2 ({ origin=$ScriptName; \
|
||||
subject=([ $SymbolForNotification [ $IfThenElse ($Warning = true) "warning-sign" "memo" ] ] . \
|
||||
"Log Forwarding"); \
|
||||
message=("The log on " . $Identity . " contains " . [ $IfThenElse ($Count = 1) "this message" \
|
||||
@@ -94,3 +96,6 @@ $ScriptLock $0;
|
||||
} else={
|
||||
:set LogForwardRateLimit [ $MAX 0 ($LogForwardRateLimit - 1) ];
|
||||
}
|
||||
}
|
||||
|
||||
$Main [ :jobname ];
|
||||
|
Reference in New Issue
Block a user