2020-07-15 10:22:55 +00:00
|
|
|
#!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;
|
2020-07-17 06:07:12 +00:00
|
|
|
:global SymbolForNotification;
|
2020-07-15 10:22:55 +00:00
|
|
|
: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 ];
|
|
|
|
|
2020-07-15 12:43:26 +00:00
|
|
|
:if ($LogForwardLast = ($MessageVal->".id")) do={
|
2020-07-15 10:22:55 +00:00
|
|
|
: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={
|
2020-07-17 06:07:12 +00:00
|
|
|
$SendNotification ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \
|
2020-07-15 10:22:55 +00:00
|
|
|
("The log on " . $Identity . " contains these " . $Count . " messages after " . \
|
|
|
|
[ / system resource get uptime ] . " uptime.\n" . $Messages);
|
|
|
|
|
2020-07-15 12:43:26 +00:00
|
|
|
:set LogForwardLast ($MessageVal->".id");
|
2020-07-15 10:22:55 +00:00
|
|
|
}
|