I have an ovpn server with about a hundred connections, some of these have a profile to send me sms+email if they go down. The problem is that sometimes is just reconnects, so the downtime is like 5 seconds and it is spamming my phone + email with alerts.
I would like to add some delay like 30 secs to my script and then check the ovpn connection state, but it is automatically triggered by the "On Up" script set in the ovpn profile - so I don't know what connection should I check? How do I get what connection triggered the "On Up" script?
Or if there is other good way to achieve this, except reading the log file?
The script initializes a global empty array $ovpnUsersOffline at the beginning:
:global ovpnUsersOffline [:toarray ""];
The script then has an endless loop that:
Sleeps (:delay) for 30s.
Initializes the content of the email in a string variable.
Runs a :foreach k,v in=$ovpnUsersOffline do=... loop over the global array from above. If $v is equal to 1 append a line to the email content, saying that "User $k is offline." or something similar.
Resets the global array to empty:
:set ovpnUsersOffline [:toarray ""];
Sends the email, that sumarized all the currently offline users.
In the on-down event of the PPP profile, set the corresponding keyed element of the array to 1:
I like the idea, I did some tests with it, but it started to get quite large, with increasing number of variables etc, since I have other conditions - like to send just one email, send it when it gets back online, send when it just jumps online for lost/stolen devices etc.
Anyway, I lowered the number of monitored connections, so I created a profile for every one of them, waiting for 60 secs and running, so I'm good.
But if anyone would ever find out how to address the interface that triggered the On Up / On Down in the Up/Down script itself, I'd still love to know
Maybe you should split logic among OVPN script and DHCP one?
If you want to monitor on/off/stealing/reconnecting/temporary disconnect etc. ... that would expand your sceript to the enormous size. You should consider other solution IMHO.