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.3, 3.4 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['foo@example.com']
print(foo_client.bytes_received) # 334.9 kB
print(foo_client.bytes_sent) # 2.0 MB
More detail and API reference are in the document.
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
Built Distribution
File details
Details for the file openvpn-status-0.1.0.tar.gz
.
File metadata
- Download URL: openvpn-status-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f1d7028468a5461967af8b09b94c43379b5072845ff512bc05da44295f4b2ad |
|
MD5 | 1e074c0ff31ee190a7c4a1430e83c3a7 |
|
BLAKE2b-256 | ed6f05dbb72fe0ca0a63da89825f35cbcacf6d8bc14ef27bcc2ca94a865694f2 |
File details
Details for the file openvpn_status-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: openvpn_status-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8bdee1253fafd64ade87e9f550f4e8eb97443d2f1cac3d5f924f572be4808bb |
|
MD5 | 9b1234b3fdb7beffe97e6d61f981ff39 |
|
BLAKE2b-256 | 03dcbd7bc8eb4bf1cb2eec39cb983fc5569f3366b0c05561c4c9c7ae051269ab |