📜 ⬆️ ⬇️

Managing Internet modules Laurent from RouterOS MikroTik

What are Mikrotik routers (MikroTik), in our time is known to almost everyone who is interested in network technologies a little more than just a user. Thanks to reliable hardware and low cost, these routers are becoming increasingly popular not only in the professional environment of large network administrators, but also in office and home use. An important component of the success of this equipment among professionals and amateurs is the Mikrotik specialized RouterOS (RouterOS, ROS), uniform for all devices, a powerful operating system equipped with a convenient graphical shell WINBOX, which allows to configure the router flexibly and universally. Sometimes the possibilities of RouterOS are not limited to this ...

This article discusses the possibility of using the ROS MikroTik functionality to send commands to the Laurent Internet modules from KernelChip, which accept direct http requests, through the integration of these devices in the network by creating special firmware - ROS script functions.


image

Laurent2 module


The Laurent2 module has on board a fairly rich “snap-in” available on the terminal block pads along the edges of the board. The module includes:


Laurent112


Laurent112 looks more modest, not having the above-mentioned variety of Laurent2 possibilities, but carrying on itself “in compensation” 12 relays capable of switching the standard load of household appliances.
')
To support these modules, the following script functions were written in Mikrotik RouterOs:

FuncLaurent2REL - Laurent2 relay function
FuncLaurent2OUT - function of work with module OUT-lines
FuncLaurent2PWM - setting the power of the PWM signal
FuncLaurent2Status - Laurent2 Status Request
FuncLaurent112REL - Laurent112 module relay function
FuncLaurent112Status - Laurent112 Status Request
FuncPing - a service function for requesting an IP address response to a "ping", used by all functions
FuncMail - an additional function of sending an arbitrary message to the mail

For ease of use, the listed functions together with some service and example scripts of their call are combined into a single Laurent.rsc file, which can be imported into the Router with a terminal command

/import file=Laurent.rsc 

(import time can take from 20-30 seconds to 1 minute depending on the performance of your Mikrotik router model).

If the Laurent script library file is not damaged and the import of scripts into the repository is correct, we will see the message “Script file loaded finished successfully” in the console of the WINBOX utility:

image

At the same time, in the repository of the router, in addition to your existing scripts, the following should appear:

image

They are easily distinguished by the label owner-creator (owner), which will be marked "Laurent".

You can call Laurent functions from any other scripts as follows:
First you need to execute scripts that place the necessary functions in the form of global variables in the environment of the variables of the router's repository. For the Laurent2 module, these are the Func_Laurent2_library , Func_Ping and Func_Mail scripts (an optional, but convenient “mail” function). For Laurent112, these are the Func_Laurent112_REL , Func_Laurent112_Status , Func_Ping and Func_Mail scripts .

These scripts can be run once, when they need these functions. If they are used in a permanent job, it is convenient to implement the launch of their scripts immediately at the start of the router from the RouterOS scheduler ( / system schduler ). Or you can use the launch of a special script Laurent_START.rsc , which does everything necessary to install all the functions of both modules at once. After executing this script from WINBOX or console with the command
 /system script run Laurent_START.rsc 
library functions are located in the environment of repository variables and part of the Jaga melody sounds.

The log of the router displays a message about the successful start of the library:

image

In consequence, you can edit the installation file so that only the functions you need (according to the model of your Laurent board) are put in the environment, or you can call them yourself using the example from the text of the Laurent_START.rsc file

Now, in the environment of variables, we can see our functions, defined in RouterOS as global variables (: global), ready to work:

image

After defining the function, you can call it in your scripts, the router scheduler (for scheduled execution) or any special cases (DHCP-server Alerts, PPP-profile scripts, etc.) by announcing their global names in the calling script.

It should be noted that the functions of working with the relays of both modules, setting the output lines and the power of the PWM signal Laurent2 can only work in the “unprotected” mode of the modules. When the protect mode is enabled in modules, these http commands are not executed with the corresponding error messages (see below). The functions for requesting the status of modules work in both protected and unprotected modes.

