Does RouterOS scripting language have an equivalent of a GoSub command? I could not find one in the Wiki.
Here is what I am trying to accomplish. I have a script that does a ping test to a few addresses on my LAN, and sends an E-Mail to me if a device does not respond. I want to expand that to currently 34 devices. Rather than having to write (or copy, paste and modify) the same ping test routine 34 times, I would rather do something like this:
Load four variables that are used with error E-Mails
Load three variables for device #1
Execute a subroutine that performs the test, then return
Load three variables for device #2
Execute a subroutine that performs the test, then return
etc
Stop processing
At the end is the subroutine.
Here are a couple code segments of what I am currently doing (for just a few devices):
Code: Select all
# Set up variables for average return times
:local AvgRtt;
# Set up variables for error E-Mails
:local Sub1 "Ping failure to"
:local Sub2 "from Router #1."
:local Bo1 "Test to IP: "
:local Bo2 "Average ping RTT: "
And the variables for two devices:
Code: Select all
# Set the monitored IP address for test 01
:local IP01 192.168.106.51;
:local IP01n Wyze_camera-01_TBD;
:local Cam01Enable 1;
# Same for test 02
:local IP02 192.168.106.52;
:local IP02n Wyze_camera-02_Matrix-panels;
:local Cam02Enable 1;
And the test and E-Mail if needed:
Code: Select all
# Start the test for Camera 01
:if ($Cam01Enable = 1) do={
/tool flood-ping $IP01 count=10 do={
:if ($sent = 10) do={
:set AvgRtt $"avg-rtt"
}}
:log info "Average RTT to $IP01 is: $AvgRtt mSec"
:if ($AvgRtt = 0) do={
:log err "Wyze Ping failure to Camera 01 E-Mail is being sent";
# Send mail
/tool e-mail send to jim@redacted subject=("$Sub1 $IP01n $Sub2") body=("$Bo1 $IP01 $IP01n \n $Bo2 $AvgRtt mSec.")
}}