Skip to content

Commit

Permalink
fix(DMVP-2705): Create Jira ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
Julia Aghamyan committed Oct 26, 2023
1 parent cfac0f6 commit 71e6768
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ def event_handler_for_expression(metrics_body):
}
return MetricWidget,expression,metric_namespace,metric_name

def event_handler(event, context):
def event_handler(event, context,region):
"""send message via teams"""

print("Event",event)
print("Context",context)

url = "https://" + os.environ['REGION'] + ".console.aws.amazon.com/cloudwatch/home?region=" + \
os.environ['REGION'] + "#alarmsV2:?~(alarmStateFilter~'ALARM)t"
url = "https://" + region + ".console.aws.amazon.com/cloudwatch/home?region=" + \
region + "#alarmsV2:?~(alarmStateFilter~'ALARM)t"

logger.debug("Event: {}".format(event))
message = str(event['Records'][0]['Sns']['Message'])
Expand Down Expand Up @@ -209,7 +209,7 @@ def event_handler(event, context):
}

# Get Cloudwatch metric widget, encoded base64
cloudwatch = boto3.client('cloudwatch', region_name=os.environ['REGION'])
cloudwatch = boto3.client('cloudwatch', region_name=region)
response = cloudwatch.get_metric_widget_image(
MetricWidget=json.dumps(MetricWidget))
encoded_data = base64.b64encode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def handler(event, context):
file_url = "https://raw.githubusercontent.com/dasmeta/terraform-aws-monitoring/DMVP-2705/modules/cloudwatch-alarm-actions/modules/lambda-subscription/src/event_handler.py"
# Import the module
module = import_from_url(file_url)
region = os.environ['REGION']

# Now you can use the function from the module
alert_type,subject,aws_account,aws_alarmdescription,dimension_string,metric_namespace,metric_name,image,url = module.event_handler(event, context)
alert_type,subject,aws_account,aws_alarmdescription,dimension_string,metric_namespace,metric_name,image,url = module.event_handler(event, context,region)

if alert_type == "Expression":
all_data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ def handler(event, context):
file_url = "https://raw.githubusercontent.com/dasmeta/terraform-aws-monitoring/DMVP-2705/modules/cloudwatch-alarm-actions/modules/lambda-subscription/src/event_handler.py"
# Import the module
module = import_from_url(file_url)
region = os.environ['REGION']

# Now you can use the function from the module
alert_type,subject,aws_account,aws_alarmdescription,dimension_string,metric_namespace,metric_name,image,url = module.event_handler(event, context)
alert_type,subject,aws_account,aws_alarmdescription,dimension_string,metric_namespace,metric_name,image,url = module.event_handler(event, context,region)

payload_data = payload(alert_type,subject,aws_account,aws_alarmdescription,dimension_string,metric_namespace,metric_name,image,url)
teams_webhook_url =os.environ['WEBHOOK_URL']
Expand Down

0 comments on commit 71e6768

Please sign in to comment.