Consider the features and functions for the module Laurent2


FuncLaurent2REL - Laurent2 relay on / off / inversion function

The function allows you to: turn on the specified relay, turn off the relay, reset the relay for a specified time.

The syntax of the function is as follows:

 [$FuncLaurent2REL Ladr="IP-address" Lport="http-port" Rele="nRele" Action="m" Time="time s"] 

Where:

Ladr - Laurent2 module IP address in the network in the generally accepted format;

Lport - http-port module. In the current versions of all Laurent modules, only the standard http-port 80 is used, an arbitrary port is not configured. This parameter Lport can not be specified;

Rele - the number of the relay to which the function refers in the range from 1 to 4;

Action - the action performed on the relay. It can take the value (m) equal to 1, which is equivalent to switching on the relay (on) or 0 (off);

Time - the time of action on the relay in seconds in the range allowed by the module firmware [1-255]. If not specified, the action takes place once. If the Time value is specified, the relay is “reset” —the relay status changes to the seconds specified in the Action for Time and returns to the opposite state.

The result of the function can be returned to the string variable Lanswer (this is the value of functions, in contrast to simple commands).

To return the result, you need to use the construction of the definition (: local or: global) or assigning a value (: set) to a previously defined variable, for example:

 :local Lanswer [$FuncLaurent2REL Ladr="IP-address" Lport="http-port" Rele="nRele" Action="m" Time="time s"] 

If the function is successfully executed, “ DONE ” will be returned to Lanswer, or an error message will be returned. If the function is successfully performed, if Action = "1", a router equipped with a beeper emits one short beep. When the relay is turned off or inverse inversion, two consecutive short beeps sound.

The function can return the following error messages:

"> ERROR: rele range mismath" - if an invalid relay number is specified in the Rele variable;
"> ERROR: rele set set mismatch" - in the case of not specified or incorrectly specified Action;
"> ERROR: time mismatch" - in case of an erroneous Time value (not in the range [1-255]);
"> ERROR: device not responded" - in the absence of a response from Laurent to ping;
"> ERROR: command ROS" - in case of an error while executing the RouterOs / tool fetch URL command (if the Lrr is set incorrectly, Ladr is set incorrectly, the specific user Mikrotik is unavailable for the service / tool fetch, etc.);
"> ERROR: device protect" - if the "protected device mode" is set and the command cannot be executed;
"> ERROR: command syntax" - syntax error in the command (* not all variants of errors can be eliminated, script may hang if the syntax is incorrect in the function, for example, if the format is Ladr and Lport is incorrect or not specified)

Examples of using FuncLaurent2REL

Switching on the relay â„–1 of the Laurent2 module with the IP address 192.168.0.101 with the return of the function response to the variable:

 :global FuncLaurent2REL; :local Lanswer [$FuncLaurent2REL Ladr="192.168.0.101" Lport="80" Rele="1" Action="1"]; :if ([:find $Lanswer "DONE"]=0) do={:log warning $Lanswer} 

Of course, instead of any direct values ​​of the function parameters specified in quotation marks, you can use RooterOS variables with arbitrary names:

Invert relay number 4 for 20 seconds without returning the function response:

 :local LaurentIPadr "192.168.10.5" :local LaurentRele 4 :local LTime 20 [$FuncLaurent2REL Ladr=$LaurentIPadr Lport="8021" Rele=$LaurentRele Action="1" Time=$Ltime] 

Laurent2 and Laurent112 functions can be applied to any constructions allowed by the Lua ROS language (loops, nesting, branching, etc ...).

That is, using the cycle, you can, for example, turn on all the relays of the board:

 :for i from=1 to=4 do={[$FuncLaurent2REL Ladr="192.168.0.101" Lport="80" Rele=$i Action="1"];} 

Or, in a similar way, perform group operations on i / o lines.

FuncLaurent2OUT - Laurent2 output line state setting function

