Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
1
Indexable
Never
Bookmark Line: 2023-05-14T05:48:39+00:00 LONSTBYRDEV02 tag_audit_log: type=CRYPTO_KEY_USER msg=audit(1684039717.583:68344093): pid=10590 uid=0 auid=4294967295 ses=4294967295 msg='op=destroy kind=server fp=SHA256:b6:0b:d4:a1:ef:1e:fd:12:4a:9f:07:59:2b:fc:38:c0:39:38:ab:c5:78:92:cd:90:8c:d5:8f:e2:aa:9a:c4:69 direction=? spid=10590 suid=0  exe="/usr/sbin/sshd" hostname=? addr=10.72.208.221 terminal=? res=success'

Traceback (most recent call last):
  File "/App/jar/KPI/syslog_purging_linecache.py", line 141, in <module>
    purge_logs()
  File "/App/jar/KPI/syslog_purging_linecache.py", line 122, in purge_logs
    timestamp = get_timestamp_from_line(line)
  File "/App/jar/KPI/syslog_purging_linecache.py", line 78, in get_timestamp_from_line
    timestamp = line.split()[0]
IndexError: list index out of range


This is the function-

def get_timestamp_from_line(line):
    # Extract the timestamp from the line
    timestamp = line.split()[0]
    return timestamp


import datetime

def purge_logs():
    vm_details = get_vm_details()

    for vm in vm_details:
        vm_id = vm['vm_id']
        vm_ip = vm['vm_ip']
        syslog_file = vm['syslog_file_location']
        retention_period = get_retention_period(vm_id)
        bookmark_index = get_bookmark_index(vm_ip)

        print("VM:", vm_id)
        print("Syslog File Location:", syslog_file)
        print("Retention Period:", retention_period)
        print("Bookmark Index:", bookmark_index)
        print("Purging Logs...")

 try:
            bookmark_line = linecache.getline(syslog_file, int(bookmark_index))
            print("Bookmark Line:", bookmark_line)
        except Exception as e:
            print("Exception while reading line from file:", e)
            return None

        if not bookmark_line:
            print("Bookmark line not found.")
            continue

        bookmark_timestamp = get_timestamp_from_line(bookmark_line)