List connected OpenVPN Users like Status / Openvpn from a shell script
I was thinking if there is a way to get the list of connected user to all openvpn servers, like Status / Open page, from a shell script
(my idea is to integrate this in zabbix)
This would be very useful. I am also very interested in this as it will allow my organization to monitor connected remote users.
Gertjan last edited by Gertjan
Status / Open page
You mean the Status / OpenVPN ? Or the OpenVPN widget ?
The page Status / OpenVPN - which is a PHP script file, contains the answer.
You will find on line 54 :
... $clients = openvpn_get_active_clients(); ....
When you check that function, it's here /etc/inc/openvp,n.php, you will see that the GUI (php) is questioning the openvpn process by connecting to it's socket, and sending command a get a list with all the details.
Check for yourself :
Find the socket name of your OpenVPN server instance, it's here /var/etc/openvpn/. There will be a one or more files called serverx.sock where x is the OpenVPN server instance.
Now, presume you have only one instance, so x is "1"
telnet -u /var/etc/openvpn/server1.sock
and type the command
On each line you have the details of a connected user. Pipe this rsult through a "wc -l" command to get the number of lines = number of connected users.
Type quit to exit the connection.
Use the OpenVPN manual to know how to talk to the OpenVPN process.
Up to you to script it all out.
You can use the Status / OpenVPN php file and OpenVPN widget php file as a guide line.