The function is absolutely similar to the previous one. It has the same parameters, except for replacing the Rele parameter with the Line parameter, which can take values ​​in the range of 1-12 (remember that Laurent2 has 12 output lines). When specifying Action = "1" on the line, a high logic level is set, with Action = "0" - low. Inverting a line for a specified time also works in the same way as FuncLaurent2REL when setting Time.

An example of a function call with setting the output line No. 12 in the “High level”:

 [$FuncLaurent2OUT Ladr=1"92.168.0.1" Line="12" Action="1"] 

The function FuncLaurent2OUT sends the answer “DONE” in case of a successful completion.

Error messages are similar to FuncLaurent2REL, but output lines are reported:

"> ERROR: line range mismath" - if an invalid line number is specified in the Line variable;
"> ERROR: line set set mismatch" - in the case of not specified or incorrectly specified Action;
"> ERROR: time mismatch" - in case of an erroneous Time value (not in the range [1-255]);
"> ERROR: device not responded" - in the absence of a response from Laurent to ping;
"> ERROR: command ROS" - in case of an error while executing the URL command RouterOs / tool fetch;
"> ERROR: device protect" - if the "protected device mode" is set and the command cannot be executed;
"> ERROR: command syntax" - syntax error in command entry.


FuncLaurent2PWM - PWM Signal Power Adjustment Function

The function sets the signal power at the PWM output, which can be used to adjust the brightness of the light, for example, or the speed of the fan connected to this output.

The syntax of the function is as follows:

 [$FuncLaurent2PWM Ladr="IP-address" Lport="http-port" PW="n(%)"] 

In the PW parameter, the PWM signal power should be specified in percent (without indicating the% sign), respectively, in the range of 0-100.

If the PW parameter is specified incorrectly, the error "> ERROR: PWM range mismath" is issued, other error messages are similar to those for FuncLaurent2REL and FuncLaurent2OUT.

FuncLaurent2Status - Laurent2 module status request function

The function can request the full status of the module in various formats, separately for each of the parameters (all relays, all input lines, all output lines, temperature sensor readings, PWM output power, pulse counters, etc ...), as well as separately from the elements of multielement parameters (specific relay or discrete line). Laurent modules allow you to query the status of the board regardless of whether the protect mode is enabled or disabled.

The recording format of the function is as follows:

 [$FuncLaurent2Status Ladr="IP-address" Lport="http-port" Type="all, xml or name" N="el. number"] 

Wherein:

Ladr and Lport - IP address and http-port (the port can be omitted) of the Laurent2 device in the network;

Type is a required requested parameter that can take values ​​(systime, rele, in, out, adc1, adc2, count1, count2, count2, count4, temp, pwm) according to the technical description of the Laurent2 board. You can also set Type = “all” or Type = “xml”, not specifying Type at all is not allowed;

N is an optional function parameter. It is used only for for multi-element Type (rele, in, out) and for them determines the number of the requested element of the Type parameter status (for rele N = [1-4], for out N = [1-12], for in N = [1 -6]);

