Skip to main content

Parse OpenVPN status logs in Python

Project description

openvpn-status is a Python library. It parses OpenVPN status log and turns it into Python data structure for you.

It is compatible with CPython 2.7, 3.4, 3.5, 3.6, 3.7 and PyPy.

Installation

pip install openvpn-status

Don’t forget to put it in setup.py / requirements.txt.

Getting Started

You could configure your OpenVPN server to log for client status. In usual it could be achieved by adding status /path/to/openvpn-status.log line to /etc/openvpn/openvpn.conf. For example:

proto udp
port 1194
dev tun0
status /var/run/openvpn-status.log

Once OpenVPN server running, the log file will be created and written. It looks like:

OpenVPN CLIENT LIST
Updated,Thu Jun 18 08:12:15 2015
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
foo@example.com,10.10.10.10:49502,334948,1973012,Thu Jun 18 04:23:03 2015
bar@example.com,10.10.10.10:64169,1817262,28981224,Thu Jun 18 04:08:39 2015
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
192.168.255.134,foo@example.com,10.10.10.10:49502,Thu Jun 18 08:12:09 2015
192.168.255.126,bar@example.com,10.10.10.10:64169,Thu Jun 18 08:11:55 2015
GLOBAL STATS
Max bcast/mcast queue length,0
END

Now we could parse log file with this library:

from openvpn_status import parse_status

with open('/var/run/openvpn-status.log') as logfile:
    status = parse_status(logfile.read())

print(status.updated_at)  # datetime.datetime(2015, 6, 18, 8, 12, 15)

foo_client = status.client_list['169.254.0.1']
print(foo_client.common_name)  # foo@example.com
print(foo_client.bytes_received)  # 334.9 kB
print(foo_client.bytes_sent)  # 2.0 MB
print(int(foo_client.bytes_sent))  # 2097152

More details are in the API reference.

Contributing

If you want to report bugs or request features, please feel free to open issues on GitHub.

Of course, pull requests are always welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openvpn-status-0.2.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

openvpn_status-0.2.1-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file openvpn-status-0.2.1.tar.gz.

File metadata

  • Download URL: openvpn-status-0.2.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for openvpn-status-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4ac6a6ec6069c7d6fb3e9d73ab109f9390a0d0ecb2dc940553aa6d751fd7fb85
MD5 5e92efa306e2510b4eed4626243e7a6d
BLAKE2b-256 a97c2725db70532568d1d701665e64f6047e8870b94ee5f7c8704e20071ae7de

See more details on using hashes here.

File details

Details for the file openvpn_status-0.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: openvpn_status-0.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

File hashes

Hashes for openvpn_status-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 49d113759cfefd72e404021c95aed72501edff54a034674012b0a4c84aabea29
MD5 230bb1fcee7bb59e87b4c5d329a963eb
BLAKE2b-256 740dc42e22bd12f8f37384213bb986b546a560e96a76cba35528e759c0fe8882

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page