HOWTO - use Monit to monitor VPN

How to customize and extend your OpenVPN installation.
Post Reply
pm13
OpenVpn Newbie
Posts: 4
Joined: Sun Jan 02, 2022 7:36 pm

HOWTO - use Monit to monitor VPN

Post by pm13 » Sun Jan 02, 2022 7:47 pm

Hi,

I used OpenVPN at home on an OPNSense firewall & since this is a home LAN the use of VPN is minimal and and have limited users.

My request:
At the time of a VPN user logging in, is there a way to execute a custom shell script on OpenVPN server? If so where do I need to add the script - config file or its location?

The idea is that as soon a VPN user logs in, the script will execute on server and send me a text "User-X has logged-on/logged-off at xx:yy:zz".

Any pointers will be appreciated!

User avatar
TinCanTech
Forum Team
Posts: 10720
Joined: Fri Jun 03, 2016 1:17 pm

Re: Newbie question around custom shell script

Post by TinCanTech » Sun Jan 02, 2022 9:46 pm


pm13
OpenVpn Newbie
Posts: 4
Joined: Sun Jan 02, 2022 7:36 pm

Re: Newbie question around custom shell script

Post by pm13 » Sun Jan 02, 2022 10:24 pm

TinCanTech wrote:
Sun Jan 02, 2022 9:46 pm
Start here: https://community.openvpn.net/openvpn/w ... nPage#lbAS

If you feel brave then you could try this: https://github.com/TinCanTech/easy-tls
Thanks for the pointers, I've become little bold experimenting stuff on OPNSense and just need to follow one rule i.e make a backup of configuration. The experiments mostly end badly but system restoration is a breeze once I am done messing around!

pm13
OpenVpn Newbie
Posts: 4
Joined: Sun Jan 02, 2022 7:36 pm

Re: Newbie question around custom shell script

Post by pm13 » Sun Jan 02, 2022 11:23 pm

TinCanTech wrote:
Sun Jan 02, 2022 9:46 pm
Start here: https://community.openvpn.net/openvpn/w ... nPage#lbAS
If I want to access an environment variable say "ifconfig_remote" from command line of the OS running OpenVPN Server then how do I get the output. I have tried "echo $ifconfig_remote", tried exporting it from a bash script using "--client-connected" option but each time I get "undefined_variable" as output.

User avatar
TinCanTech
Forum Team
Posts: 10720
Joined: Fri Jun 03, 2016 1:17 pm

Re: Newbie question around custom shell script

Post by TinCanTech » Sun Jan 02, 2022 11:53 pm

pm13 wrote:
Sun Jan 02, 2022 11:23 pm
If I want to access an environment variable say "ifconfig_remote" from command line of the OS running OpenVPN Server then how do I get the output. I have tried "echo $ifconfig_remote",
Imagine if you have 50 clients connected to your server, which ifconfig_remote, for which client, do you require ?
pm13 wrote:
Sun Jan 02, 2022 11:23 pm
tried exporting it from a bash script using "--client-connected" option but each time I get "undefined_variable" as output
That is not how your server OS works. And teaching you how your OS works is way beyond the scope of this Forum.

The variables are only available to a script which was started by openvpn.

pm13
OpenVpn Newbie
Posts: 4
Joined: Sun Jan 02, 2022 7:36 pm

Re: Newbie question around custom shell script [Solved]

Post by pm13 » Mon Jan 03, 2022 10:40 pm

I finally got OpenVPN and Monit to work together & the solution actually worked out to be lot simpler than I originally thought - https://forum.opnsense.org/index.php?topic=26221.0

@TinCanTech - thanks for your inputs!

User avatar
TinCanTech
Forum Team
Posts: 10720
Joined: Fri Jun 03, 2016 1:17 pm

Re: HOWTO - use Monit to monitor VPN

Post by TinCanTech » Mon Jan 03, 2022 11:46 pm

Edited for visibility.

No idea of the quality.

Imagine, if you had 5,000 clients and ..

Post Reply