Skip to content

Commit e46565e

Browse files
committed
Allow users to set the alarm prefix string from the CloudFormation template.
1 parent aff0fcf commit e46565e

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

Monitoring/auto-add-cw-alarms/auto_add_cw_alarms.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@
7272
#
7373
# The following is put in front of all alarms so an IAM policy can be create
7474
# that will allow this script to only be able to delete the alarms it creates.
75-
# If you change this, you must also change the IAM policy. Note that the
76-
# Cloudfomration template also assume the value of this variable.
77-
basePrefix="FSx-ONTAP-Auto"
75+
# If you change this, you must also change the IAM policy. It can be
76+
# set via an environment variable, this is so that the CloudFormation template
77+
# can pass the value to the Lambda function. To change the value, change
78+
# the "FSx-ONTAP-Auto" string to your desired value.
79+
import os
80+
basePrefix = os.environ.get('basePrefix', "FSx-ONTAP-Auto")
7881
#
7982
# Define the prefix for the volume utilization alarm name for the CloudWatch alarms.
8083
alarmPrefixVolume=f"{basePrefix}-Volume_Utilization_for_volume_"
@@ -92,7 +95,6 @@
9295
import botocore
9396
from botocore.config import Config
9497
import boto3
95-
import os
9698
import getopt
9799
import sys
98100
import time

Monitoring/auto-add-cw-alarms/cloudformation.yaml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Metadata:
1414
- defaultSSDThreshold
1515
- defaultVolumeThreshold
1616
- checkInterval
17+
- alarmPrefixString
1718

1819
Parameters:
1920
SNStopic:
@@ -56,6 +57,11 @@ Parameters:
5657
MinValue: 5
5758
Default: 15
5859

60+
alarmPrefixString:
61+
Description: "This is the string that will be prepended to all CloudWatch alarms created by this script."
62+
Type: String
63+
Default: "FSx-ONTAP-Auto"
64+
5965
Resources:
6066
LambdaRole:
6167
Type: "AWS::IAM::Role"
@@ -91,7 +97,7 @@ Resources:
9197
- Effect: "Allow"
9298
Action:
9399
- "cloudwatch:DeleteAlarms"
94-
Resource: !Sub "arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:FSx-ONTAP-Auto*"
100+
Resource: !Sub "arn:aws:cloudwatch:*:${AWS::AccountId}:alarm:${alarmPrefixString}*"
95101

96102
SchedulerRole:
97103
Type: "AWS::IAM::Role"
@@ -144,6 +150,7 @@ Resources:
144150
defaultCPUThreshold: !Ref defaultCPUThreshold
145151
defaultSSDThreshold: !Ref defaultSSDThreshold
146152
defaultVolumeThreshold: !Ref defaultVolumeThreshold
153+
basePrefix: !Ref alarmPrefixString
147154

148155
Code:
149156
ZipFile: |
@@ -176,8 +183,8 @@ Resources:
176183
# Lastly, you can create an override for the SSD alarm, by creating a tag
177184
# with the name "SSD_Alarm_Threshold" on the file system resource.
178185
#
179-
# Version: v2.11
180-
# Date: 2024-09-27-16:03:19
186+
# Version: v2.12
187+
# Date: 2024-10-01-14:58:15
181188
#
182189
################################################################################
183190
#
@@ -221,9 +228,12 @@ Resources:
221228
#
222229
# The following is put in front of all alarms so an IAM policy can be create
223230
# that will allow this script to only be able to delete the alarms it creates.
224-
# If you change this, you must also change the IAM policy. Note that the
225-
# Cloudfomration template also assume the value of this variable.
226-
basePrefix="FSx-ONTAP-Auto"
231+
# If you change this, you must also change the IAM policy. It can be
232+
# set via an environment variable, this is so that the CloudFormation template
233+
# can pass the value to the Lambda function. To change the value, change
234+
# the "FSx-ONTAP-Auto" string to your desired value.
235+
import os
236+
basePrefix = os.environ.get('basePrefix', "FSx-ONTAP-Auto")
227237
#
228238
# Define the prefix for the volume utilization alarm name for the CloudWatch alarms.
229239
alarmPrefixVolume=f"{basePrefix}-Volume_Utilization_for_volume_"
@@ -241,7 +251,6 @@ Resources:
241251
import botocore
242252
from botocore.config import Config
243253
import boto3
244-
import os
245254
import getopt
246255
import sys
247256
import time

0 commit comments

Comments
 (0)