Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tonyseek/openvpn-status
Parse OpenVPN status logs in Python
https://github.com/tonyseek/openvpn-status
openvpn openvpn-monitor python
Last synced: 2 days ago
JSON representation
Parse OpenVPN status logs in Python
- Host: GitHub
- URL: https://github.com/tonyseek/openvpn-status
- Owner: tonyseek
- License: mit
- Created: 2015-06-19T18:37:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-19T13:08:27.000Z (over 1 year ago)
- Last Synced: 2024-12-30T20:11:31.474Z (9 days ago)
- Topics: openvpn, openvpn-monitor, python
- Language: Python
- Homepage: https://openvpn-status.readthedocs.io
- Size: 90.8 KB
- Stars: 83
- Watchers: 6
- Forks: 31
- Open Issues: 12
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
- Authors: AUTHORS.rst
Awesome Lists containing this project
README
|Build Status| |Coverage Status| |PyPI Version| |Wheel Status|
OpenVPN Status
==============.. summary-begin
**openvpn-status** is a Python library. It parses OpenVPN status log and turns
it into Python data structure for you... summary-end
It is compatible with Python `2.7`, `3.6` to `3.10`, and PyPy.
Installation
------------.. code-block:: bash
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.logOnce 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
[email protected],10.10.10.10:49502,334948,1973012,Thu Jun 18 04:23:03 2015
[email protected],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,[email protected],10.10.10.10:49502,Thu Jun 18 08:12:09 2015
192.168.255.126,[email protected],10.10.10.10:64169,Thu Jun 18 08:11:55 2015
GLOBAL STATS
Max bcast/mcast queue length,0
ENDNow we could parse log file with this library:
.. code-block:: python
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) # [email protected]
print(foo_client.bytes_received) # 334.9 kB
print(foo_client.bytes_sent) # 2.0 MB
print(int(foo_client.bytes_sent)) # 2097152More 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.
.. _`API reference`: https://openvpn-status.readthedocs.io/en/latest/api.html
.. _GitHub: https://github.com/tonyseek/openvpn-status/issues.. |Build Status| image:: https://img.shields.io/travis/tonyseek/openvpn-status.svg
:target: https://travis-ci.org/tonyseek/openvpn-status
:alt: Build Status
.. |Coverage Status| image:: https://img.shields.io/coveralls/tonyseek/openvpn-status.svg
:target: https://coveralls.io/r/tonyseek/openvpn-status
:alt: Coverage Status
.. |Wheel Status| image:: https://img.shields.io/pypi/wheel/openvpn-status.svg
:target: https://warehouse.python.org/project/openvpn-status
:alt: Wheel Status
.. |PyPI Version| image:: https://img.shields.io/pypi/v/openvpn-status.svg
:target: https://pypi.python.org/pypi/openvpn-status
:alt: PyPI Version