Skip to content

Commit

Permalink
Add dynamic values for metric expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
cfln123 committed Sep 16, 2024
1 parent 7533103 commit 5b0eefb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/cfnguardian/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,16 @@ def get_alarms(group,overides={})
@alarms.each {|a| a.group = @override_group}
end

# String interpolation for alarm dimensions
@alarms.each do |alarm|
if ! alarm.metrics.nil?
alarm.metrics.each_with_index do |m,i|
m['Expression'] = { "Fn::Sub": [ m['Expression'], @resource ] }
m['Label'] = "#{alarm.name}#{i}" if m['Label'].nil?
m['Id'] = "q#{i}" if m['Id'].nil?
m['Period'] = alarm.period if m['Period'].nil?
end
end
# String interpolation for alarm dimensions
next if alarm.dimensions.nil? || ! alarm.metrics.nil?
alarm.dimensions.each do |k,v|
if v.is_a?(String) && v.match?(/^\${Resource::.*[A-Za-z]}$/)
Expand Down

0 comments on commit 5b0eefb

Please sign in to comment.