tonyseek / openvpn-status

Parse OpenVPN status logs in Python
https://openvpn-status.readthedocs.io
MIT License
83 stars 31 forks source link

client-specific configuration files (ccd) #4

Closed gunawanw9 closed 6 years ago

gunawanw9 commented 6 years ago

This is my current openvpn-status.log for the client with ccd

OpenVPN CLIENT LIST
Updated,Sun Oct  8 17:32:16 2017
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
camdev0,36.79.164.81:41718,11958,11952,Sun Oct  8 17:27:27 2017
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
192.168.192.6,camdev0,36.79.164.81:41718,Sun Oct  8 17:31:25 2017
172.24.1.0/24,camdev0,36.79.164.81:41718,Sun Oct  8 17:27:28 2017
GLOBAL STATS
Max bcast/mcast queue length,0
END'

And simple script to try was

#/usr/bin/env python3

from openvpn_status import parse_status

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

print(status.updated_at)

foo_client = status.client_list['camdev0']
print(foo_client.bytes_received)
print(foo_client.bytes_sent)

And the result

Traceback (most recent call last):
  File "openvpn-status.py", line 6, in <module>
    status = parse_status(logfile.read())
  File "/usr/local/lib/python3.5/dist-packages/openvpn_status/shortcuts.py", line 18, in parse_status
    return parser.parse()
  File "/usr/local/lib/python3.5/dist-packages/openvpn_status/parser.py", line 92, in parse
    for r in self._parse_fields(Routing, Status.global_stats.label)})
  File "/usr/local/lib/python3.5/dist-packages/openvpn_status/parser.py", line 90, in <dictcomp>
    status.routing_table.update({
  File "/usr/local/lib/python3.5/dist-packages/openvpn_status/parser.py", line 123, in _parse_fields
    setattr(instance, name, value)
  File "/usr/local/lib/python3.5/dist-packages/openvpn_status/descriptors.py", line 29, in __set__
    value = self.input_type(value)
  File "/usr/lib/python3.5/ipaddress.py", line 54, in ip_address
    address)
ValueError: '172.24.1.0/24' does not appear to be an IPv4 or IPv6 address

i guess the fault was on CIDR format recognized as Host Address. This 172.24.1.0/24 is the network behind 192.168.192.6 address (client). hmm... let's see...

tonyseek commented 6 years ago

Thanks for your feedback. I will fix it in next release.