Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Potential fix for #19
Browse files Browse the repository at this point in the history
  • Loading branch information
mlevit committed May 24, 2019
1 parent b9ebcf3 commit c80c51a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions auto_remediate/lambda_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from config_rules import *
from custom_rules import *
from security_hub_rules import *
from sns_logging_handler import *
from sns_handler import *


class Remediate:
Expand Down Expand Up @@ -159,9 +159,9 @@ def get_settings(self):
settings[record_json["key"]] = record_json["value"]
except:
self.logging.error(
f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'."
, exc_info=True)

f"Could not read DynamoDB table '{os.environ['SETTINGSTABLE']}'.",
exc_info=True,
)

return settings

Expand Down Expand Up @@ -226,9 +226,10 @@ def send_to_dead_letter_queue(self, config_payload, try_count):
)
except:
self.logging.error(
f"Could not send payload to SQS DLQ '{os.environ['DEADLETTERQUEUE']}'."
, exc_info=True)

f"Could not send payload to SQS DLQ '{os.environ['DEADLETTERQUEUE']}'.",
exc_info=True,
)

else:
self.logging.warning(
f"Could not remediate Config change within an "
Expand All @@ -253,7 +254,9 @@ def send_to_missing_remediation_topic(self, config_rule_name, config_payload):
Subject=f"No remediation available for Config Rule '{config_rule_name}'",
)
except:
self.logging.error(f"Could not publish to SNS Topic 'topic_arn'.", exc_info=True)
self.logging.error(
f"Could not publish to SNS Topic 'topic_arn'.", exc_info=True
)


def lambda_handler(event, context):
Expand All @@ -271,13 +274,20 @@ def lambda_handler(event, context):
# set logging format
logging.basicConfig(
format="[%(levelname)s] %(message)s (%(filename)s, %(funcName)s(), line %(lineno)d)",
level=os.environ.get("LOGLEVEL", "WARNING"),
level=os.environ.get("LOGLEVEL", "INFO"),
)

# add console logger
console_logger = logging.StreamHandler()
console_logger.setLevel(os.environ.get("LOGLEVEL", "INFO"))

# add SNS logger
# sns_logger = SNSLoggingHandler(os.environ.get('LOGTOPIC'))
# sns_logger.setLevel(logging.INFO)
# loggger.addHandler(sns_logger)
sns_logger = SNSHandler(os.environ.get("LOGTOPIC"))
sns_logger.setLevel(logging.INFO)

# add the handlers to the root logger
loggger.addHandler(console_logger)
loggger.addHandler(sns_logger)

# instantiate class
remediate = Remediate(logging, event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import boto3


class SNSLoggingHandler(logging.Handler):
class SNSHandler(logging.Handler):
def __init__(self, topic_arn):
logging.Handler.__init__(self)
self.client = boto3.client("sns")
Expand Down

0 comments on commit c80c51a

Please sign in to comment.