If successful (without any errors), the response of the function can be returned in the Lanswer variable, or in the one-dimensional key array of the same name (if the entire module status is queried for Type = "ll" (see below).

When setting Type = “xml”, the function returns the module status without changes in the xml format returned by the board. In RouterOS Mikrotik, this format is hardly convenient, but this feature is preserved.

When Type = "all", the function returns the full module status in the one-dimensional Lanswer key array. The status of individual elements can be extracted from it by the names of the elements. The keys of the elements have names according to the technical description of the module status parameters (systime, rele, in, out, adc1, adc2, count1, count2, count2, count4, temp, pwm), where:

systime - the current system time of the module in seconds, calculated from the moment of power supply;

rele - module relay state as a summary data line. The first character in the line corresponds to relay number 1, the second character to number 2, and so on. 1 in the corresponding position corresponds to the "relay on", 0 - off;

in - states on all 6 input discrete lines in the form of a summary line of data. The first character in the line corresponds to line number 1, the second character is line number 2, and so on. “0” - low logic level is set on the line, “1” - high logic level, respectively;

out - similarly for 12 output lines;

adc1 - indications of measurements of the channel of the ADC-1 module in Volts;

adc2 - readings of measurements of the channel of the ADC-2 module in Volts;

temp - temperature sensor reading in degrees Celsius;

count1 is the value of the pulse counter No. 1, an integer in the range of 0–32766;

count2 - similarly for the other three pulse counters ...;
count3 -
count4 - ...

pwm is the output power of the signal at the PWM output. Can take values ​​from 0 to 100,
in percents

As an example, we will get the full status of the device and output only its individual parameters to the router's log - the temperature value of the temperature sensor (temp) and the status of all relays (rele):

Script example number 1 with the function FuncLaurent2Status
 :global FuncLaurent2Status; ; #    Lanswer   ; :local Lanswer [$FuncLaurent2Status Ladr="192.168.0.101" Type="all"]; #      ; :log info "  Laurent2        -:"; :log info $Lanswer; :log info ""; ; #              : :local termokey "temp"; :local relekey "rele"; :local Tsend ""; :set Tsend ($Lanswer->$termokey); :log info (" : "."$Tsend"); :log info ""; :set Tsend ($Lanswer->$relekey); :log info ("-  : "."$Tsend"); :log info ""; ; #        : :log info ("  :"."\n"); :local rezult; local Saction; :local Reletext; :for i from=1 to 4 do {:set rezult [:pick $Tsend ($i-1) $i]; :if (rezult="0") do={:set Saction "<  >"} else={:set Saction "<  >"} :log info (" â„–"."$i"." "."$Saction"); :set Reletext ("$Reletext"." â„–"."$i"." "."$Saction"."\n")} :log info ""; 


The output of the above script to the log of the router:

image

* Note:

- In RouterOS, the elements of the key arrays are arranged in alphabetical order according to the names of the keys. This does not affect their selective output, you can query the necessary elements of the array by name or in any order.
- The temperature sensor in this case shows -273 ° C (not connected).
- Clearly shows the status of all four built-in relays of the module (on / off).

For multi-element parameters (such as rele, in, or out) that contain the status of all the corresponding elements in their line, respectively, their position number, you can only output a specific element (the status of a specific relay, input line or output line). This is useful when you need to get the status of individual heterogeneous parameters and elements or the status of a group of elements so as not to call the function of requesting the status of a specific element using the N parameter in the loop.

For example, from the already received full status of the module, we derive the state of only the input line No. 6:

 #     ; :local numelem 6; #       ; :local Par ($Lanswer->"in") :local elem [:pick $Par ($numelem-1) $numelem] :log info $elem 

You can also directly request not the full status of the board, but only the state of the desired parameter, for example, all output lines (out):

 :local Lanswer [$FuncLaurent2Status Ladr="192.168.0.101" Type="out"]; :set Lanswer ("   : "."$Lanswer"); :log info $Lanswer; 

Or just one element of the multi-element parameter (let it be relay number 7):

 :local Lanswer [$FuncLaurent2Status Ladr="192.168.0.101" Type="rele" N="7"]; :log info $Lanswer; 

For parameters with one element (such as temp, cont2, adc1, systime, etc.) N is not specified, and if specified, it is ignored.

For Type, for which N is possible (in, out, rele), but not specified, the status of the entire field specified in Type as a string is returned, say “0100011000” (taking into account the number of elements of this Type), where each position corresponds to the value log 1 or log 0.

If a multi-element parameter is requested and N is specified in the function, and it is specified incorrectly (N <1 or N> possible for this Type) - the entire Type parameter is also returned (the error of the incorrect range N is not output).

In case of unsuccessful input / execution, the function may issue the following error messages to the Lanswser variable in the log:

> ERROR: device not responded - in the absence of a response from the Laurent module to ping;
> ERROR: command ROS - in case of an error while executing the URL command RouterOs / tool fetch;
> ERROR: TYPE MISMATCH - in case of a wrong status parameter specified in the request (rele, out, in, all, etc ...)

Below is a sample script code that allows you to work entirely or selectively with the status of a Laurent device. After analyzing the logic of his work, I hope you can write any custom scripts for querying the status of a module.

Script example number 2 of the function FuncLaurent2Status
 :global FuncLaurent2Status; ; :local Ltype "out"; # all –          (rele, out, temp ...); :local Npar ""; # -               (""); :local PR "all"; #-  "all"               № Npar; ; :local Lanswer [$FuncLaurent2Status Ladr="192.168.0.101" Lport="80" Type=$Ltype]; :if ($Lanswer=">ERROR: device protect") do={:log error "  .    "}; :if ([:find $Lanswer "ERROR"]=1) do={:log error $Lanswer;} else={ :local keytype [:toarray "systime, rele, in, out, adc1, adc2, count1, count2, count3, count4, temp, pwm"]; :local typepar {"systime"="1"; "rele"="4"; "in"="6"; "out"="12"; "adc1"="1"; "adc2"="1"; "count1"="1"; "count2"="1"; "count3"="1"; "count4"="1"; "temp"="1"; "pwm"="1"}; :local T; :local row; :local rezult; :if ($Ltype="all") do={ :foreach i in=$keytype do={ :set row ($Lanswer->$i); log info ("$i"." = "."$row");} } else={:set T ($typepar->"$Ltype"); :if ($PR="all") do={:set rezult $Lanswer} else={:set rezult (". . ". "$[:pick $Lanswer ($Npar-1) $Npar]")} :log info ("$Ltype"."  "."$T"."; "."$Ltype "."$Npar".": "."$rezult");}}; :log info ""; 


Functions for the Laurent112 module


The Laurent112 module is intended only for connecting loads, but the number of built-in relays is 12. Accordingly, only two functions were created to support its functionality - the installation of the FuncLaurent112REL relay and the request for the status of the FuncLaurent112Status module.

FuncLaurent112REL - the function of working with the relay module Laurent112 is completely similar to that for Laurent2, described above. The Rele parameter of this function can vary in the range [1-12].

FuncLaurent112Status - Laurent112 status request function is limited to issuing only two status parameters - system time elapsed from power supply to the module (systime) in seconds and the satus of the relay (rele).

Similar to the Laurent2 status request function, the FuncLaurent112Status function can display the full Laurent112 status in the xml module format (when setting Type = "xml"), the full status as a key array placed in Lanswer (with Type = "all") or separately for systime and rele. For Type = “rele”, the task is supported in the request of the parameter N with the indication of the number of the relay whose status is to be requested. If N is not specified, or is set not in the correct range of possible values ​​(from 1 to 12), the function returns a string containing the status of all relays where the relay status is encoded with zeros (0) or units (1) in the corresponding position of each relay position of the relay in the string .

The format for accessing these functions and returning error messages is similar to the corresponding Laurent2 functions (see above).

How to practice using the implemented integration of the Mikrotik router and Laurent Internet modules?


One of the Important moments of the integration results of the Mikrotik router and the Laurent Internet modules mentioned should be considered autonomy - that is, the possibility of its existence between two network devices, none of which are PCs and each of which can work without human intervention (user, administrator). In this case, the router is the main device of any local network and, as a rule, the gateway to the Internet. Considering the capabilities of the RouterOS and the wide hardware spectrum of the RouterBoard, all possible applications of this integration are difficult to imagine, it all depends on the technical tasks and imagination of the applicator.

Most of the autonomous operation of the Laurent board, after appropriate configuration, including the CAT system, can generally be performed independently.

The main applications of Laurent in integration with the Mikrotik router are the following:

  1. - , .
  2. / (, , )
  3. «» .
  4. « » Laurent, /, ) .
  5. / (, …), , SMS.

