Script to Check if OpenVPN is Up or Down
-
I am wanting to make a script that periodically checks it see if my OpenVPN client is up or down. What command can I issue from an SSH session that will tell me if the VPN client is Up or Down?
-
go into the developer shell once and create a script:
pfSense shell: record checkopenvpn_status Recording of checkopenvpn_status started. pfSense shell: require_once("openvpn.inc"); pfSense shell: $clients = openvpn_get_active_clients(); pfSense shell: print_r(array_values($clients)); pfSense shell: stoprecording Recording stopped.
then either do from devshell
playback checkopenvpn_status
or from normal shell or console:
[2.3-ALPHA][root@pfsense.xxxx]/root: pfSsh.php playback checkopenvpn_status Starting the pfSense developer shell.... Array ( [0] => Array ( [port] => [name] => vpn to xxxx [vpnid] => 1 [mgmt] => client1 [status] => up [connect_time] => Sat Oct 3 1:49:14 2015 [virtual_addr] => xxxx [remote_host] => xxxxx [bytes_recv] => 151003156 [bytes_sent] => 151211004 ) )
adjust however you want offcourse.
relevant functions:
openvpn_get_active_servers(); openvpn_get_active_servers("p2p"); openvpn_get_active_clients();
for more insight: https://github.com/pfsense/pfsense/blob/master/src/usr/local/www/status_openvpn.php