tonyseek / openvpn-status

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

Can't parse files without ports in status.log #16

Open stemenn opened 4 years ago

stemenn commented 4 years ago

I have an openvpn-status.log like that one:

OpenVPN CLIENT LIST Updated,Tue Mar 31 12:14:41 2020 Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since s4-mini,xxx.xxx.xxx.xxx,3747660,15781519,Tue Mar 31 04:33:44 2020 ROUTING TABLE Virtual Address,Common Name,Real Address,Last Ref fd8b:ed45::1:10,s4-mini,xxx.xxx.xxx.xxx,Tue Mar 31 12:12:50 2020 10.8.1.10,s4-mini,xxx.xxx.xxx.xxx,Tue Mar 31 12:17:10 2020 GLOBAL STATS Max bcast/mcast queue length,0 END

So there is no port given in the file. The xxx.xxx.xxx.xxx is most times an ipv4, but it can also be an ipv6.

When I try to parse the file with the parse, I get this error message:

Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/openvpnstatus/descriptors.py", line 31, in __set_\ value = self.input_type(value) File "/usr/local/lib/python3.6/dist-packages/openvpn_status/utils.py", line 29, in parse_peer host, port = peer.rsplit(':', 1) ValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/openvpn_status/parser.py", line 84, in parse return self._parse() File "/usr/local/lib/python3.6/dist-packages/openvpn_status/parser.py", line 98, in _parse for c in self._parse_fields(Client, Status.routing_table.label)}) File "/usr/local/lib/python3.6/dist-packages/openvpn_status/parser.py", line 96, in status.client_list.update({ File "/usr/local/lib/python3.6/dist-packages/openvpn_status/parser.py", line 132, in _parse_fields setattr(instance, name, value) File "/usr/local/lib/python3.6/dist-packages/openvpnstatus/descriptors.py", line 33, in __set_\ raise AssignmentValueError(e) openvpn_status.descriptors.AssignmentValueError: not enough values to unpack (expected 2, got 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/dist-packages/openvpn_status/shortcuts.py", line 18, in parse_status return parser.parse() File "/usr/local/lib/python3.6/dist-packages/openvpn_status/parser.py", line 89, in parse raise ParsingError('expected valid format: %s' % msg) openvpn_status.parser.ParsingError: expected valid format: not enough values to unpack (expected 2, got 1)

It seems that there has to be an port in the file, but my Server ist not writing one into it. I am using Openvpn 2.4.4 on Ubuntu

dset0x commented 4 years ago

I have also been hit by this.

openvpn consciously does not include a port for IPv6 addresses (for me it doesn't show them for IPv4 either when running with udp6). (https://github.com/OpenVPN/openvpn/blob/9cf7b4925a54d93fbea1cadcf3dc0e11f3ce358f/src/openvpn/mroute.c#L506)

I think this is particularly problematic because it prevents one from joining the CLIENT LIST with the ROUTING TABLE models on the IP:port. I suspect openvpn could had been using brackets (a-la curl) but I am not at all versed in IPv6 intricacies to be able to make a call. At any rate, just keep in mind that even if openvpn-status works around this, it will still break client code out there.