Community discussions

MikroTik App
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Script Error

Thu Sep 16, 2021 11:07 am

Hi, we have a simple script that checks for internet connectivity via the LTE interface but i seem to have an error when it runs when the LTE interface isn't working.

I'm not sure if its something simple like i have the interface name wrong, would someone mind taking a look and provide some feedback please.

Script
:if ([/ping 8.8.8.8 count=10] = 0) do={
:log error "** LTE DOWN **";
/interface disable lte
/delay 5s	
/interface enable lte
} else={
:log info "** LTE ONLINE **";
}
List of interfaces
Flags: D - dynamic, X - disabled, R - running, S - slave 
 #     NAME                                TYPE       ACTUAL-MTU L2MTU  MAX-L2MTU
 0  R  ether1                              ether            1500  1596       2026
 1     ether2                              ether            1500  1596       2026
 2     ether3                              ether            1500  1596       2026
 3  R  lte1                                lte              1480
Many Thanks
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Script Error

Thu Sep 16, 2021 1:43 pm

You try to disable/enable interface lte, but name of your interface is lte1
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Thu Sep 16, 2021 2:03 pm

Thank you@jotne

I did wonder if that was the case but when i jump into the termninal and type
/interface lte1
i get an error, where as if i type
/interface lte
it works?

Is it something to do with Name V's Type ?

Thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Thu Sep 16, 2021 7:45 pm

Is not a "type", is a submenu / section, like on /interface wireless you find the dedicated section for... wireless
/interface show all type of interfaces, usually the menu is less rich than the dedicated section for each type of interfaces.

This script work on both way: disable and enable command are present on both generic /interface and dedicated /interface lte section.
But the interface name is lte1

Revised script:
/interface lte
:if ([:ping 8.8.8.8 count=10] = 0) do={
    :log warning "** LTE DOWN **"
     disable lte1
     :delay 5s
     enable lte1
} else={
    :log info "** LTE ONLINE **"
}
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Thu Sep 16, 2021 8:20 pm

Thanks @rextended

Turns out the problem we had was due to a previous reboot and the LTE interface didn't load for some reason.

I was thinking of adding something like this to the script
:if ([/interface list print count-only where name=LTE] = 0) do={
:log error "** LTE INTERFACE OFFLINE **";
/system reboot
}
but would need an additional else statement. Is that possible or am i better off have a dedicated alternative script scheduled to run first.

Thanks


Thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Thu Sep 16, 2021 9:47 pm

Missing lte interface cause previous script to fail... give me 10 minutes...

this is wrong:
/interface list print count-only where name=LTE

at least
/interface print count-only where type="lte" (or /interface print count-only where name="lte1")
or
/interface lte print count-only where name="lte1" (or simply /interface lte print count-only)

but really must be do on this way:
[:len [/interface lte find]]

because the print command, with some exception, is related mostly to put text on terminal than manage variables.
Last edited by rextended on Thu Sep 16, 2021 10:03 pm, edited 4 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Thu Sep 16, 2021 9:55 pm

Remember on /system logging to save the warning/error logs on DISK file, or you lost that info on reboot (you can not send e-mail or sms if lte1 not work)

ltestatus added for warn only one time when status change
:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] = 0) do={
        :if ($ltestatus = "online") do={:log warning "*** LTE NOT WORK ***"}
        :set ltestatus "offline"
         disable [find]
         :delay 5s
         enable [find]
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}

You can put it on scheduler directly without creat separate script,
set the scheduler to start the action on "startup" and run every 4 minutes and 30 seconds (because is already present 30s delay inside script),
and add this before any line of script,
for give the time to the system to finish booting:
:delay 30s
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Fri Sep 17, 2021 11:55 am

WOW... thank you @rextended, thats very helpfull of you.

I will get this loaded onto a RB this morning and test everything, it will be a great, robust script to check the LTE interface and keep it online hopefully.

Grazie mille
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Fri Sep 17, 2021 12:04 pm

Di niente :lol:
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Wed Oct 06, 2021 6:04 pm

@rextended

Sorry to resurrect this thread, i wanted to ask a question if i may.

Is there a way to alter this script so if the ping response fails three times it will reboot the router rather than disable / enable the LTE interface.

I have seen the below issue a couple of times and i believe the LTE interface is crashing due to a number of "not registered" errors but i am not sure if that means the LTE interface doesn’t exist which the script does check for. The above example happened following an automated router reboot which happens everyday at 23:00

RB.png
Thanks
You do not have the required permissions to view the files attached to this post.
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Script Error

Wed Oct 06, 2021 6:17 pm

I would rather reboot the "modem" instead of the router, that way you still keep the logs, etc