Next, we consider examples of the implementation of some of them.

1. “Physical protection” of access to an important network resource.

Suppose there is an important device in your local network that you would like to additionally protect against access from outside. As you know, there are a great number of network protections, for example, the port knoking method, the organization of various VPN tunnels, etc ...
They are all good, but almost all have been opened for a long time. Of course, if you are not a banker, then professionals will not engage in hacking your network, and, as a rule, even hack even lightweight defenses for ordinary users.

Nevertheless, there are quite a few hacking facts about remote desktops, file servers, etc ..., which is not very pleasant. What can our integration offer in this sense?
Mainly - the physical limitation of access to a resource in time, and this is one of the most important factors affecting the possibility of hacking the network from the outside.

So, remember that all software methods of network protection (for example, NAT and FIREWALL of the router itself) protect access to any network resource that is constantly running on the network.
With the help of Mikrotik-network relay integration (in this case, the Laurent module), it is easy and convenient, in addition to these protection methods, to make a “physical block” of access to the device we need on the network. How to implement it?

Connect the power of our protected device (for example, a secret file server with your personal archive of data about your company) to one of the Laurent module's relays, for example, to relay 1. We will configure any VPN server, for example, one of the most popular routers, such as one of the most popular ones - pptp server . RouterOc allows you to flexibly configure individual PPP-profiles for server user users (PPP-profile), individually for each VPN client or group of clients. For example, we have a configured PPP-profile for a VPN client named D_Ivanov. In addition to setting the login and password for the client login and a host of other possible network settings for each PPP-profile, RouterOS allows you to set the PPP-scripts options “on Up” and “on Down”, into which you can put the directly executed script code.

