Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Script to Check if OpenVPN is Up or Down

    Scheduled Pinned Locked Moved General pfSense Questions
    2 Posts 2 Posters 1.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      archedraft
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • H
        heper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.