mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-06-21 01:25:52 +02:00
check-routeros-update: split off check-perpetual-license...
... and also add documentation, screenshot, etc.
This commit is contained in:
parent
16c9ce437e
commit
3c30276e23
8 changed files with 152 additions and 39 deletions
|
@ -225,6 +225,7 @@ Available scripts
|
||||||
* [Renew certificates and notify on expiration](doc/check-certificates.md)
|
* [Renew certificates and notify on expiration](doc/check-certificates.md)
|
||||||
* [Notify about health state](doc/check-health.md)
|
* [Notify about health state](doc/check-health.md)
|
||||||
* [Notify on LTE firmware upgrade](doc/check-lte-firmware-upgrade.md)
|
* [Notify on LTE firmware upgrade](doc/check-lte-firmware-upgrade.md)
|
||||||
|
* [Check perpetual license on CHR](doc/check-perpetual-license.md)
|
||||||
* [Notify on RouterOS update](doc/check-routeros-update.md)
|
* [Notify on RouterOS update](doc/check-routeros-update.md)
|
||||||
* [Collect MAC addresses in wireless access list](doc/collect-wireless-mac.md)
|
* [Collect MAC addresses in wireless access list](doc/collect-wireless-mac.md)
|
||||||
* [Use wireless network with daily psk](doc/daily-psk.md)
|
* [Use wireless network with daily psk](doc/daily-psk.md)
|
||||||
|
|
78
check-perpetual-license.rsc
Normal file
78
check-perpetual-license.rsc
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#!rsc by RouterOS
|
||||||
|
# RouterOS script: check-perpetual-license
|
||||||
|
# Copyright (c) 2025 Christian Hesse <mail@eworm.de>
|
||||||
|
# https://rsc.eworm.de/COPYING.md
|
||||||
|
#
|
||||||
|
# requires RouterOS, version=7.15
|
||||||
|
#
|
||||||
|
# check perpetual license on CHR
|
||||||
|
# https://rsc.eworm.de/doc/check-perpetual-license.md
|
||||||
|
|
||||||
|
:global GlobalFunctionsReady;
|
||||||
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
|
:local ExitOK false;
|
||||||
|
:do {
|
||||||
|
:local ScriptName [ :jobname ];
|
||||||
|
|
||||||
|
:global Identity;
|
||||||
|
:global SentCertificateNotification;
|
||||||
|
|
||||||
|
:global LogPrint;
|
||||||
|
:global ScriptLock;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global WaitFullyConnected;
|
||||||
|
|
||||||
|
:if ([ $ScriptLock $ScriptName ] = false) do={
|
||||||
|
:set ExitOK true;
|
||||||
|
:error false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$WaitFullyConnected;
|
||||||
|
|
||||||
|
:local License [ /system/license/get ];
|
||||||
|
:if ([ :typeof ($License->"deadline-at") ] != "str") do={
|
||||||
|
$LogPrint info $ScriptName ("This device does not have a perpetual license.");
|
||||||
|
:set ExitOK true;
|
||||||
|
:error true;
|
||||||
|
}
|
||||||
|
|
||||||
|
:if ([ :len ($License->"next-renewal-at") ] = 0 && ($License->"limited-upgrades") = true) do={
|
||||||
|
$LogPrint warning $ScriptName ("Your license expired on " . ($License->"deadline-at") . "!");
|
||||||
|
:if ($SentCertificateNotification != "expired") do={
|
||||||
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
|
subject=([ $SymbolForNotification "warning-sign" ] . "License expired!"); \
|
||||||
|
message=("Your license expired on " . ($License->"deadline-at") . \
|
||||||
|
", can no longer update RouterOS on " . $Identity . "...") });
|
||||||
|
:set SentCertificateNotification "expired";
|
||||||
|
}
|
||||||
|
:set ExitOK true;
|
||||||
|
:error true;
|
||||||
|
}
|
||||||
|
|
||||||
|
:if ([ :totime ($License->"deadline-at") ] - 3w < [ :timestamp ]) do={
|
||||||
|
$LogPrint warning $ScriptName ("Your license will expire on " . ($License->"deadline-at") . "!");
|
||||||
|
:if ($SentCertificateNotification != "warning") do={
|
||||||
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
|
subject=([ $SymbolForNotification "warning-sign" ] . "License about to expire!"); \
|
||||||
|
message=("Your license failed to renew and is about to expire on " . \
|
||||||
|
($License->"deadline-at") . " on " . $Identity . "...") });
|
||||||
|
:set SentCertificateNotification "warning";
|
||||||
|
}
|
||||||
|
:set ExitOK true;
|
||||||
|
:error true;
|
||||||
|
}
|
||||||
|
|
||||||
|
:if ([ :typeof $SentCertificateNotification ] = "str" && \
|
||||||
|
[ :totime ($License->"deadline-at") ] - 4w > [ :timestamp ]) do={
|
||||||
|
$LogPrint info $ScriptName ("Your license was successfully renewed.");
|
||||||
|
$SendNotification2 ({ origin=$ScriptName; \
|
||||||
|
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "License renewed"); \
|
||||||
|
message=("Your license was successfully renewed on " . $Identity . \
|
||||||
|
". It is now valid until " . ($License->"deadline-at") . ".") });
|
||||||
|
:set SentCertificateNotification;
|
||||||
|
}
|
||||||
|
} on-error={
|
||||||
|
:global ExitError; $ExitError $ExitOK [ :jobname ];
|
||||||
|
}
|
|
@ -22,7 +22,6 @@
|
||||||
:global SafeUpdateNeighborIdentity;
|
:global SafeUpdateNeighborIdentity;
|
||||||
:global SafeUpdatePatch;
|
:global SafeUpdatePatch;
|
||||||
:global SafeUpdateUrl;
|
:global SafeUpdateUrl;
|
||||||
:global SentCertificateNotification;
|
|
||||||
:global SentRouterosUpdateNotification;
|
:global SentRouterosUpdateNotification;
|
||||||
|
|
||||||
:global DeviceInfo;
|
:global DeviceInfo;
|
||||||
|
@ -67,43 +66,6 @@
|
||||||
:error "A reboot for update is already scheduled.";
|
:error "A reboot for update is already scheduled.";
|
||||||
}
|
}
|
||||||
|
|
||||||
:local License [ /system/license/get ];
|
|
||||||
:if ([ :typeof ($License->"deadline-at") ] = "str") do={
|
|
||||||
:if ([ :len ($License->"next-renewal-at") ] = 0 && ($License->"limited-upgrades") = true) do={
|
|
||||||
$LogPrint warning $ScriptName ("Your license expired on " . ($License->"deadline-at") . "!");
|
|
||||||
:if ($SentCertificateNotification != "expired") do={
|
|
||||||
$SendNotification2 ({ origin=$ScriptName; \
|
|
||||||
subject=([ $SymbolForNotification "warning-sign" ] . "License expired!"); \
|
|
||||||
message=("Your license expired on " . ($License->"deadline-at") . \
|
|
||||||
", can no longer update RouterOS on " . $Identity . "...") });
|
|
||||||
:set SentCertificateNotification "expired";
|
|
||||||
}
|
|
||||||
:set ExitOK true;
|
|
||||||
:error false;
|
|
||||||
}
|
|
||||||
|
|
||||||
:if ([ :totime ($License->"deadline-at") ] - 3w < [ :timestamp ]) do={
|
|
||||||
$LogPrint warning $ScriptName ("Your license will expire on " . ($License->"deadline-at") . "!");
|
|
||||||
:if ($SentCertificateNotification != "warning") do={
|
|
||||||
$SendNotification2 ({ origin=$ScriptName; \
|
|
||||||
subject=([ $SymbolForNotification "warning-sign" ] . "License about to expire!"); \
|
|
||||||
message=("Your license failed to renew and is about to expire on " . \
|
|
||||||
($License->"deadline-at") . " on " . $Identity . "...") });
|
|
||||||
:set SentCertificateNotification "warning";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:if ([ :typeof $SentCertificateNotification ] = "str" && \
|
|
||||||
[ :totime ($License->"deadline-at") ] - 4w > [ :timestamp ]) do={
|
|
||||||
$LogPrint info $ScriptName ("Your license was successfully renewed.");
|
|
||||||
$SendNotification2 ({ origin=$ScriptName; \
|
|
||||||
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "License renewed"); \
|
|
||||||
message=("Your license was successfully renewed on " . $Identity . \
|
|
||||||
". It is now valid until " . ($License->"deadline-at") . ".") });
|
|
||||||
:set SentCertificateNotification;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$LogPrint debug $ScriptName ("Checking for updates...");
|
$LogPrint debug $ScriptName ("Checking for updates...");
|
||||||
/system/package/update/check-for-updates without-paging as-value;
|
/system/package/update/check-for-updates without-paging as-value;
|
||||||
:local Update [ /system/package/update/get ];
|
:local Update [ /system/package/update/get ];
|
||||||
|
|
BIN
doc/check-perpetual-license.d/notification.avif
Normal file
BIN
doc/check-perpetual-license.d/notification.avif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
70
doc/check-perpetual-license.md
Normal file
70
doc/check-perpetual-license.md
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
Check perpetual license on CHR
|
||||||
|
==============================
|
||||||
|
|
||||||
|
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
||||||
|
[](https://github.com/eworm-de/routeros-scripts/network)
|
||||||
|
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||||
|
[](https://mikrotik.com/download/changelogs/)
|
||||||
|
[](https://t.me/routeros_scripts)
|
||||||
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
||||||
|
|
||||||
|
[⬅️ Go back to main README](../README.md)
|
||||||
|
|
||||||
|
> ℹ️ **Info**: This script can not be used on its own but requires the base
|
||||||
|
> installation. See [main README](../README.md) for details.
|
||||||
|
|
||||||
|
Description
|
||||||
|
-----------
|
||||||
|
|
||||||
|
On *Cloud Hosted Router* (*CHR*) the licensing is perpetual: Buy once, use
|
||||||
|
forever - but it needs regular renewal. This script checks licensing state
|
||||||
|
and sends a notification to warn before expiration.
|
||||||
|
|
||||||
|
### Sample notification
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Requirements and installation
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Just install the script:
|
||||||
|
|
||||||
|
$ScriptInstallUpdate check-perpetual-license;
|
||||||
|
|
||||||
|
And add a scheduler for automatic update notification:
|
||||||
|
|
||||||
|
/system/scheduler/add interval=1d name=check-perpetual-license on-event="/system/script/run check-perpetual-license;" start-time=startup;
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
|
||||||
|
No extra configuration is required for this script, but notification
|
||||||
|
settings are required for
|
||||||
|
[e-mail](mod/notification-email.md),
|
||||||
|
[matrix](mod/notification-matrix.md),
|
||||||
|
[ntfy](mod/notification-ntfy.md) and/or
|
||||||
|
[telegram](mod/notification-telegram.md).
|
||||||
|
|
||||||
|
Usage and invocation
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Be notified when run from scheduler or run it manually:
|
||||||
|
|
||||||
|
/system/script/run check-perpetual-license;
|
||||||
|
|
||||||
|
Tips & Tricks
|
||||||
|
-------------
|
||||||
|
|
||||||
|
The script checks for full connectivity before acting, so scheduling at
|
||||||
|
startup is perfectly valid:
|
||||||
|
|
||||||
|
/system/scheduler/add name=check-perpetual-license@startup on-event="/system/script/run check-perpetual-license;" start-time=startup;
|
||||||
|
|
||||||
|
See also
|
||||||
|
--------
|
||||||
|
|
||||||
|
* [Notify on RouterOS update](check-routeros-update.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
[⬅️ Go back to main README](../README.md)
|
||||||
|
[⬆️ Go back to top](#top)
|
|
@ -99,6 +99,7 @@ startup is perfectly valid:
|
||||||
See also
|
See also
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
* [Check perpetual license on CHR](check-perpetual-license.md)
|
||||||
* [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md)
|
* [Automatically upgrade firmware and reboot](firmware-upgrade-reboot.md)
|
||||||
* [Manage system update](packages-update.md)
|
* [Manage system update](packages-update.md)
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
# Git commit id & info, expected configuration version
|
# Git commit id & info, expected configuration version
|
||||||
:global CommitId "unknown";
|
:global CommitId "unknown";
|
||||||
:global CommitInfo "unknown";
|
:global CommitInfo "unknown";
|
||||||
:global ExpectedConfigVersion 135;
|
:global ExpectedConfigVersion 136;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
133="Updated the default configuration for 'fw-addr-lists', deprecated lists were removed, a collective list was added.";
|
133="Updated the default configuration for 'fw-addr-lists', deprecated lists were removed, a collective list was added.";
|
||||||
134="Enhanced 'mod/notification-telegram' and 'telegram-chat' to support topics in groups.";
|
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.";
|
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.";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Migration steps to be applied on script updates
|
# Migration steps to be applied on script updates
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue