Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoring openvpn clients after upgrade to OPNsense 23.7.1 #41

Open
sibelle-labs opened this issue Aug 23, 2023 · 3 comments
Open

ignoring openvpn clients after upgrade to OPNsense 23.7.1 #41

sibelle-labs opened this issue Aug 23, 2023 · 3 comments

Comments

@sibelle-labs
Copy link

Hi !
after upgrading to OPNsense 23.7.1, client connections aren't detected
thanks a lot

@katamadone
Copy link

Are you using openvpn server or instances?

@katamadone
Copy link

if you are using instances this would work. I've put that above the section def checklocal_ipsec(self):
But you would have to check with your instance ID.. - sorry absolutely beginner here.

    def checklocal_openvpninstances(self):

        def search_key_in_json(obj, key):
            if isinstance(obj, dict):
                if key in obj:
                    return True
                for val in obj.values():
                    if search_key_in_json(val, key):
                        return True
            elif isinstance(obj, list):
                for item in obj:
                    if search_key_in_json(item, key):
                        return True
            return False
        
        _ret =[]
        # Run the command and capture its output
        # /usr/local/opnsense/scripts/openvpn/ovpn_status.py
        output = subprocess.run(['python3', '/usr/local/opnsense/scripts/openvpn/ovpn_status.py'], capture_output=True, text=True)

        # Parse the output as JSON
        data = json.loads(output.stdout)
        result = search_key_in_json(data, "client_id")

        if result:
            print("client_id found!")

            # Extracting the client_id from the client list
            client_list = data["server"]["0f7731d9-0222-44f8-be6d-2ae16147650f"]["client_list"]
            client_ids = [entry["client_id"] for entry in client_list]

            # Count the number of entries
            num_entries = len(client_ids)
            # Construct string
            outvar = (f'0 "OVPN Instances Clients" total_connected_clients={num_entries} Total Clients over all Instances')
            #print(outvar)
            _ret.append(outvar)
            return _ret
        else:
            outvar = (f'0 "OVPN Instances Clients" total_connected_clients=0 Total Clients over all Instances')
            #print(outvar)
            _ret.append(outvar)
            return _ret
        #pass

@katamadone
Copy link

katamadone commented Feb 24, 2024

https://github.com/katamadone/checkmk-opnsense-agent/tree/main - ⚠️⚠️⚠️as told: don't take this as "the new" only to see it in the complete python file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants