Skip to content

Commit 45b82e9

Browse files
committed
Add check LTE state update script
1 parent 7594345 commit 45b82e9

File tree

3 files changed

+204
-0
lines changed

3 files changed

+204
-0
lines changed

check-lte-state-update

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!rsc by RouterOS
2+
# RouterOS script: check-lte-state-update
3+
# Copyright (c) 2018-2022 Christian Hesse <[email protected]>
4+
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
5+
#
6+
# check for LTE state, send notification
7+
# https://git.eworm.de/cgit/routeros-scripts/about/doc/check-lte-state-update.md
8+
9+
:local 0 "check-lte-state-update";
10+
:global GlobalFunctionsReady;
11+
:while ($GlobalFunctionsReady != true) do={ :delay 500ms; }
12+
13+
:global CurrentLteStatePrimaryBand
14+
15+
:if ([ :typeof $CurrentLteStatePrimaryBand ] != "array") do={
16+
:global CurrentLteStatePrimaryBand ({});
17+
}
18+
19+
:global CurrentLteStateCaBand
20+
21+
:if ([ :typeof $CurrentLteStateCaBand ] != "array") do={
22+
:global CurrentLteStateCaBand ({});
23+
}
24+
25+
:global CurrentLteStateIp
26+
27+
:if ([ :typeof $CurrentLteStateIp ] != "array") do={
28+
:global CurrentLteStateIp ({});
29+
}
30+
31+
:global CheckLteStateUpdateBtestHost
32+
:global CheckLteStateUpdateBtestUser
33+
:global CheckLteStateUpdateBtestPassword
34+
35+
$LogPrintExit2 debug $0 ("Prepared") false;
36+
37+
:local CheckInterface do={
38+
:local Interface $1;
39+
40+
:global Identity;
41+
:global SentLteStateUpdateNotification;
42+
:global CurrentLteStatePrimaryBand;
43+
:global CurrentLteStateCaBand;
44+
:global CurrentLteStateIp;
45+
:global CharacterReplace;
46+
:global LogPrintExit2;
47+
:global ScriptFromTerminal;
48+
:global SendNotification2;
49+
:global SymbolForNotification;
50+
:global CheckLteStateUpdateBtestHost;
51+
:global CheckLteStateUpdateBtestUser;
52+
:global CheckLteStateUpdateBtestPassword;
53+
54+
:local IntName [ /interface/lte/get $Interface name ];
55+
:local Ip [ /ip address get [ find interface=$IntName ] address ]
56+
:local Info;
57+
:do {
58+
:set Info [ /interface/lte/monitor $Interface once as-value ];
59+
} on-error={
60+
$LogPrintExit2 debug $0 ("Could not get latest LTE monitoring information for interface " . \
61+
$IntName . ".") false;
62+
:return false;
63+
}
64+
:local CurrentOperator ($Info->"current-operator");
65+
:local PrimaryBand ($Info->"primary-band");
66+
:local CaBand ($Info->"ca-band");
67+
:local Sinr ($Info->"sinr");
68+
:local Rssi ($Info->"rssi");
69+
:local Rsrq ($Info->"rsrq");
70+
:local Rsrp ($Info->"rsrp");
71+
:local Ri ($Info->"ri");
72+
:local PassedCheck false;
73+
:local CurrentPrimaryBand ($CurrentLteStatePrimaryBand->$IntName);
74+
:local CurrentCaBand ($CurrentLteStateCaBand->$IntName);
75+
:local CurrentIP ($CurrentLteStateIp->$IntName);
76+
77+
:local IpMessage;
78+
:local PrimaryBandMessage;
79+
:local CaBandMessage
80+
81+
:if ($CurrentIP != $Ip) do={
82+
:set IpMessage ("IP address changed from $CurrentIP to $Ip\n");
83+
:set ($CurrentLteStateIp->$IntName) $Ip;
84+
:set PassedCheck (true);
85+
}
86+
:if ($CurrentPrimaryBand != $PrimaryBand) do={
87+
:set PrimaryBandMessage ("Primary band changed from $CurrentPrimaryBand to $PrimaryBand\n");
88+
:set ($CurrentLteStatePrimaryBand->$IntName) $PrimaryBand;
89+
:set PassedCheck (true);
90+
}
91+
:if ($CurrentCaBand != $CaBand) do={
92+
:set CaBandMessage ("CA band changed\n");
93+
:set ($CurrentLteStateCaBand->$IntName) $CaBand;
94+
:set PassedCheck (true);
95+
}
96+
97+
:if ($PassedCheck = false) do={
98+
:if ([ $ScriptFromTerminal $0 ] = true) do={
99+
$LogPrintExit2 info $0 ("No state update for LTE interface " . $IntName . ".") false;
100+
}
101+
:return true;
102+
}
103+
104+
:local DownloadSpeed 0;
105+
:local UploadSpeed 0;
106+
107+
$LogPrintExit2 debug $0 ("Checking the speed for interface " . \
108+
$IntName . ".") false;
109+
/tool speed-test address=[:resolve $CheckLteStateUpdateBtestHost] user=$CheckLteStateUpdateBtestUser password=$CheckLteStateUpdateBtestPassword do={
110+
:set DownloadSpeed ($"tcp-download");
111+
:set UploadSpeed ($"tcp-upload");
112+
}
113+
114+
:local Message;
115+
:set $Message ("LTE interface $IntName on $Identity has the following comm values:
116+
$IpMessage$PrimaryBandMessage$CaBandMessage
117+
CurrentOperator: $CurrentOperator
118+
PrimaryBand: $PrimaryBand
119+
sinr: $Sinr
120+
rssi: $Rssi
121+
rsrq: $Rsrq
122+
rsrp: $Rsrp
123+
ri: $Ri
124+
125+
btest:
126+
download: $DownloadSpeed
127+
upload: $UploadSpeed
128+
");
129+
130+
:if (($SentLteStateUpdateNotification->$IntName) = ($Message)) do={
131+
$LogPrintExit2 debug $0 ("Already sent the LTE state update notification for message " . \
132+
($Message) . ".") false;
133+
:return false;
134+
}
135+
136+
$LogPrintExit2 info $0 ("A new LTE state " . ($Message) . " for " . \
137+
"LTE interface " . $IntName . ".") false;
138+
$SendNotification2 ({ origin=$0; \
139+
subject=([ $SymbolForNotification "sparkles" ] . "LTE state update"); \
140+
message=($Message); silent=true });
141+
:set ($SentLteStateUpdateNotification->$IntName) ($Message);
142+
}
143+
144+
:foreach Interface in=[ /interface/lte/find ] do={
145+
$CheckInterface $Interface;
146+
}

doc/check-lte-state-update.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Notify on LTE state update
2+
==========================
3+
4+
[◀ Go back to main README](../README.md)
5+
6+
> ℹ️ **Info**: This script can not be used on its own but requires the base
7+
> installation. See [main README](../README.md) for details.
8+
9+
Description
10+
-----------
11+
12+
This script is run from scheduler periodically, checking for LTE state changes.
13+
14+
### Sample notification
15+
16+
![check-lte-state-update notification](check-lte-state-update.d/notification.avif)
17+
18+
Requirements and installation
19+
-----------------------------
20+
21+
Just install the script:
22+
23+
$ScriptInstallUpdate check-lte-state-update;
24+
25+
... and create a scheduler:
26+
27+
/system/scheduler/add interval=1h name=check-lte-state-update on-event="/system/script/run check-lte-state-update;" start-time=startup;
28+
29+
Configuration
30+
-------------
31+
32+
The configuration goes to `global-config-overlay`, this is the only parameter:
33+
34+
* `CheckLteStateUpdateBtestHost`: host to test for internet connectivity (btest server)
35+
* `CheckLteStateUpdateBtestUser`: user to test for internet connectivity (btest server)
36+
* `CheckLteStateUpdateBtestPassword`: password to test for internet connectivity (btest server)
37+
38+
Also notification settings are required for
39+
[e-mail](mod/notification-email.md),
40+
[matrix](mod/notification-matrix.md) and/or
41+
[telegram](mod/notification-telegram.md).
42+
43+
See also
44+
--------
45+
46+
* [Notify on RouterOS update](check-routeros-update.md)
47+
* [Install LTE firmware upgrade](unattended-lte-firmware-upgrade.md)
48+
49+
---
50+
[◀ Go back to main README](../README.md)
51+
[▲ Go back to top](#top)

global-config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@
147147
# add more here...
148148
};
149149

150+
# host to test for internet connectivity (btest server)
151+
:global CheckLteStateUpdateBtestHost "example.com";
152+
# user to test for internet connectivity (btest server)
153+
:global CheckLteStateUpdateBtestUser "mikrotik";
154+
# password to test for internet connectivity (btest server)
155+
:global CheckLteStateUpdateBtestPassword "v3ry-s3cr3t";
156+
150157
# This is the address used to send gps data to.
151158
:global GpsTrackUrl "https://example.com/index.php";
152159

0 commit comments

Comments
 (0)