tonyseek / openvpn-status

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

Timestamp format in openvpn-status.log #24

Open apatrick13 opened 2 years ago

apatrick13 commented 2 years ago

In my version of openvpn (xxx), the status log format changes in the timestamp field. Wed Jul 20 16:43:45 2022 -> 2022-07-20 16:43:45 This raises exceptions : openvpn_status.parser.ParsingError: expected valid format: time data '2022-07-20 16:43:45' does not match format '%a %b %d %H:%M:%S %Y'

To cope with this change, make the following changes in the file util.py rename DATETIME_FORMAT_OPENVPN to DATETIME_FORMAT_OPENVPN_F1 (= u'%a %b %d %H:%M:%S %Y') Add DATETIME_FORMAT_OPENVPN_F2 = u'%Y-%m-%d %H:%M:%S'

Change parse_time function : def parse_time(time): """Parses date and time from input string in OpenVPN logging format.""" if isinstance(time, datetime.datetime): return time try: res=datetime.datetime.strptime(time, DATETIME_FORMAT_OPENVPN_F1) return res except Exception as e: pass return datetime.datetime.strptime(time, DATETIME_FORMAT_OPENVPN_F2)

May be more simple solutions, but this one works :+1:

Regards

pandafy commented 1 year ago

It will be beneficial to allow configuring the DATETIME_FORMAT_OPENVPN setting defined in `openvpn_status.utils'. I think we can make it look for a environment variable.

mikysal78 commented 1 year ago

Hi, idem... i have this: OpenVPN parsing error: expected valid format: time data '2023-04-05 21:38:47' does not match format '%a %b %d %H:%M:%S %Y'\"" I have OpenVPN 2.5.1 on server (debian 11) and OpenVPN 2.5.7 on client (openwrt 22.03.3). Howto change this format? thanks.

burbilog commented 1 year ago

I've got the same problem after updating debian 11 to 12. Any chances to have this fixed?.... it seems the issue is year old.