Untitled

 avatar
unknown
plain_text
a year ago
2.2 kB
1
Indexable
# Calculate the purging date (retention_period days before the bookmark timestamp)
        bookmark_date = datetime.datetime.strptime(bookmark_timestamp, "%Y-%m-%dT%H:%M:%S+00:00").date()
        print("Bookmark Date:", bookmark_date)
        logging.info("Bookmark Date %s ", bookmark_date)

        current_date = datetime.datetime.now().date()
        print("Current Date:", current_date)
        logging.info("Current Date %s ", current_date)

        purging_date = current_date - datetime.timedelta(days=retention_period)
        print("Purging Date:", purging_date)
        logging.info("Purging Date : %s ", purging_date)

        if purging_date <= bookmark_date:
            print("Performing Purging..")
            ## Function call to perform purging
            perform_purging(syslog_file, purging_date,bookmark_record)
        else:
            print("Purging date greater than Bookmark Date, no purging will be done")
            logging.info("Purging date greater than Bookmark Date, no purging will be done")



We moved this code to PROD , we faced this error-

VM: 2756
VM_IP: 10.252.25.124
Bookmark record  10.252.25.124_bookmark_log
Syslog File Location: /syslog/fradmdap-10.252.25.124.log
Retention Period: 0
Bookmark Index: 391
Bookmark Line: 2023-09-20T15:45:15+02:00 fradmdap SAPEDD_10[4779]: EMF Background Processing: Logon of Jobstep User Failed
Bookmark Timestamp: 2023-09-20T15:45:15+02:00
Traceback (most recent call last):
  File "syslog_purging_python.py", line 221, in <module>
    purge_logs()
  File "syslog_purging_python.py", line 137, in purge_logs
    bookmark_date = datetime.datetime.strptime(bookmark_timestamp, "%Y-%m-%dT%H:%M:%S+00:00").date()
  File "/usr/lib64/python3.6/_strptime.py", line 565, in _strptime_datetime
    tt, fraction = _strptime(data_string, format)
  File "/usr/lib64/python3.6/_strptime.py", line 362, in _strptime
    (data_string, format))
ValueError: time data '2023-09-20T15:45:15+02:00' does not match format '%Y-%m-%dT%H:%M:%S+00:00'

Somewhere here-
bookmark_date = datetime.datetime.strptime(bookmark_timestamp, "%Y-%m-%dT%H:%M:%S+00:00").date()

we are getting this error, how to handle this.