bin/check-sqs-messages.rb in sensu-plugins-aws-16.2.0 vs bin/check-sqs-messages.rb in sensu-plugins-aws-17.0.0
- old
+ new
@@ -41,16 +41,24 @@
short: '-r AWS_REGION',
long: '--aws-region REGION',
description: 'AWS Region (defaults to us-east-1).',
default: 'us-east-1'
- option :queue,
+ option :queues,
short: '-q SQS_QUEUE',
long: '--queue SQS_QUEUE',
description: 'A comma seperated list of the SQS queue(s) you want to check the number of messages for',
- default: ''
+ default: [],
+ proc: proc { |q| q.split(',') }
+ option :exclude_queues,
+ short: '-Q SQS_QUEUES',
+ long: '--exclude-queues SQS_QUEUE',
+ description: 'A comma separated list of the SQS queue(s) to exclude, if using --prefix',
+ default: [],
+ proc: proc { |q| q.split(',') }
+
option :prefix,
short: '-p PREFIX',
long: '--prefix PREFIX',
description: 'The prefix of the queues you want to check the number of messages for',
default: ''
@@ -98,18 +106,18 @@
def run
Aws.config.update(aws_config)
sqs = Aws::SQS::Resource.new
if config[:prefix].empty?
- if config[:queue].empty?
+ if config[:queues].empty?
critical 'Error, either QUEUE or PREFIX must be specified'
end
warnings = []
crits = []
passing = []
- queues = config[:queue].split(',')
+ queues = config[:queues]
queues.each do |q|
url = sqs.get_queue_by_name(queue_name: q).url
messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All']).attributes[config[:metric]].to_i
if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
@@ -129,13 +137,16 @@
end
else
warn = false
crit = false
queues = []
+ exclusions = config[:exclude_queues]
sqs.queues(queue_name_prefix: config[:prefix]).each do |q|
messages = sqs.client.get_queue_attributes(queue_url: q.url, attribute_names: ['All']).attributes[config[:metric]].to_i
queue_name = q.attributes['QueueArn'].split(':').last
+
+ next if exclusions.include? queue_name
if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over])
crit = true
queues << "#{messages} message(s) in #{queue_name} queue"
elsif (config[:warn_under] >= 0 && messages < config[:warn_under]) || (config[:warn_over] >= 0 && messages > config[:warn_over])