Put the following code in these fields:

image

Then, when the D_Ivanov VPN client is connected to the router with its username and password (first stage of protection), the script located in “on Up” will be executed in 5 seconds, which will switch on relay No. 1 using the FuncLaurent2REL function (remember that 1 is powered by our "secret" file server, our second stage of "physical protection"). The server power will be turned on, it will boot up and the client will get access to it “outside” via VPN. As soon as the VPN client breaks the tunnel (terminates the session or the session is terminated due to violations of Internet traffic), the second script located in the “on Down” field will turn off the power of our file server and the server will not be physically accessible. This allows the server (or any other device,whichever you want) is not always in working condition (and be a potentially vulnerable target for password pickers all 24 hours a day), and physically be activated only for the duration of the VPN client access.

This method of double protection is very effective, because “Getting close” to a non-working device, standing already behind the protected router, finding out its model, pinging ports is simply not possible, and it’s very difficult to do it in a short time of its operation (the hacker doesn’t know when you decide to connect via VPN to your router). Of course, in the same fields of PPP profile scripts, you can add a code that sends messages to the mail or mobile phone about entering the VPN client (which will additionally inform, in particular, the administrator about hacking the router's VPN server, but not your secret file server yet! will quickly protect).

2. Turn on / off individual network segments.

Operating with functions of working with relays or output lines (you should not forget that they can also be connected to relays or relay blocks), for example, you can physically turn on / off the subsidiary networks and subnets behind the router. The Laurent2 module has 4 built-in relays and 12 output lines, if you use them all (connect relay or relay blocks to the output lines), you get 16 power outputs. Laurent112 carries 12 pre-built built-in relays. That is, having one of these Laurent modules, it is possible to organize the separate inclusion of 16 or 12, respectively, wifi access points, switches or similar network devices.
Thus, it is possible to regulate the operation of the network of a whole large office or enterprise, turning on / off, rebooting physically “guest” networks, “street” access points, network bridges and other points. And this can be done not by the operator / network administrator, but by the Mikrotik router in automatic mode, including on a schedule or under any conditions.

For example, enable through our function wifi-access point. If it does not turn on, that is, it does not respond to ping, does not connect clients (this is also checked by our script) - turn off its power and turn on another, backup point, etc. ... It will also limit the expenditure of traffic and additionally ensure the safety of certain network segments ( for example, street).

3. Monitoring of Laurent modules and the work of integration with Mikrotik on a schedule

Since the Laurent modules themselves "do not know how" to read time from the servers of the exact time, the work on schedule in them is very limited. Modules can only rely on their own system time, which starts counting from the power supply to the board itself.
Router Mikrotik operates with a “real” daily time date and can perform any actions on RouterOS on an exact schedule by tracking this time with a script or in its own “scheduler” (in WINBOX it is available in the / system scheduler tab). There we can put scripts that use our functions to support Laurent modules, adjusting the operation logic for them (you can “trigger” at the start of the router, at the start with the necessary delay, at a certain time of day once or with regular repetition).

Using these capabilities, you can, in addition to the CAT system of Laurent modules, not only manage any loads and lines, but also read the status of the module or its individual elements in RouterOS Mikrotik. Further, you can make any decisions similar to the conditions of the CAT system, as well as inform the administrator and the users of the router about the events to their email addresses and / or mobile numbers via SMS. In this case, you can use the free features of sending messages from a postal address to a mobile number, for example, a resource sms.ru or similar. You can also send data from Mikrotik to Telegram bots. There are special instructions on how to set it up.

As an example, the following is a script for obtaining full status from the Laurent module with the formation of a convenient visual report and sending this report to the user's email address (do not forget to change the user’s Smail variable to your own).

Laurent2 status request script with email report
 # #   Laurent2 c   E-mail  # ; #     ; :global FuncMail; # -    ; :local Smail "user@mail.ru"; # -       ; ; :global FuncLaurent2Status; # -     Laurent2; :local Sadr "192.168.1.101"; # - IP- ; :local Sport "80"; # - http-,    :local Stype "all"; # -    :local keytype [:toarray "systime, rele, in, out, adc1, adc2, count1, count2, count3, count4, temp, pwm"]; :local Tsend ""; ; #    Laurent; ; :local Lanswer [$FuncLaurent2Status Ladr="192.168.0.101" Lport=$Sport Type=$Stype]; ; #      Mtext ; :local Mtext; :local Stext; :local row; :foreach i in=$keytype do={ :set row ($Lanswer->$i); :set Stext ("$i"." = "."$row"."\n"); :set Mtext ("$Mtext"."$Stext")} ; #   -     Reletext ; :set Tsend ($Lanswer->"rele"); :local rezult; local Saction; :local Reletext; :for i from=1 to 4 do {:set rezult [:pick $Tsend ($i-1) $i]; :if (rezult="0") do={:set Saction "<  >"} else={:set Saction "<  >"} :set Reletext ("$Reletext"." â„–"."$i"." "."$Saction"."\n")} ; #           ; :log info ("STATUS Laurent2 module IP "."$Sadr"."\n"); :log info $Mtext; :log info ""; :log info $Reletext; :set Mtext ("Router "."$[/system identity get name]"." about STATUS Laurent2 module IP "."$Sadr"."\n"."\n"."$Mtext"."\n"."$Reletext"); [$FuncMail Email=$Smail Mailtext=$Mtext] 


When executing the script code of the above example, the mail.ru mail server receives a letter of the following type and content:

image

You can improve and extend the given example script code at your discretion.

The possibilities of implementing the Mikrotik and Laurent ingraction are not limited to the examples described above. It is quite realistic to create almost any solutions, depending on the specific tasks of the user.

Conclusion


It is possible that during the operation of the first version of the library of support scripts for the modules Laurent2 and Laurent112, any errors will be revealed, or the users will have comments or suggestions. The author will be glad if you tell him about it, to improve the library scripts. It is also possible in principle to create support for other KernelChip modules with an RJ45 network interface, such as the JEROME Internet module.

Download a library of scripts for managing Internet modules Laurent2 and Laurent112. A

blog about managing Internet modules from Mikrotik RouterOS.



01.02.2018 Serkov Sergey Vladimirovich
serkov1375@mail.ru

Source: https://habr.com/ru/post/348120/


All Articles