Exemple #1
0
def cloudtrail_reenable():
    """Re-enables CloudTrail if it has been turned off"""
    alert = False

    for aws_region in aws.get_regions():

        client = boto3.client('cloudtrail', region_name=aws_region)
        cloudtrails = client.describe_trails()['trailList']

        for cloudtrail in cloudtrails:
            if aws_region == cloudtrail['HomeRegion']:
                status = client.get_trail_status(Name=cloudtrail['TrailARN'])
                if status['IsLogging'] is False:
                    response = client.start_logging(
                        Name=cloudtrail['TrailARN'])
                    alert = True
                    logger.warning('CloudTrail disabled: {}'.format(
                        cloudtrail['TrailARN']))

    if alert:
        subject = 'CloudTrail Disabled!'
        body_text = 'CloudTrail(s) were disabled and attempted to be re-enabled.  See logs for additional information.'
        ses.send_email_default(subject, body_text)
    else:
        logger.info('No CloudTrail issues found')
if os.path.isdir(path):
    pass
else:
    os.mkdir(path)

logger = logging.getLogger("Rotating Log")
log_formatter = logging.Formatter('%(asctime)s\t %(levelname)s %(message)s')
logger.setLevel(logging.INFO)
handler = RotatingFileHandler(logfile, maxBytes=5 * 1024 * 1024, backupCount=5)
handler.setFormatter(log_formatter)
logger.addHandler(handler)

alert = False

for aws_region in aws.get_regions():

    client = boto3.client('cloudtrail', region_name=aws_region)
    cloudtrails = client.describe_trails()['trailList']

    for cloudtrail in cloudtrails:
        if aws_region == cloudtrail['HomeRegion']:
            status = client.get_trail_status(Name=cloudtrail['TrailARN'])
            if status['IsLogging'] is False:
                response = client.start_logging(Name=cloudtrail['TrailARN'])
                alert = True
                logger.warning('CloudTrail disabled: {}'.format(
                    cloudtrail['TrailARN']))

if alert:
    pass
import boto3
from aws import get_regions


def get_rules(region):
    client = boto3.client('config', region_name=region)
    response = client.describe_config_rules()

    return response


if __name__ == "__main__":
    aws_regions = get_regions()
    for aws_region in aws_regions:
        print(aws_region)

    selection = input('\nChoose a Region from above to see all Config Rules'
                      ' or type "all" to deploy Config from all Regions: ')

    if selection.lower() == 'all':
        for aws_region in aws_regions:
            print('*' * 15, aws_region, '*' * 15)
            rules = get_rules(aws_region)
            if len(rules['ConfigRules']) == 0:
                print('No Config Rules Implemented')
            else:
                n = 1
                answer = get_rules(aws_region)
                rules = answer['ConfigRules']
                for rule in rules:
                    print('Config Rule {}'.format(n))