mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-02-24 09:09:36 +00:00
Add check LTE state update script
This commit is contained in:
parent
7594345da8
commit
dcf7445c25
3 changed files with 229 additions and 0 deletions
159
check-lte-state-update
Normal file
159
check-lte-state-update
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
#!rsc by RouterOS
|
||||||
|
# RouterOS script: check-lte-state-update
|
||||||
|
# Copyright (c) 2018-2022 Christian Hesse <mail@eworm.de>
|
||||||
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||||
|
#
|
||||||
|
# check for LTE state, send notification
|
||||||
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/check-lte-state-update.md
|
||||||
|
|
||||||
|
:local 0 "check-lte-state-update";
|
||||||
|
:global GlobalFunctionsReady;
|
||||||
|
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
|
||||||
|
|
||||||
|
:global CurrentLteStatePrimaryBand
|
||||||
|
|
||||||
|
:if ([ :typeof $CurrentLteStatePrimaryBand ] != "array") do={
|
||||||
|
:global CurrentLteStatePrimaryBand ({});
|
||||||
|
}
|
||||||
|
|
||||||
|
:global CurrentLteStateCaBand
|
||||||
|
|
||||||
|
:if ([ :typeof $CurrentLteStateCaBand ] != "array") do={
|
||||||
|
:global CurrentLteStateCaBand ({});
|
||||||
|
}
|
||||||
|
|
||||||
|
:global CurrentLteStateIp
|
||||||
|
|
||||||
|
:if ([ :typeof $CurrentLteStateIp ] != "array") do={
|
||||||
|
:global CurrentLteStateIp ({});
|
||||||
|
}
|
||||||
|
|
||||||
|
$LogPrintExit2 debug $0 ("Prepared") false;
|
||||||
|
|
||||||
|
:local CheckInterface do={
|
||||||
|
:local Interface $1;
|
||||||
|
|
||||||
|
:global Identity;
|
||||||
|
:global SentLteStateUpdateNotification;
|
||||||
|
:global CurrentLteStatePrimaryBand;
|
||||||
|
:global CurrentLteStateCaBand;
|
||||||
|
:global CurrentLteStateIp;
|
||||||
|
:global CharacterReplace;
|
||||||
|
:global LogPrintExit2;
|
||||||
|
:global ScriptFromTerminal;
|
||||||
|
:global SendNotification2;
|
||||||
|
:global SymbolForNotification;
|
||||||
|
:global CheckLteStateUpdateBtestHost;
|
||||||
|
:global CheckLteStateUpdateBtestUser;
|
||||||
|
:global CheckLteStateUpdateBtestPassword;
|
||||||
|
:global CheckLteStateUpdateIp;
|
||||||
|
:if ([ :typeof $CheckLteStateUpdateIp ] != "bool") do={
|
||||||
|
:global CheckLteStateUpdateIp (true);
|
||||||
|
}
|
||||||
|
:global CheckLteStateUpdatePrimaryBand;
|
||||||
|
:if ([ :typeof $CheckLteStateUpdatePrimaryBand ] != "bool") do={
|
||||||
|
:global CheckLteStateUpdatePrimaryBand (false);
|
||||||
|
}
|
||||||
|
:global CheckLteStateUpdateCABand;
|
||||||
|
:if ([ :typeof $CheckLteStateUpdateCABand ] != "bool") do={
|
||||||
|
:global CheckLteStateUpdateCABand (false);
|
||||||
|
}
|
||||||
|
|
||||||
|
:local IntName [ /interface/lte/get $Interface name ];
|
||||||
|
:local Ip [ /ip address get [ find interface=$IntName ] address ]
|
||||||
|
:local Info;
|
||||||
|
:do {
|
||||||
|
:set Info [ /interface/lte/monitor $Interface once as-value ];
|
||||||
|
} on-error={
|
||||||
|
$LogPrintExit2 debug $0 ("Could not get latest LTE monitoring information for interface " . \
|
||||||
|
$IntName . ".") false;
|
||||||
|
:return false;
|
||||||
|
}
|
||||||
|
:local CurrentOperator ($Info->"current-operator");
|
||||||
|
:local PrimaryBand ($Info->"primary-band");
|
||||||
|
:local CaBand ($Info->"ca-band");
|
||||||
|
:local Sinr ($Info->"sinr");
|
||||||
|
:local Rssi ($Info->"rssi");
|
||||||
|
:local Rsrq ($Info->"rsrq");
|
||||||
|
:local Rsrp ($Info->"rsrp");
|
||||||
|
:local Ri ($Info->"ri");
|
||||||
|
:local PassedCheck false;
|
||||||
|
:local CurrentPrimaryBand ($CurrentLteStatePrimaryBand->$IntName);
|
||||||
|
:local CurrentCaBand ($CurrentLteStateCaBand->$IntName);
|
||||||
|
:local CurrentIP ($CurrentLteStateIp->$IntName);
|
||||||
|
|
||||||
|
:local IpMessage;
|
||||||
|
:local PrimaryBandMessage;
|
||||||
|
:local CaBandMessage
|
||||||
|
|
||||||
|
:if ($CheckLteStateUpdateIp && $CurrentIP != $Ip) do={
|
||||||
|
:set IpMessage ("IP address changed from $CurrentIP to $Ip\n");
|
||||||
|
:set ($CurrentLteStateIp->$IntName) $Ip;
|
||||||
|
:set PassedCheck (true);
|
||||||
|
}
|
||||||
|
:if ($CheckLteStateUpdatePrimaryBand && $CurrentPrimaryBand != $PrimaryBand) do={
|
||||||
|
:set PrimaryBandMessage ("Primary band changed from $CurrentPrimaryBand to $PrimaryBand\n");
|
||||||
|
:set ($CurrentLteStatePrimaryBand->$IntName) $PrimaryBand;
|
||||||
|
:set PassedCheck (true);
|
||||||
|
}
|
||||||
|
:if ($CheckLteStateUpdateCABand && $CurrentCaBand != $CaBand) do={
|
||||||
|
:set CaBandMessage ("CA band changed\n");
|
||||||
|
:set ($CurrentLteStateCaBand->$IntName) $CaBand;
|
||||||
|
:set PassedCheck (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
:if ($PassedCheck = false) do={
|
||||||
|
:if ([ $ScriptFromTerminal $0 ] = true) do={
|
||||||
|
$LogPrintExit2 info $0 ("No state update for LTE interface " . $IntName . ".") false;
|
||||||
|
}
|
||||||
|
:return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
:local BtestMessage;
|
||||||
|
:if ($CheckLteStateUpdateBtestHost) do={
|
||||||
|
$LogPrintExit2 debug $0 ("Checking the speed for interface " . \
|
||||||
|
$IntName . ".") false;
|
||||||
|
/tool speed-test test-duration=5 address=[:resolve $CheckLteStateUpdateBtestHost] user=$CheckLteStateUpdateBtestUser password=$CheckLteStateUpdateBtestPassword do={
|
||||||
|
:local DownloadSpeed;
|
||||||
|
:local UploadSpeed;
|
||||||
|
|
||||||
|
:set DownloadSpeed ($"tcp-download");
|
||||||
|
:set UploadSpeed ($"tcp-upload");
|
||||||
|
:set BtestMessage ("
|
||||||
|
btest:
|
||||||
|
$DownloadSpeed
|
||||||
|
$UploadSpeed
|
||||||
|
");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:local Message;
|
||||||
|
:set $Message ("LTE interface $IntName on $Identity has the following comm values:
|
||||||
|
$IpMessage$PrimaryBandMessage$CaBandMessage
|
||||||
|
CurrentOperator: $CurrentOperator
|
||||||
|
PrimaryBand: $PrimaryBand
|
||||||
|
sinr: $Sinr
|
||||||
|
rssi: $Rssi
|
||||||
|
rsrq: $Rsrq
|
||||||
|
rsrp: $Rsrp
|
||||||
|
ri: $Ri
|
||||||
|
$BtestMessage
|
||||||
|
");
|
||||||
|
|
||||||
|
:if (($SentLteStateUpdateNotification->$IntName) = ($Message)) do={
|
||||||
|
$LogPrintExit2 debug $0 ("Already sent the LTE state update notification for message " . \
|
||||||
|
($Message) . ".") false;
|
||||||
|
:return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$LogPrintExit2 info $0 ("A new LTE state " . ($Message) . " for " . \
|
||||||
|
"LTE interface " . $IntName . ".") false;
|
||||||
|
$SendNotification2 ({ origin=$0; \
|
||||||
|
subject=([ $SymbolForNotification "sparkles" ] . "LTE state update"); \
|
||||||
|
message=($Message); silent=true });
|
||||||
|
:set ($SentLteStateUpdateNotification->$IntName) ($Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
:foreach Interface in=[ /interface/lte/find ] do={
|
||||||
|
$CheckInterface $Interface;
|
||||||
|
}
|
||||||
54
doc/check-lte-state-update.md
Normal file
54
doc/check-lte-state-update.md
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
Notify on LTE state update
|
||||||
|
==========================
|
||||||
|
|
||||||
|
[◀ 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
|
||||||
|
-----------
|
||||||
|
|
||||||
|
This script is run from scheduler periodically, checking for LTE state changes.
|
||||||
|
|
||||||
|
### Sample notification
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Requirements and installation
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
Just install the script:
|
||||||
|
|
||||||
|
$ScriptInstallUpdate check-lte-state-update;
|
||||||
|
|
||||||
|
... and create a scheduler:
|
||||||
|
|
||||||
|
/system/scheduler/add interval=1h name=check-lte-state-update on-event="/system/script/run check-lte-state-update;" start-time=startup;
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
-------------
|
||||||
|
|
||||||
|
The configuration goes to `global-config-overlay`, this is the only parameter:
|
||||||
|
|
||||||
|
* `CheckLteStateUpdateBtestHost`: host to test for internet connectivity (btest server), leave empty to disable internet connectivity check
|
||||||
|
* `CheckLteStateUpdateBtestUser`: user to test for internet connectivity (btest server)
|
||||||
|
* `CheckLteStateUpdateBtestPassword`: password to test for internet connectivity (btest server)
|
||||||
|
* `CheckLteStateUpdateIP`: check the IP address, set to false to disable IP address check (default true, enabled)
|
||||||
|
* `CheckLteStateUpdatePrimaryBand`: check the primary band, set to true to enable primary band check, (default false, disabled)
|
||||||
|
* `CheckLteStateUpdateCABand`: check the CA band, set to true to enable CA band check, (default false, disabled)
|
||||||
|
|
||||||
|
Also notification settings are required for
|
||||||
|
[e-mail](mod/notification-email.md),
|
||||||
|
[matrix](mod/notification-matrix.md) and/or
|
||||||
|
[telegram](mod/notification-telegram.md).
|
||||||
|
|
||||||
|
See also
|
||||||
|
--------
|
||||||
|
|
||||||
|
* [Notify on RouterOS update](check-routeros-update.md)
|
||||||
|
* [Install LTE firmware upgrade](unattended-lte-firmware-upgrade.md)
|
||||||
|
|
||||||
|
---
|
||||||
|
[◀ Go back to main README](../README.md)
|
||||||
|
[▲ Go back to top](#top)
|
||||||
|
|
@ -147,6 +147,22 @@
|
||||||
# add more here...
|
# add more here...
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# host to test for internet connectivity (btest server, disabled by default)
|
||||||
|
:global CheckLteStateUpdateBtestHost;
|
||||||
|
# :global CheckLteStateUpdateBtestHost "example.com"; # enable btest
|
||||||
|
# user to test for internet connectivity (btest server)
|
||||||
|
:global CheckLteStateUpdateBtestUser;
|
||||||
|
# :global CheckLteStateUpdateBtestUser "mikrotik"; # enable btest
|
||||||
|
# password to test for internet connectivity (btest server)
|
||||||
|
:global CheckLteStateUpdateBtestPassword;
|
||||||
|
# :global CheckLteStateUpdateBtestPassword "v3ry-s3cr3t"; # enable btest
|
||||||
|
:global CheckLteStateUpdateIP true;
|
||||||
|
# :global CheckLteStateUpdateIP false; # disable checking IP
|
||||||
|
:global CheckLteStateUpdatePrimaryBand false;
|
||||||
|
# :global CheckLteStateUpdatePrimaryBand true; # enable checking primary band
|
||||||
|
:global CheckLteStateUpdateCABand false;
|
||||||
|
# :global CheckLteStateUpdateCABand true; # enable checking CA band
|
||||||
|
|
||||||
# This is the address used to send gps data to.
|
# This is the address used to send gps data to.
|
||||||
:global GpsTrackUrl "https://example.com/index.php";
|
:global GpsTrackUrl "https://example.com/index.php";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue