Good day, everyone!
This time, I decided to describe a situation that doesn't seem particularly addressed on the internet, although there are some hints about it; most of it came from long, methodical digging through the code and Mikrotik's wiki.
The task is to implement SMS management of several devices, for example, turning ports on and off.
Available:
- Secondary router CRS317-1G-16S+
- Mikrotik NETMETAL 5 access point
- LTE modem R11e-LTE
Let's start with the fact that the wonderful Netmetal 5 access point features a soldered SIM card slot and a port for installing the LTE modem. Therefore, we purchased essentially the best modem available that was supported by the access point's operating system, specifically the R11e-LTE. The unit was disassembled, and everything was installed in its place (although you should know that the SIM card is located under the modem and cannot be accessed without removing the main board), so please check the SIM card for functionality, or you will have to disassemble the access point several times.
Next, we drilled a couple of holes in the case, installed 2 pigtails, and secured the ends to the modem. Unfortunately, there are no photos of the process. On the other hand, we attached universal antennas with magnetic bases to the pigtails.
The main setup steps are described quite well online, except for some minor interaction quirks. For example, the modem stops receiving SMS messages when 5 messages are in the Inbox, and clearing messages or restarting the modem doesn't always resolve the issue. However, in version 6.44.1, reception works more stably. The Inbox displays the last 4 SMS messages, while the others are automatically deleted and do not interfere with operation.
The main goal of the experiment is to turn interfaces on and off on two routers within the same physical network. The main difficulty was that Mikrotik does not support management via SNMP but only allows reading values. Therefore, we had to dig in another direction, specifically using the Mikrotik API.
There is no clear documentation on how to manage this, so experimentation was necessary, and this instruction was created for future attempts.
To manage multiple devices, a functional WEB server available on the local network is required; it must be responsible for handling commands to Mikrotik.
1. On Netmetal 5, you need to create a couple of scripts to enable and disable interfaces respectively.
system script
add dont-require-permissions=no name=disableiface owner=admin policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=
"/tool fetch http://WEB_SERVER_IP/di.php "
add dont-require-permissions=no name=enableiface owner=admin policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=
"/tool fetch http://WEB_SERVER_IP/en.php "
2. Create 2 scripts on the web. server (of course, PHP should be installed on the system in this case):
debug=true;
if ($API->connect('Managed Mikrotik IP', 'admin login', 'admin password')) {
$API->comm("/interface/ethernet/enable", array(
"numbers"=>"sfp-sfpplus16",));
}
$API->disconnect();
?>
debug=true;
if ($API->connect('Managed Mikrotik IP', 'admin login', 'admin password')) {
$API->comm("/interface/ethernet/disable", array(
"numbers"=>"sfp-sfpplus16",));
}
$API->disconnect();
?>
3. Download routeros_api.class.php from the Mikrotik forum and place it in an accessible directory. server.
Instead of sfp-sfpplus16, specify the name of the interface to be disabled/enabled.
Now, when sending a message to the number in the format
:cmd SECRET_CODE script enableiface
or
:cmd SECRET_CODE script disableiface
NETMETAL will run the corresponding script, which in turn executes the command on the WEB server.
The speed of operation when receiving SMS is a fraction of a second. It works stably.
Additionally, there is functionality for sending SMS to phones using the Zabbix monitoring system and opening a backup internet connection when the optical link fails. This might go beyond the scope of this article, but I will say right away that when sending SMS, their length should fit within the standard size of a single message since Mikrotik does not split them and simply does not send long messages. Furthermore, it is important to filter characters in the messages; otherwise, the SMS will not be sent.
Source: habr.com
