snovvcrash / usbrip

Tracking history of USB events on GNU/Linux
https://habr.com/ru/post/352254/
GNU General Public License v3.0
1.15k stars 109 forks source link

ValueError: time data does not match format #10

Closed krosseyed closed 5 years ago

krosseyed commented 5 years ago

I am getting an error when running usbrip after changing my rsyslog.conf to use high precision time.

I am using v2.1.4-1

Below is an output of the error. Notice that my timestamp seems to be correct

[*] Started at 2019-08-13 22:46:18
[22:46:18] [INFO] Searching for log files: "/var/log/syslog*" or "/var/log/messages*"
[22:46:18] [INFO] Reading "/var/log/syslog"
Traceback (most recent call last):
  File "./usbrip", line 11, in <module>
    sys.exit(main())
  File "/home/deepblue/.local/lib/python3.6/site-packages/usbrip/__main__.py", line 87, in main
    ueh = USBEvents(args.file)
  File "/home/deepblue/.local/lib/python3.6/site-packages/usbrip/lib/core/usbevents.py", line 86, in __new__
    filtered_history = _get_filtered_history()
  File "/home/deepblue/.local/lib/python3.6/site-packages/usbrip/lib/core/usbevents.py", line 273, in _get_filtered_history
    filtered_history.extend(_read_log_file(syslog))
  File "/home/deepblue/.local/lib/python3.6/site-packages/usbrip/lib/core/usbevents.py", line 317, in _read_log_file
    date = datetime.strptime(line[:32], '%Y-%m-%dT%H:%M:%S.%f%z')  # ex. 2019-08-09T06:15:49.655261-04:00
  File "/usr/lib/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data '2019-08-13T22:33:30.052019-05:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%z'
[*] Shutted down at 2019-08-13 22:46:18
[*] Time taken: 0:00:00.111860

Here is my kernel

# uname -a                                                                                                                                                     
Linux somehost 4.15.0-58-generic #64-Ubuntu SMP Tue Aug 6 11:13:26 UTC 2019 ppc64le ppc64le ppc64le GNU/Linux

Sample output of /var/log/system

2019-08-13T22:41:11.026107-05:00 deepblue systemd[1]: Started System Logging Service.
2019-08-13T22:41:11.026174-05:00 deepblue rsyslogd: rsyslogd's groupid changed to 106
2019-08-13T22:41:11.026238-05:00 deepblue rsyslogd: rsyslogd's userid changed to 102
2019-08-13T22:41:11.026302-05:00 deepblue rsyslogd:  [origin software="rsyslogd" swVersion="8.32.0" x-pid="37251" x-info="http://www.rsyslog.com"] start
2019-08-13T22:45:39.632022-05:00 deepblue kernel: [12438.996079] usb 2-1: USB disconnect, device number 3
snovvcrash commented 5 years ago

The latest commit containing the fix was not on the PyPI. Upgrade to the 2.1.4-2 and give it a try

krosseyed commented 5 years ago

Works great, thanks snovvcrash!