Skip to content

Commit

Permalink
feat: add suppression of notifications for specific fsx states (#34)
Browse files Browse the repository at this point in the history
* feat: add suppression of notifications for specific fsx states

* terraform-docs: automated action

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
stefanfreitag and github-actions[bot] committed Oct 22, 2023
1 parent 62ec478 commit 285f7ec
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ terraform.rc

# Output directory for zipped Lambda functions
out

# Python
.venv/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_email"></a> [email](#input\_email) | List of e-mail addresses subscribing to the SNS topic. Default is empty list. | `list(string)` | `[]` | no |
| <a name="input_ignore_states"></a> [ignore\_states](#input\_ignore\_states) | Suppress warnings for the listed FSx states. Default: ['CREATING', 'UPDATING'] | `list(string)` | <pre>[<br> "CREATING",<br> "UPDATING"<br>]</pre> | no |
| <a name="input_log_retion_period_in_days"></a> [log\_retion\_period\_in\_days](#input\_log\_retion\_period\_in\_days) | Number of days logs will be retained. Default is 365 days. | `number` | `365` | no |
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | Amount of memory in MByte that the Lambda Function can use at runtime. Default is 160. | `number` | `160` | no |
| <a name="input_schedule_expression"></a> [schedule\_expression](#input\_schedule\_expression) | The schedule expression for the CloudWatch event rule. Default is 'rate(60 minutes)'. | `string` | `"rate(60 minutes)"` | no |
Expand Down
15 changes: 11 additions & 4 deletions functions/check-fsx-status/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
import os


def lambda_handler(event, context):
LAMBDASNSTOPIC = os.environ["LambdaSNSTopic"]
LAMBDASNSTOPIC = os.environ["LambdaSNSTopic"]
SUPPRESS_STATES = os.environ["SUPPRESS_STATES"].split(",")
VALID_STATES = ["AVAILABLE"] + SUPPRESS_STATES


def lambda_handler(event, context):
fsx_windows = boto3.client("fsx")
filesystems = fsx_windows.describe_file_systems()
print(
"Notifications suppressed for these FSx states: {}".format(
", ".join(VALID_STATES)
)
)
for filesystem in filesystems.get("FileSystems"):
status = filesystem.get("Lifecycle")
filesystem_id = filesystem.get("FileSystemId")
sns_client = boto3.client("sns")
if status != "AVAILABLE":
if status not in VALID_STATES:
print("The file system: {} needs attention.".format(filesystem_id))
sns_client.publish(
TopicArn=LAMBDASNSTOPIC,
Expand All @@ -28,5 +36,4 @@ def lambda_handler(event, context):
filesystem_id
)
)
# Return the status
return {"statusCode": 200, "body": "OK"}
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ resource "aws_lambda_function" "fsx_health_lambda" {
}
environment {
variables = {
LambdaSNSTopic = aws_sns_topic.fsx_health_sns_topic.arn
LambdaSNSTopic = aws_sns_topic.fsx_health_sns_topic.arn
SUPPRESS_STATES = join(",", var.ignore_states)
}
}
source_code_hash = data.archive_file.status_checker_code.output_base64sha256
Expand Down
8 changes: 8 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ variable "email" {
default = []
}

variable "ignore_states" {
description = "Suppress warnings for the listed FSx states. Default: ['CREATING', 'UPDATING']"
type = list(string)
default = [
"CREATING", "UPDATING"
]
}

variable "log_retion_period_in_days" {
type = number
default = 365
Expand Down

0 comments on commit 285f7ec

Please sign in to comment.