Skip to content

Commit

Permalink
Move the cloudwatch alarm to api-lambda errors and put the pattern ma…
Browse files Browse the repository at this point in the history
…tching in jsonencode (#1019)

* try

* try

* fix
  • Loading branch information
jzbahrai authored Nov 9, 2023
1 parent e4c3b29 commit c65ae0c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
14 changes: 0 additions & 14 deletions aws/eks/cloudwatch_alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -715,17 +715,3 @@ resource "aws_cloudwatch_metric_alarm" "documentation-evicted-pods" {
ok_actions = [var.sns_alert_warning_arn]
insufficient_data_actions = [var.sns_alert_warning_arn]
}

resource "aws_cloudwatch_metric_alarm" "failed-login-count-5-minute-warning" {
alarm_name = "failed-login-count-5-minute-warning"
alarm_description = "One user had a failed login count of more than 10 times in 5 minutes"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = aws_cloudwatch_log_metric_filter.failed-login-count-more-than-10[0].name
namespace = aws_cloudwatch_log_metric_filter.failed-login-count-more-than-10[0].metric_transformation[0].namespace
period = 60
statistic = "Sum"
threshold = 1
treat_missing_data = "notBreaching"
alarm_actions = [var.sns_alert_warning_arn]
}
13 changes: 0 additions & 13 deletions aws/eks/cloudwatch_log.tf
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,3 @@ resource "aws_cloudwatch_log_metric_filter" "documentation-evicted-pods" {
value = "1"
}
}

resource "aws_cloudwatch_log_metric_filter" "failed-login-count-more-than-10" {
count = var.cloudwatch_enabled ? 1 : 0
name = "failed-login-count-more-than-10"
pattern = "\"Failed login: Incorrect password for\""
log_group_name = aws_cloudwatch_log_group.notification-canada-ca-eks-application-logs[0].name

metric_transformation {
name = "failed-login-count"
namespace = "LogMetrics"
value = "1"
}
}
16 changes: 15 additions & 1 deletion aws/lambda-api/cloudwatch_alarms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,18 @@ module "lambda_no_log_detection" {
time_period_minutes = 10
use_anomaly_detection = false
billing_tag_value = "notification-canada-ca-${var.env}"
}
}

resource "aws_cloudwatch_metric_alarm" "failed-login-count-5-minute-warning" {
alarm_name = "failed-login-count-5-minute-warning"
alarm_description = "One user had a failed login count of more than 10 times in 5 minutes"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = "5"
metric_name = aws_cloudwatch_log_metric_filter.failed-login-count-more-than-10[0].name
namespace = aws_cloudwatch_log_metric_filter.failed-login-count-more-than-10[0].metric_transformation[0].namespace
period = 60
statistic = "Sum"
threshold = 1
treat_missing_data = "notBreaching"
alarm_actions = [var.sns_alert_warning_arn]
}
15 changes: 14 additions & 1 deletion aws/lambda-api/cloudwatch_logs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ resource "aws_cloudwatch_log_metric_filter" "errors-salesforce-api" {
namespace = "LogMetrics"
value = "1"
}
}
}

resource "aws_cloudwatch_log_metric_filter" "failed-login-count-more-than-10" {
count = var.cloudwatch_enabled ? 1 : 0
name = "failed-login-count-more-than-10"
pattern = jsonencode("Failed login: Incorrect password for")
log_group_name = aws_cloudwatch_log_group.api_lambda_log_group[0].name

metric_transformation {
name = "failed-login-count"
namespace = "LogMetrics"
value = "1"
}
}

0 comments on commit c65ae0c

Please sign in to comment.