Skip to content

Timestamp format in openvpn-status.log #24

@apatrick13

Description

@apatrick13

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 👍

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions