oracle/oci-python-sdk

audit trails in datasafe library fails to return

bathax opened this issue · 5 comments

I'm trying to get certain events from datasafe:

def get_audit_trails(region,compartment, datasafe_client, start_time, end_time, lifecycle_state, status):
    print(region + "-" + compartment.name + ": Getting Audit Trails - " + lifecycle_state + " - " + status)
    try:
        audit_trails = datasafe_client.list_audit_trails(compartment.id,lifecycle_state=lifecycle_state, status=status)
        audit_trail_list = []
        for audit_trail in audit_trails.data.items:
          audit_trail_list.append(audit_trail)
        has_next_page = audit_trails.has_next_page
        while has_next_page:
          next_page = audit_trails.next_page
          audit_trails = datasafe_client.list_audit_trails(compartment.id,lifecycle_state=lifecycle_state, status=status)
          has_next_page = audit_trails.has_next_page
          for audit_trail in audit_trails.data.items:
              audit_trail_list.append(audit_trail)
        for audit_trail in audit_trail_list:
          yield audit_trail
    except oci.exceptions.ServiceError as e:
        print('Unexpected error when retrieving events: {}'.format(str(e)))
        if e.code == "TooManyRequests":
          time.sleep(60)
    except AttributeError as e:
        print('Unexpected error when retrieving events: {}'.format(str(e)))

When querying any audit trail that exists this will stall forever. Is this working correctly?

bump

Thanks for reporting this @bathax. We will try the code you shared at our end to reproduce this. qq - what is the purpose of this statement
next_page = audit_trails.next_page on line no. 10 ?

this is for pagination in the while loop that I have, otherwise I'd keep getting the same page over and over.

@jyotisaini any update on this?

@bathax but I do not see next_page being used anywhere. I think the loop isn't progressing and its going in infinite loop.