aboutsummaryrefslogtreecommitdiffstats
path: root/log-forward
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-07-15 12:22:55 +0200
committerGravatar Christian Hesse <mail@eworm.de>2020-07-15 12:41:29 +0200
commit6bce0a4b6a3d1ee48a1e4b4f40652ae490fb288c (patch)
tree5cff4a2b93eb6d0d305cd8f824cf6d9d63c3c206 /log-forward
parent9740b1f26993bafe09834e19a0275036e2f5c22a (diff)
add 'log-forward', drop 'early-errors'change-23
Diffstat (limited to 'log-forward')
-rw-r--r--log-forward47
1 files changed, 47 insertions, 0 deletions
diff --git a/log-forward b/log-forward
new file mode 100644
index 0000000..8f7bc1f
--- /dev/null
+++ b/log-forward
@@ -0,0 +1,47 @@
+#!rsc
+# RouterOS script: log-forward
+# Copyright (c) 2020 Christian Hesse <mail@eworm.de>
+# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
+#
+# forward log messages via notification
+# https://git.eworm.de/cgit/routeros-scripts/about/doc/log-forward.md
+
+:global Identity;
+:global LogForwardFilter;
+:global LogForwardLast;
+
+:global LogPrintExit;
+:global MailServerIsUp;
+:global SendNotification;
+:global WaitFullyConnected;
+
+$WaitFullyConnected;
+
+:if ($MailServerIsUp = false) do={
+ $LogPrintExit warning ("Mail server is not up.") true;
+}
+
+:local Count 0;
+:local Messages "";
+:local MessageVal;
+
+:foreach Message in=[ / log find where !(topics~$LogForwardFilter) ] do={
+ :set MessageVal [ / log get $Message ];
+
+ :if ($LogForwardLast = $MessageVal) do={
+ :set Messages "";
+ :set Count 0;
+ } else={
+ :set Messages ($Messages . "\n" . $MessageVal->"time" . " " . \
+ [ :tostr ($MessageVal->"topics") ] . " " . $MessageVal->"message");
+ :set Count ($Count + 1);
+ }
+}
+
+:if ($Count > 0) do={
+ $SendNotification ("\E2\9A\A0 Log Forwarding") \
+ ("The log on " . $Identity . " contains these " . $Count . " messages after " . \
+ [ / system resource get uptime ] . " uptime.\n" . $Messages);
+
+ :set LogForwardLast $MessageVal;
+}