Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only the last default RDS alarm is created #48

Open
connorhsm opened this issue May 10, 2023 · 1 comment
Open

Only the last default RDS alarm is created #48

connorhsm opened this issue May 10, 2023 · 1 comment

Comments

@connorhsm
Copy link

connorhsm commented May 10, 2023

It appears there's a small indentation error that mistakenly left some items outside the for loop, causing only the last alarm configured in the RDS default alarms to be created.

for tag in default_alarms['AWS/RDS']:
alarm_properties = tag['Key'].split(alarm_separator)
Namespace = alarm_properties[1]
MetricName = alarm_properties[2]
ComparisonOperator = alarm_properties[3]
Period = alarm_properties[4]
EvaluationPeriods = alarm_properties[5]
Statistic = alarm_properties[6]
AlarmName = alarm_separator.join(
[alarm_identifier, db_id, Namespace, MetricName, ComparisonOperator, str(tag['Value']),
Period, "{}p".format(EvaluationPeriods), Statistic])
# capture optional alarm description
try:
AlarmDescription = alarm_properties[7]
AlarmName += alarm_separator + AlarmDescription
except:
logger.info('Description not supplied')
AlarmDescription = None
create_alarm(AlarmName, AlarmDescription, MetricName, ComparisonOperator, Period, tag['Value'], Statistic,
Namespace, dimensions, EvaluationPeriods, sns_topic_arn)

If you compare to the earlier Lambda implementation:

for tag in default_alarms['AWS/Lambda']:
alarm_properties = tag['Key'].split(alarm_separator)
Namespace = alarm_properties[1]
MetricName = alarm_properties[2]
ComparisonOperator = alarm_properties[3]
Period = alarm_properties[4]
# Provide support for previous formatting of custom alarm tags where the evaluation period wasn't specified.
# If an evaluation period isn't specified in the tag then it defaults to 1, similar to past behavior.
if alarm_properties[5] in valid_statistics:
EvaluationPeriods = 1
eval_period_offset = 0
else:
EvaluationPeriods = alarm_properties[5]
eval_period_offset = 1
Statistic = alarm_properties[(5 + eval_period_offset)]
AlarmName = alarm_separator.join(
[alarm_identifier, function_name, Namespace, MetricName, ComparisonOperator, str(tag['Value']),
Period, "{}p".format(EvaluationPeriods), Statistic])
# capture optional alarm description
try:
AlarmDescription = alarm_properties[(6 + eval_period_offset)]
AlarmName += alarm_separator + AlarmDescription
except:
logger.info('Description not supplied')
AlarmDescription = None
create_alarm(AlarmName, AlarmDescription, MetricName, ComparisonOperator, Period, tag['Value'], Statistic,
Namespace,
dimensions, EvaluationPeriods, sns_topic_arn)

Greatly appreciate this sample, thanks for your work here!

@jbuiles1
Copy link

jbuiles1 commented Aug 2, 2023

Can confirm this is an issue and also indenting it properly is the solution. As the code is, when adding RDS alarms to the default set, only the last alarm gets created since the create alarm function is outside the for loop so it does not properly iterate through all alarms in the default alarm dictionary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants