Community discussions

MikroTik App
 
alexathinaios
just joined
Topic Author
Posts: 4
Joined: Sat Jun 14, 2014 2:46 am
Contact:

Automated Script for Checking PPPoE Client Status

Wed Jun 29, 2016 1:52 pm

Hello Everyone,
I'm using Mikrotik for three years and working for WISP two years now. We have several ADSLs connections(pppoe clients) running and sharing internet threw pptp into the nodes where the clients are connected. The problem with these ADSLs is that during the day (not every day) we have disconnections and the customers still trying to access to the internet from those lines because the pptp is still connected to the gateway router (where the ADSL is). So for that I had to make a script by checking the pppoe status and if the pppoe dropped the script will close the pptp server and when the pppoe is back again will enable the pptp server so the nodes can connect to the gateways. The script i made is separeted in 4 different scripts to avoid problems and confusing of the script.

Part 1: (name of the script  DSL CHECK STATUS START   )
/interface pppoe-client monitor ADSL once do={
:if ($status= "connected") do={:log warning "DSL is ok"; :delay 60s; /system script run "DSL CHECK STATUS START";}
 else={:log warning "Dsl Is Down!!!, Disabling PPTP Server And Go To Next Step"; /interface pptp-server server set enabled=no; /system script run "DSL CHECK STATUS NEXT"}
}

Part 2: (name of the script   DSL CHECK STATUS NEXT   )
/interface pppoe-client monitor ADSL once do={
:if ($status= "connected") do={:log warning "Dsl is Now Up!!! ,running next script";  :delay 20s; /system script run "PPOE";}
 else={:log warning "Nothing Yet, Re Check In 30secs"; :delay 30s; /system script run "DSL CHECK STATUS NEXT"; }
}

Part 3:  (name of the script   PPOE      )
/system script run "pptp server up"; log warning "Pptp Server Just Enabled,script is running, wait 5secs";
:delay 5s;
/interface pppoe-client disable ADSL; log warning "Pppoe Disabled, wait 5secs";
:delay 5s;
/interface pppoe-client enable ADSL; log warning "Pppoe Enabled, wait 2secs";
:delay 2s;
/interface pppoe-client disable ADSL; log warning "Pppoe Disabled, wait 2secs";
:delay 2s
/interface pppoe-client enable ADSL; log warning "Pppoe Enabled, wait 25secs and start from beginning";
:delay 25s;
/system script run "DSL CHECK STATUS START";
I'm doing that twice disable and enable because when i'm enabling the pptp server the default route on routing table goes unreachable (propably mikrotik's bug) and for that i have to disable and enable the pppoe and then sometimes I found that the pppoe might be enable but still it doesn't make the call to connect so i have to disable - enable twice.


Part 4:  (Name of the script   pptp server up   )
/interface pptp-server server set enabled=yes;
*The script you will find it in jobs tab but maximum jobs are somewhere 1000+ times so when the jobs reached the maximum number will be stoped by it self. I found the total time of running and is 15h&16m. So for that because i want the script running all the time even aftre a reboot of the router I made also two scheduler entries.
Schedule 1: name: ADSL Check
Start Time: startup
Interval: 00:00:00
:delay 10s;

/system script run "DSL CHECK STATUS START"
the 10s delay is for waiting to load properly the router after the reboot because sometimes I noticed that after the reboot the script didn't run properly.

Schedule 2: name ADSL Check cycle
Start Time: startup
Interval: 15:18:00

/system script run "DSL CHECK STATUS START"
The interval time is 2 minutes more so i can leave the router free of scripting for 2 minutes for any memory problems but I haven't noticed any problems 3 months now.

*The script is working on version 6.35.2 and on previous versions.

I hope i will help some people out there as i found solutions in some problems I had before.
Thank you very much Mikrotik.
Greetings from Greece.
Alex
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

Re: Automated Script for Checking PPPoE Client Status

Wed Jun 29, 2016 4:13 pm

At a glace it would seem like the first script (DSL CHECK STATUS START) goes into an endless loop until it detects a failure, and that is without haven't fully looked at how the flow goes if it does detect a failure.
Looking at the "System -> Scripts -> Jobs tab" menu must be scary.

Why are you doing all this simply to check if a connection is down? Wouldn't it be a lot easier to just use a netwatch or a scheduled ping script?
 
alexathinaios
just joined
Topic Author
Posts: 4
Joined: Sat Jun 14, 2014 2:46 am
Contact:

Re: Automated Script for Checking PPPoE Client Status

Wed Jun 29, 2016 5:09 pm

We had the netwatch before but it had limit at 1000ms which sometimes we had that latency but still the adsl was online. After that we faced with the unreachable route, which the only solution for that is disable and enable again the pppoe client. The route goes unreachable after we enable the pptp server. On our network all the adsl are connected with pptp to our nodes so if a adsl fails we need to stop the pptp until it will come back thats why i made all this. The ping script is a good idea only if there werent those problems.
I tested many many times and it does work smooth so far..

Στάλθηκε από το GT-I9300 μου χρησιμοποιώντας Tapatalk