bin/check-cloudwatch-alarms.rb in sensu-plugins-aws-18.5.0 vs bin/check-cloudwatch-alarms.rb in sensu-plugins-aws-18.6.0

- old
+ new

@@ -14,12 +14,13 @@ # DEPENDENCIES: # gem: aws-sdk # gem: sensu-plugin # # USAGE: +# ./check-cloudwatch-alarms --name-prefix "staging" # ./check-cloudwatch-alarms --exclude-alarms "CPUAlarmLow" -# ./check-cloudwatch-alarms --region eu-west-1 --exclude-alarms "CPUAlarmLow" +# ./check-cloudwatch-alarms --aws-region eu-west-1 --exclude-alarms "CPUAlarmLow" # # NOTES: # # LICENSE: # Copyright (c) 2017, Olivier Bazoud, olivier.bazoud@gmail.com @@ -44,10 +45,16 @@ description: 'State of the alarm', short: '-s STATE', long: '--state STATE', default: 'ALARM' + option :name_prefix, + description: 'Alarm name prefix', + short: '-p NAME_PREFIX', + long: '--name-prefix NAME_PREFIX', + default: '' + option :exclude_alarms, description: 'Exclude alarms', short: '-e EXCLUDE_ALARMS', long: '--exclude-alarms', proc: proc { |a| a.split(',') }, @@ -55,9 +62,14 @@ def run client = Aws::CloudWatch::Client.new options = { state_value: config[:state] } + + unless config[:name_prefix].empty? + options[:alarm_name_prefix] = config[:name_prefix] + end + alarms = client.describe_alarms(options).metric_alarms if alarms.empty? ok "No alarms in '#{config[:state]}' state" end