Page 1 of 1

Run "down" scripts only if user does not reconnect within time

Posted: Mon Oct 12, 2020 3:14 pm
by petterg
I have some devices around that I need to access remotely. As they are behind nat (most of them) and non of them have a static public ip, I've solved the remote access by having all of them setup as a vpn client, using a mikrotik hAP as a vpn server. Most of the devices uses pptp. (Those that supports sstp or ovpn uses those.) And those that does not support any vpn at all are placed behind a mikrotik that handles the vpn for them.
As these devices mostly uses mobile internet connection, the connections aren't very stable. They loose connection often, and they reconnect almost as often. The problem here is the word "almost". Each device has its own username at the vpn server.

So, I created a down script to run on the vpn server. This script sends me an email every time one of the devices disconnects..... Suddenly I got like 25-30 mails like that every day! So, to not have to manually check if each of the devices had reconnected, I created UP script emailing me every time the devices had reconnected. That gives me 60 mails each day! And often the connect-mail comes before the disconnect mail. There's so many mails that I don't notice if one of them has not reconnected. If they don't reconnect within seconds, very often they reconnects after a few hours. (I'm guessing mobile signal may be affected by weather.)

Is there any way to make the down script wait for a little while (15 minutes or so) before sending the email. And if the user reconnects, don't send it at all? Similar for the up script - if the "wait" time since disconnect is not up, don't send the mail. I would like to be notified if a user is logged out for more than 15 minutes, and I would like to get another mail when/if the user reconnects after I've received the disconnect mail.

Re: Run "down" scripts only if user does not reconnect within time

Posted: Mon Oct 12, 2020 5:01 pm
by eworm
Does this have to be associated to the vpn disconnect and (re-)connect?

I have a script netwatch-notify that does monitor ip addresses via netwatch. It has a simple state machine to ignore a (configurable) number of failed attempts. (You have to install the base scripts for this to work, see main README.)

If this does not fit your needs it may give an idea how to implement a state machine for vpn monitoring.

Re: Run "down" scripts only if user does not reconnect within time

Posted: Sat Oct 17, 2020 9:39 pm
by petterg
Thanks for your reply.
I thought it had to be associated to the vpn disconnect and (re-)connects because the disconnect may be related to public ip change on the network the devices are connected to. But on second thought, maybe a netwatch on the vpn connections remote (seen from server) ip could work. At least if the device responds to ping (or whatever netwatch uses to monitor). I'll try that out....