Compare commits

...

5 commits

Author SHA1 Message Date
Christian Hesse
6a6c83a509 doc/check-lte-firmware-upgrade: add missing reference for ntfy 2025-04-28 11:00:00 +02:00
Christian Hesse
2459003d41 update list of contributors 2025-04-28 11:00:00 +02:00
Leonardo David Monteiro
be7b3b4366 introduce mod/notification-gotify...
... for sending notifications via Gotify (https://gotify.net).

Co-authored-by: Christian Hesse <mail@eworm.de>
2025-04-28 11:00:00 +02:00
Christian Hesse
b0ec93a235 Merge branch 'external-links' into next 2025-04-28 10:59:33 +02:00
Christian Hesse
ea02d5300a README: add disclaimer on external links 2025-04-28 10:51:11 +02:00
25 changed files with 284 additions and 6 deletions

View file

@ -74,6 +74,7 @@ See also
* [Download, import and update firewall address-lists](doc/fw-addr-lists.md)
* [Manage DNS and DoH servers from netwatch](doc/netwatch-dns.md)
* [Send notifications via Gotify](doc/mod/notification-gotify.md)
* [Send notifications via Matrix](doc/mod/notification-matrix.md)
* [Send notifications via Ntfy](doc/mod/notification-ntfy.md)

View file

@ -22,6 +22,7 @@ for details!
* [Daniel Ziegenberg](mailto:daniel@ziegenberg.at) (@ziegenberg)
* [Ignacio Serrano](mailto:ignic@ignic.com) (@ignic)
* [Ilya Kulakov](mailto:kulakov.ilya@gmail.com) (@Kentzo)
* [Leonardo David Monteiro](mailto:leo@cub3.xyz) (@leosfsm)
* [Michael Gisbers](mailto:michael@gisbers.de) (@mgisbers)
* [Miquel Bonastre](mailto:mbonastre@yahoo.com) (@mbonastre)
* @netravnen

View file

@ -16,7 +16,8 @@ repository holds a number of [scripts ↗️](https://wiki.mikrotik.com/wiki/Man
to manage RouterOS devices or extend their functionality.
*Use at your own risk*, pay attention to
[license and warranty](#license-and-warranty)!
[license and warranty](#license-and-warranty) and
[disclaimer on external links](#disclaimer-on-external-links)!
Requirements
------------
@ -267,6 +268,7 @@ Available modules
* [Inspect variables](doc/mod/inspectvar.md) (`mod/inspectvar`)
* [IP address calculation](doc/mod/ipcalc.md) (`mod/ipcalc`)
* [Send notifications via e-mail](doc/mod/notification-email.md) (`mod/notification-email`)
* [Send notifications via Gotify](doc/mod/notification-gotify.md) (`mod/notification-gotify`)
* [Send notifications via Matrix](doc/mod/notification-matrix.md) (`mod/notification-matrix`)
* [Send notifications via Ntfy](doc/mod/notification-ntfy.md) (`mod/notification-ntfy`)
* [Send notifications via Telegram](doc/mod/notification-telegram.md) (`mod/notification-telegram`)
@ -371,6 +373,21 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[GNU General Public License](COPYING.md) for more details.
Disclaimer on external links
----------------------------
Our website contains links to the websites of third parties ("external
links"). As the content of these websites is not under our control, we
cannot assume any liability for such external content. In all cases, the
provider of information of the linked websites is liable for the content
and accuracy of the information provided. At the point in time when the
links were placed, no infringements of the law were recognisable to us.
As soon as an infringement of the law becomes known to us, we will
immediately remove the link in question.
> 💡️ **Hint**: All external links are marked with an arrow pointing
> diagonally in an up-right, or north-east direction (↗️).
Upstream
--------

View file

@ -49,6 +49,7 @@ The configuration goes to `global-config-overlay`, these are the parameters:
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -55,6 +55,7 @@ The configuration goes to `global-config-overlay`, these are the parameters:
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -51,6 +51,7 @@ subject alternative name (aka *Subject Alt Name* or *SAN*) can be used.
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -113,6 +113,7 @@ The configuration goes to `global-config-overlay`, these are the parameters:
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -44,7 +44,9 @@ Configuration
Also notification settings are required for
[e-mail](mod/notification-email.md),
[matrix](mod/notification-matrix.md) and/or
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).
See also

View file

@ -41,6 +41,7 @@ Configuration
No extra configuration is required for this script, but notification
settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -73,6 +73,7 @@ The configuration goes to `global-config-overlay`, these are the parameters:
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -54,6 +54,7 @@ entries are to be added.
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -79,6 +79,7 @@ For legacy local interface:
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[trix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -22,15 +22,15 @@ server (see `/system/logging`). This has some limitation, however:
* does not work early after boot if network connectivity is not
yet established, or breaks intermittently
* lots of messages generate a flood of mails
* Matrix, Ntfy and Telegram are not supported
* Gotify, Matrix, Ntfy and Telegram are not supported
The script works around the limitations, for example it does:
* read from `/log`, including messages from early boot
* skip multi-repeated messages
* rate-limit itself to mitigate flooding
* forward via notification (which includes *e-mail*, *Matrix*, *Ntfy* and
*Telegram* when installed and configured, see below)
* forward via notification (which includes *e-mail*, *Gotify*, *Matrix*,
*Ntfy* and *Telegram* when installed and configured, see below)
It is intended to be run periodically from scheduler, then collects new
log messages and forwards them via notification.
@ -80,6 +80,7 @@ To forward **all** (ignoring severity) log messages with topics `account`
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -79,6 +79,7 @@ function available:
See also
--------
* [Send notifications via Gotify](notification-gotify.md)
* [Send notifications via Matrix](notification-matrix.md)
* [Send notifications via Ntfy](notification-ntfy.md)
* [Send notifications via Telegram](notification-telegram.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View file

@ -0,0 +1,97 @@
Send notifications via Gotify
===========================
[![GitHub stars](https://img.shields.io/github/stars/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=red)](https://github.com/eworm-de/routeros-scripts/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=green)](https://github.com/eworm-de/routeros-scripts/network)
[![GitHub watchers](https://img.shields.io/github/watchers/eworm-de/routeros-scripts?logo=GitHub&style=flat&color=blue)](https://github.com/eworm-de/routeros-scripts/watchers)
[![required RouterOS version](https://img.shields.io/badge/RouterOS-7.15-yellow?style=flat)](https://mikrotik.com/download/changelogs/)
[![Telegram group @routeros_scripts](https://img.shields.io/badge/Telegram-%40routeros__scripts-%2326A5E4?logo=telegram&style=flat)](https://t.me/routeros_scripts)
[![donate with PayPal](https://img.shields.io/badge/Like_it%3F-Donate!-orange?logo=githubsponsors&logoColor=orange&style=flat)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
[⬅️ Go back to main README](../../README.md)
> **Info**: This module can not be used on its own but requires the base
> installation. See [main README](../../README.md) for details.
Description
-----------
This module adds support for sending notifications via
[Gotify ↗️](https://gotify.net/). A queue is used to make sure
notifications are not lost on failure but sent later.
Requirements and installation
-----------------------------
Just install the module:
$ScriptInstallUpdate mod/notification-gotify;
Also deploy the [Gotify server ↗️](https://github.com/gotify/server) and
optionally install a Gotify client on your mobile device.
Configuration
-------------
Follow the [Installation ↗️](https://gotify.net/docs/install) instructions
and the [First Login ↗️](https://gotify.net/docs/first-login) setup. Once
you have a user and account you can start creating apps. Each app is an
independent notification feed for a device or application.
![Create new app](notification-gotify.d/appsetup.avif)
On creation apps are assigned a *Token* for authentification, you will need
that in configuration.
Edit `global-config-overlay`, add `GotifyServer` with your server address
(just the address, no protocol - `https://` is assumed) and `GotifyToken`
with the *Token* from your configured app on the Gotify server. Then reload
the configuration.
> **Info**: Copy relevant configuration from
> [`global-config`](../../global-config.rsc) (the one without `-overlay`) to
> your local `global-config-overlay` and modify it to your specific needs.
For a custom service installing an additional certificate may be required.
You may want to install that certificate manually, after finding the
[certificate name from browser](../../CERTIFICATES.md).
Usage and invocation
--------------------
There's nothing special to do. Every script or function sending a notification
will now send it to your Gotify application feed.
But of course you can use the function to send notifications directly. Give
it a try:
$SendGotify "Subject..." "Body...";
Alternatively this sends a notification with all available and configured
methods:
$SendNotification "Subject..." "Body...";
To use the functions in your own scripts you have to declare them first.
Place this before you call them:
:global SendGotify;
:global SendNotification;
In case there is a situation when the queue needs to be purged there is a
function available:
$PurgeGotifyQueue;
See also
--------
* [Certificate name from browser](../../CERTIFICATES.md)
* [Send notifications via e-mail](notification-email.md)
* [Send notifications via Matrix](notification-matrix.md)
* [Send notifications via Ntfy](notification-ntfy.md)
* [Send notifications via Telegram](notification-telegram.md)
---
[⬅️ Go back to main README](../../README.md)
[⬆️ Go back to top](#top)

View file

@ -131,6 +131,7 @@ See also
* [Certificate name from browser](../../CERTIFICATES.md)
* [Send notifications via e-mail](notification-email.md)
* [Send notifications via Gotify](notification-gotify.md)
* [Send notifications via Ntfy](notification-ntfy.md)
* [Send notifications via Telegram](notification-telegram.md)

View file

@ -90,6 +90,7 @@ See also
* [Certificate name from browser](../../CERTIFICATES.md)
* [Send notifications via e-mail](notification-email.md)
* [Send notifications via Gotify](notification-gotify.md)
* [Send notifications via Matrix](notification-matrix.md)
* [Send notifications via Telegram](notification-telegram.md)

View file

@ -115,6 +115,7 @@ See also
* [Chat with your router and send commands via Telegram bot](../telegram-chat.md)
* [Send notifications via e-mail](notification-email.md)
* [Send notifications via Gotify](notification-gotify.md)
* [Send notifications via Matrix](notification-matrix.md)
* [Send notifications via Ntfy](notification-ntfy.md)

View file

@ -47,6 +47,7 @@ The hosts to be checked have to be added to netwatch with specific comment:
Also notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -56,6 +56,7 @@ The configuration goes to `global-config-overlay`, this is the only parameter:
Notification settings are required for
[e-mail](mod/notification-email.md),
[gotify](mod/notification-gotify.md),
[matrix](mod/notification-matrix.md),
[ntfy](mod/notification-ntfy.md) and/or
[telegram](mod/notification-telegram.md).

View file

@ -63,6 +63,12 @@
:global NtfyServerToken "";
:global NtfyTopic "";
# You can send Gotify notifications. Configure these settings and
# install the module:
# $ScriptInstallUpdate mod/notification-gotify
:global GotifyServer "";
:global GotifyToken "";
# It is possible to override e-mail, Telegram, Matrix and Ntfy setting
# for every script. This is done in arrays, where 'Override' is appended
# to the variable name, like this:

View file

@ -15,7 +15,7 @@
# Git commit id & info, expected configuration version
:global CommitId "unknown";
:global CommitInfo "unknown";
:global ExpectedConfigVersion 136;
:global ExpectedConfigVersion 137;
# global variables not to be changed by user
:global GlobalFunctionsReady false;

138
mod/notification-gotify.rsc Normal file
View file

@ -0,0 +1,138 @@
#!rsc by RouterOS
# RouterOS script: mod/notification-gotify
# Copyright (c) 2025 Christian Hesse <mail@eworm.de>
# Leonardo David Monteiro <leo@cub3.xyz>
# https://rsc.eworm.de/COPYING.md
#
# requires RouterOS, version=7.15
# requires device-mode, fetch, scheduler
#
# send notifications via Gotify
# https://rsc.eworm.de/doc/mod/notification-gotify.md
:global FlushGotifyQueue;
:global NotificationFunctions;
:global PurgeGotifyQueue;
:global SendGotify;
:global SendGotify2;
# flush Gotify queue
:set FlushGotifyQueue do={ :do {
:global GotifyQueue;
:global IsFullyConnected;
:global LogPrint;
:if ([ $IsFullyConnected ] = false) do={
$LogPrint debug $0 ("System is not fully connected, not flushing.");
:return false;
}
:local AllDone true;
:local QueueLen [ :len $GotifyQueue ];
:if ([ :len [ /system/scheduler/find where name="_FlushGotifyQueue" ] ] > 0 && $QueueLen = 0) do={
$LogPrint warning $0 ("Flushing Gotify messages from scheduler, but queue is empty.");
}
:foreach Id,Message in=$GotifyQueue do={
:if ([ :typeof $Message ] = "array" ) do={
:do {
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=($Message->"headers") http-data=[ :serialize to=json ($Message->"message") ] \
($Message->"url") as-value;
:set ($GotifyQueue->$Id);
} on-error={
$LogPrint debug $0 ("Sending queued Gotify message failed.");
:set AllDone false;
}
}
}
:if ($AllDone = true && $QueueLen = [ :len $GotifyQueue ]) do={
/system/scheduler/remove [ find where name="_FlushGotifyQueue" ];
:set GotifyQueue;
}
} on-error={
:global ExitError; $ExitError false $0;
} }
# send notification via Gotify - expects one array argument
:set ($NotificationFunctions->"gotify") do={
:local Notification $1;
:global Identity;
:global IdentityExtra;
:global GotifyQueue;
:global GotifyServer;
:global GotifyServerOverride;
:global GotifyToken;
:global GotifyTokenOverride;
:global EitherOr;
:global FetchUserAgentStr;
:global IfThenElse;
:global LogPrint;
:global SymbolForNotification;
:local Server [ $EitherOr ($GotifyServerOverride->($Notification->"origin")) $GotifyServer ];
:local Token [ $EitherOr ($GotifyTokenOverride->($Notification->"origin")) $GotifyToken ];
:if ([ :len $Token ] = 0) do={
:return false;
}
:local Url ("https://" . $Server . "/message");
:local Headers ({ [ $FetchUserAgentStr ($Notification->"origin") ]; \
("X-Gotify-Key: " . $Token); "Content-Type: application/json" });
:local Message ({
"title"=("[" . $IdentityExtra . $Identity . "] " . ($Notification->"subject")); \
"message"=($Notification->"message"); \
"priority"=[ :tonum [ $IfThenElse ($Notification->"silent") 2 5 ] ] });
:do {
/tool/fetch check-certificate=yes-without-crl output=none http-method=post \
http-header-field=$Headers http-data=[ :serialize to=json $Message ] $Url as-value;
} on-error={
$LogPrint info $0 ("Failed sending Gotify notification! Queuing...");
:if ([ :typeof $GotifyQueue ] = "nothing") do={
:set GotifyQueue ({});
}
:set ($Message->"message") (($Notification->"message") . "\n" . \
[ $SymbolForNotification "alarm-clock" ] . "This message was queued since " . \
[ /system/clock/get date ] . " " . [ /system/clock/get time ] . " and may be obsolete.");
:set ($GotifyQueue->[ :len $GotifyQueue ]) { url=$Url; headers=$Headers; message=$Message };
:if ([ :len [ /system/scheduler/find where name="_FlushGotifyQueue" ] ] = 0) do={
/system/scheduler/add name="_FlushGotifyQueue" interval=1m start-time=startup \
on-event=(":global FlushGotifyQueue; \$FlushGotifyQueue;");
}
}
}
# purge the Gotify queue
:set PurgeGotifyQueue do={
:global GotifyQueue;
/system/scheduler/remove [ find where name="_FlushGotifyQueue" ];
:set GotifyQueue;
}
# send notification via Gotify - expects at least two string arguments
:set SendGotify do={
:do {
:global SendGotify2;
$SendGotify2 ({ origin=$0; subject=$1; message=$2; silent=$3 });
} on-error={
:global ExitError; $ExitError false $0;
}
}
# send notification via Gotify - expects one array argument
:set SendGotify2 do={
:local Notification $1;
:global NotificationFunctions;
($NotificationFunctions->"gotify") ("\$NotificationFunctions->\"gotify\"") $Notification;
}

View file

@ -61,6 +61,7 @@
134="Enhanced 'mod/notification-telegram' and 'telegram-chat' to support topics in groups.";
135="Introduced helper function '\$GetTelegramChatId' for 'mod/notification-telegram' which helps retrieve information.";
136="Introduced script 'check-perpetual-license' to check for license state on CHR.";
137="Added support to send notifications via Gotify (gotify.net).";
};
# Migration steps to be applied on script updates