below amended script from @rextended:
:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] = 0) do={
        :if ($ltestatus = "online") do={:log warning "*** LTE NOT WORK ***"}
        :set ltestatus "offline"
         # disable [find]
         # :delay 5s
         # enable [find]
         /system routerboard usb power-reset duration=10
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Wed Oct 06, 2021 6:46 pm

Is there a way to alter this script so if the ping response fails three times it will reboot the router rather than disable / enable the LTE interface.

Yes...
:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] < 8) do={
        :log error "*** LTE NOT WORK CORRECTLY - REBOOT ***"
        /system reboot
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Wed Oct 06, 2021 7:18 pm

Once again @rextended, thank you very much. I presume the "< 8" command is the count ?

@CZFan, thanks for the help, all critical logs are written to disk so the router reboot is teh bets option for me.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Wed Oct 06, 2021 7:23 pm

at least 3 fail?
10 - 3 = 7 (at least 7 good)
< 8 (worst than 8, because 8 are good, only 2 fail)
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Wed Oct 06, 2021 7:34 pm

Arh, Ok that makes more sense. Thanks for all your help on this
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Script Error

Wed Oct 06, 2021 7:36 pm

@pigsfoot, I think what you looking for is:
[:ping 8.8.8.8 count=3] = 0
This will send 3 ping requests, if all 3 fails, then do what is required...

If not, you will have to elaborate on your requirement
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Wed Oct 06, 2021 7:42 pm

Too much strict, someting can fill the connection and reboot the device without reason...
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Script Error

Wed Oct 06, 2021 7:49 pm

Too much strict, someting can fill the connection and reboot the device without reason...
Agree, but it is what he asked.

I would like to use this script, would you mind changing it to monitor 2 devices on innerweb, i.e. ping both 8.8.8.8 and 1.1.1.1 and if both fails, then take action?
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Script Error

Wed Oct 06, 2021 8:50 pm

...
I would like to use this script, would you mind changing it to monitor 2 devices on innerweb, i.e. ping both 8.8.8.8 and 1.1.1.1 and if both fails, then take action?

Nevermind, think I have it working...
:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if (([:ping 8.8.8.8 count=5] = 0) && ([ping 1.1.1.1 count=5] = 0)) do={
            :log warning "*** LTE Connection Down, Reboot Modem... ***"
            /system routerboard usb power-reset duration=10
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** No LTE Interfaces... ***"
   /system reboot
}
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1025
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: Script Error

Wed Oct 06, 2021 11:32 pm

Just some suggestions

We abandoned central dns addresses like 8.8.8.8 for all of our customer LTE-links because we sometimes encountered global routing errors while the local link still worked. We now only use addresses within ISP's own networks to probe for possible link errors. There is also a delay of one minute before resetting the LTE-link since it showed that many link errors are automatically restored within that time period.

Normally we don't reboot the device as just flipping the interface works equally well.

We also send error message regarding link failure etc via SMS and together with external monitoring on the LTE-device we can correlate any downtime to investigate whether the problem originates from the operator network or the local installation.

As a last resort when there are no available ip-connections we can check status or reboot the device by acting on incoming SMS commands. This has proven to be very useful and saved many hours of unnecessary travel as many LTE links are installed in remote branch offices far out in the countryside and on some remote islands.
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Mon Oct 11, 2021 8:04 pm

HI all ( @rextended ), I’m trying to enhance the script as we have had a couple of additional issues which means i also need to shut down an attached RPI via SSH. The SSH commands work fine as we use them else where, its just something is missing with this script that i cant find.

In essence if the LTE interface can not ping google BUT it can ping the RPI i need to shut the RPI down and then reboot the router, if the LTE can not ping Google AND can not ping the RPI then a system reboot is fine. The reason i need to check if the RPI is online or not is because we have found that if we just have the RPI shutdown script run and the RPi is unavailable the scripts stop working and i don’t want to just kill power to the USB port powering the RPI without shutting it down first due to corrupt SD cards.

:global ltestatus
:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}
/interface lte
:if ([:len [find]] > 0) do={
    :if (([:ping 8.8.8.8 count=10] < 8) && ([ping 192.168.88.10 count=5] = 5)) do={
        :log error "*** LTE CONNECTION ISSUE & RPI ONLINE ***"    
        /system ssh-exec address=192.168.88.10 user=root command="shutdown now";
        :delay 15s
        :log info "RPI Shutdown OK, rebooting system"
        /system reboot
    } else={
        :if (([:ping 8.8.8.8 count=10] < 8) && ([ping 192.168.88.10 count=5] = 0)) do={
        :log error "*** LTE CONNECTION ISSUE & RPI OFFLINE  ***"
        /system reboot
    } 
    } else={
        :if ($ltestatus = "offline") do={:log info "*** LTE ONLINE ***"}
        :set ltestatus "online"
    }
} else={
   :log error "*** LTE DISAPPEARED ***"
   /system reboot
}
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Tue Oct 12, 2021 3:30 pm

Fixed, i think i had a coupe of curley bracket issues :-)
:global ltestatus

:if ([:typeof $ltestatus] = "nothing") do={:set ltestatus "offline"}

/interface lte

:if ([:len [find]] > 0) do={
    :if ([:ping 8.8.8.8 count=10] < 8) do={
        :log error "* LTE OFFLINE, Need Reboot - Check RPI *"
        :if ([:ping 192.168.88.10 count=5] >= 5) do={    
            /system ssh-exec address=192.168.88.10 user=root command="shutdown now";
            :delay 15s
            :log info "RPI was ONLINE, Shutdown OK, rebooting system"
            /system reboot
        } else={
            :log info "* RPI OFFLINE, rebooting system  *"
            /system reboot
        } 
    } else={
        :if ($ltestatus = "offline") do={:log info "* LTE ONLINE *"}
        :set ltestatus "online"
    }
} else={
   :log error "* LTE DISAPPEARED *"
   /system reboot
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Script Error

Tue Oct 12, 2021 8:17 pm

count=5] >= 5
ehm...
 
Pigsfoot
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 84
Joined: Sat Oct 25, 2014 1:16 am

Re: Script Error

Tue Oct 12, 2021 10:51 pm

DOH.. should be >=1, so if the RPI replies even once to the ping request the SSH command activates and shuts the RPI down before rebooting so as to not curropt the SD card.Thanks for pointing that out

Who is online

Users browsing this forum: No registered users and 18 guests