aboutsummaryrefslogtreecommitdiffstats
path: root/log-forward
blob: 7da8a4a6cf2f995025f8f8da72b9b415d352b5a9 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!rsc by RouterOS
# 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 LogForwardFilterMessage;
:global LogForwardLast;

:global LogPrintExit;
:global MailServerIsUp;
:global ScriptLock;
:global SendNotification;
:global SymbolForNotification;
:global WaitFullyConnected;

$ScriptLock "log-forward";

$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) !(message~$LogForwardFilterMessage) ] do={
  :set MessageVal [ / log get $Message ];

  :if ($LogForwardLast = ($MessageVal->".id")) 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 ([ $SymbolForNotification "warning-sign" ] . "Log Forwarding") \
    ("The log on " . $Identity . " contains these " . $Count . " messages after " . \
      [ / system resource get uptime ] . " uptime.\n" . $Messages);

  :set LogForwardLast ($MessageVal->".id");
}