Example #1
0
def QueryLogs(args: 'argparse.Namespace') -> None:
  """Query AWS CloudTrail log events.

  Args:
    args (argparse.Namespace): Arguments from ArgumentParser.
  """
  ct = aws_log.AWSCloudTrail(account.AWSAccount(args.zone))

  params = {}
  if args.filter:
    params['qfilter'] = args.filter
  if args.start:
    params['starttime'] = datetime.strptime(args.start, '%Y-%m-%d %H:%M:%S')
  if args.end:
    params['endtime'] = datetime.strptime(args.end, '%Y-%m-%d %H:%M:%S')

  result = ct.LookupEvents(**params)

  if result:
    print('Log events found: {0:d}'.format(len(result)))
    for event in result:
      print(event)
FAKE_VOLUME = ebs.AWSVolume('fake-volume-id', FAKE_AWS_ACCOUNT, 'fake-zone-2',
                            'fake-zone-2b', False)
FAKE_BOOT_VOLUME = ebs.AWSVolume('fake-boot-volume-id',
                                 FAKE_AWS_ACCOUNT,
                                 'fake-zone-2',
                                 'fake-zone-2b',
                                 False,
                                 name='fake-boot-volume',
                                 device_name='/dev/spf')
FAKE_SNAPSHOT = ebs.AWSSnapshot('fake-snapshot-id',
                                FAKE_AWS_ACCOUNT,
                                'fake-zone-2',
                                'fake-zone-2b',
                                FAKE_VOLUME,
                                name='fake-snapshot')
FAKE_CLOUDTRAIL = aws_log.AWSCloudTrail(FAKE_AWS_ACCOUNT)
FAKE_EVENT_LIST = [
    {
        'EventId': '474e8265-9180-4407-a5c9-f3a86d8bb1f0',
        'EventName': 'CreateUser',
        'ReadOnly': 'false'
    },
    {
        'EventId': '474e8395-9122-4407-a3b9-f3a77d8aa1f0',
        'EventName': 'AddUserToGroup',
        'ReadOnly': 'false'
    },
]

MOCK_DESCRIBE_INSTANCES = {
    'Reservations': [{