mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
add 'log-forward', drop 'early-errors'
This commit is contained in:
@ -159,7 +159,6 @@ Available Scripts
|
||||
* [Use wireless network with daily psk](doc/daily-psk.md)
|
||||
* [Comment DHCP leases with info from access list](doc/dhcp-lease-comment.md)
|
||||
* [Create DNS records for DHCP leases](doc/dhcp-to-dns.md)
|
||||
* [Send notification with early errors](doc/early-errors.md)
|
||||
* [Send backup via e-mail](doc/email-backup.md)
|
||||
* [Wait for configuration und functions](doc/global-wait.md)
|
||||
* [Send GPS position to server](doc/gps-track.md)
|
||||
@ -168,6 +167,7 @@ Available Scripts
|
||||
* [Manage IP addresses with bridge status](doc/ip-addr-bridge.md)
|
||||
* [Run other scripts on DHCP lease](doc/lease-script.md)
|
||||
* [Manage LEDs dark mode](doc/leds-mode.md)
|
||||
* [Forward log messages via notification](doc/log-forward.md)
|
||||
* [Mode botton with multiple presses](doc/mode-button.md)
|
||||
* [Notify on host up and down](doc/netwatch-notify.md)
|
||||
* [Manage remote logging](doc/netwatch-syslog.md)
|
||||
|
@ -3,39 +3,8 @@ Send notification with early errors
|
||||
|
||||
[◀ Go back to main README](../README.md)
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
RouterOS supports sending log messages via e-mail or to a syslog server.
|
||||
However this does not work early after boot if network connectivity is not
|
||||
yet established. For example log messages about reboot without proper
|
||||
shutdown may be missed:
|
||||
|
||||
> router rebooted without proper shutdown, probably power outage
|
||||
|
||||
The script collects log messages with severity `error` and sends a
|
||||
notification.
|
||||
|
||||
Requirements and installation
|
||||
-----------------------------
|
||||
|
||||
Just install this script and [global-wait](global-wait.md):
|
||||
|
||||
$ScriptInstallUpdate early-errors,global-wait;
|
||||
|
||||
... and add a scheduler:
|
||||
|
||||
/ system scheduler add name=early-erros on-event="/ system script { run global-wait; run early-errors; }" start-time=startup;
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The notifications just require notification settings for e-mail and telegram.
|
||||
|
||||
See also
|
||||
--------
|
||||
|
||||
* [Wait for configuration und functions](global-wait.md)
|
||||
This script has been replace. Please migrate to
|
||||
[Forward log messages via notification](log-forward.md).
|
||||
|
||||
---
|
||||
[◀ Go back to main README](../README.md)
|
||||
|
42
doc/log-forward.md
Normal file
42
doc/log-forward.md
Normal file
@ -0,0 +1,42 @@
|
||||
Forward log messages via notification
|
||||
=====================================
|
||||
|
||||
[◀ Go back to main README](../README.md)
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
RouterOS supports sending log messages via e-mail or to a syslog server.
|
||||
This has some limitation, however:
|
||||
|
||||
* does not work early after boot if network connectivity is not
|
||||
yet established
|
||||
* lots of messages generate a flood of mails
|
||||
* Telegram is not supported
|
||||
|
||||
The script is intended to be run periodically. It collects log messages
|
||||
and forwards them via notification.
|
||||
|
||||
Requirements and installation
|
||||
-----------------------------
|
||||
|
||||
Just install the script:
|
||||
|
||||
$ScriptInstallUpdate log-forward;
|
||||
|
||||
... and add a scheduler:
|
||||
|
||||
/ system scheduler add interval=1m name=log-forward on-event="/ system script run log-forward;" start-time=startup;
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The configuration goes to `global-config-overlay`, there is just one parameters:
|
||||
|
||||
* `LogForwardFilter`: define topics *not* to be forwarded
|
||||
|
||||
Also notification settings are required for e-mail and telegram.
|
||||
|
||||
---
|
||||
[◀ Go back to main README](../README.md)
|
||||
[▲ Go back to top](#top)
|
26
early-errors
26
early-errors
@ -1,28 +1,6 @@
|
||||
#!rsc
|
||||
# RouterOS script: early-errors
|
||||
# Copyright (c) 2020 Christian Hesse <mail@eworm.de>
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||
#
|
||||
# send notification with early errors
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/early-errors.md
|
||||
|
||||
:global Identity;
|
||||
:global LogPrintExit;
|
||||
|
||||
:global SendNotification;
|
||||
:global WaitFullyConnected;
|
||||
|
||||
$WaitFullyConnected;
|
||||
|
||||
:local Errors [ / log find where (topics~"error" or topics~"critical") \
|
||||
!(topics~"certificate") !(topics~"dns") !(topics~"e-mail") ];
|
||||
:local ErrCount [ :len $Errors ];
|
||||
:if ($ErrCount > 0) do={
|
||||
:local Message ("The log on " . $Identity . " contains " . $ErrCount . \
|
||||
" errors after " . [ / system resource get uptime ] . " uptime.\n");
|
||||
:foreach Log in=$Errors do={
|
||||
:local LogVal [ / log get $Log ];
|
||||
:set Message ($Message . "\n" . [ :tostr ($LogVal->"topics") ] . \
|
||||
" " . ($LogVal->"message"));
|
||||
}
|
||||
$SendNotification ("\E2\9A\A0 Early errors") ($Message);
|
||||
}
|
||||
$LogPrintExit warning ("This script has been replaced. Please migrate to 'log-forward'.") true;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
# Make sure all configuration properties are up to date and this
|
||||
# value is in sync with value in script 'global-functions'!
|
||||
:global GlobalConfigVersion 22;
|
||||
:global GlobalConfigVersion 23;
|
||||
|
||||
# This is used for DNS and backup file.
|
||||
:global Domain "example.com";
|
||||
@ -42,6 +42,9 @@
|
||||
:global BackupUploadUser "mikrotik";
|
||||
:global BackupUploadPass "v3ry-s3cr3t";
|
||||
|
||||
# This defines a filter on log topics not to be forwarded.
|
||||
:global LogForwardFilter "(debug|info|script)";
|
||||
|
||||
# Specify an address to enable auto update to version assumed safe.
|
||||
# The configured channel (bugfix, current, release-candidate) is appended.
|
||||
:global SafeUpdateUrl "";
|
||||
|
@ -9,7 +9,7 @@
|
||||
# Make sure all configuration properties are up to date and this
|
||||
# value is in sync with value in script 'global-functions'!
|
||||
# Comment or remove to disable change notifications.
|
||||
:global GlobalConfigVersion 22;
|
||||
:global GlobalConfigVersion 23;
|
||||
|
||||
# Copy configuration from global-config here and modify it.
|
||||
|
||||
|
@ -26,4 +26,5 @@
|
||||
20="Added support for hooks to 'netwatch-notify'";
|
||||
21="Added support for installing patch updates automatically by 'check-routeros-update'";
|
||||
22="Dropped '\$ScriptUpdatesIgnore' from global configuration, auto-migrating to ignore flag in comment"
|
||||
23="Added 'log-forward' with configurable filter, which replaces 'early-errors'";
|
||||
};
|
||||
|
@ -8,7 +8,7 @@
|
||||
# https://git.eworm.de/cgit/routeros-scripts/about/
|
||||
|
||||
# expected configuration version
|
||||
:global ExpectedConfigVersion 22;
|
||||
:global ExpectedConfigVersion 23;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
47
log-forward
Normal file
47
log-forward
Normal file
@ -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;
|
||||
}
|
Reference in New Issue
Block a user