Example #1
0
def download(bucket, prefix, org_id, account_id, region, log_dir, from_s, to_s,
             wait, parallelism):
    """Downloads CloudTrail Logs from S3."""
    log_dir = os.path.expanduser(log_dir)

    from_date = time_utils.parse_human_readable_time(from_s)
    to_date = time_utils.parse_human_readable_time(to_s)

    download_cloudtrail_logs(log_dir, bucket, prefix, org_id, account_id,
                             region, from_date, to_date, parallelism)

    if wait:
        last_timestamp = last_event_timestamp_in_dir(log_dir)
        while last_timestamp <= to_date:
            click.echo("CloudTrail logs haven't caught up to " + str(to_date) +
                       " yet. " + "Most recent timestamp: " +
                       str(last_timestamp.astimezone(to_date.tzinfo)) + ". " +
                       "Trying again in 60sec.")

            time.sleep(60 * 1)

            download_cloudtrail_logs(log_dir, bucket, prefix, org_id,
                                     account_id, region, from_date, to_date,
                                     parallelism)
            last_timestamp = last_event_timestamp_in_dir(log_dir)
Example #2
0
def last_event_timestamp(log_dir):
    """Print the most recent cloudtrail event timestamp"""
    log_dir = os.path.expanduser(log_dir)
    click.echo(last_event_timestamp_in_dir(log_dir))