From 904b34dfe65f87dda4ea8eaab16b5c07f7719786 Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Tue, 16 Jun 2020 19:03:00 -0700 Subject: [PATCH 1/3] Highlight false positives in `check-sqs-messages` when metric is unsupported Previously you could see something like this: ``` bundle _1.17.3_ exec ./bin/check-sqs-messages.rb -r us-east-1 -q test-sensu-380 -m ApproximateAgeOfOldestMessage -c 1 NEWER VERSION AVAILABLE: Please upgrade to AWS SDK For Ruby V3 SQSMsgs OK: 0 messages in test-sensu-380 queue ``` Instead this will now properly notify responders to the (now) known bug. As it appears to be an api limitation and not something we did in our code we will keep the discussion open for a proper solution but first things first is getting it to tell the truth. After the fix it should look something like this: ``` bundle exec ./bin/check-sqs-messages.rb -r us-east-1 -q test-sensu-380 -c 1 SQSMsgs UNKNOWN: failed to pull metric ApproximateNumberOfMessages on queue: test-sensu-380. available attributes: {"QueueArn"=>"arn:aws:sqs:us-east-1:892476923372:test-sensu-380", "ApproximateNumberOfMessages"=>"2", "ApproximateNumberOfMessagesNotVisible"=>"0", "ApproximateNumberOfMessagesDelayed"=>"0", "CreatedTimestamp"=>"1592356301", "LastModifiedTimestamp"=>"1592356301", "VisibilityTimeout"=>"30", "MaximumMessageSize"=>"262144", "MessageRetentionPeriod"=>"345600", "DelaySeconds"=>"0", "ReceiveMessageWaitTimeSeconds"=>"0"} ``` Signed-off-by: Ben Abrams --- CHANGELOG.md | 4 ++++ bin/check-sqs-messages.rb | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6923c345..92e6c273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md) ## [Unreleased] + +### Fixed +- `check-sqs-messages.rb`: properly surface false positives when pulling an unsupported metric (@majormoses) + ## [18.5.0] - 2020-01-28 ### Changed - `check-trustedadvisor-service-limits.rb`: Trusted Advisor combined Service Limits check ID 'eW7HH0l7J9' scheduled to be disabled on Feb 15 2020. Updated the script to go through every Service Limits checks and look for not 'ok' status. Outcome is the same. (@swibowo) diff --git a/bin/check-sqs-messages.rb b/bin/check-sqs-messages.rb index ca3cbea5..5c075b09 100755 --- a/bin/check-sqs-messages.rb +++ b/bin/check-sqs-messages.rb @@ -118,7 +118,15 @@ def run 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 + messages = sqs.client.get_queue_attributes(queue_url: url, attribute_names: ['All']) + if messages.attributes.key(config[:metric]) + messages = messages.attributes([config[:metric]]).to_i + else + unknown <<~EOF + failed to pull metric #{config[:metric]} on queue: #{q}. + available attributes: #{messages.attributes} + EOF + end if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over]) crits << "#{messages} message(s) in #{q}" From e72855201ab7745fe33f4f13aacc4d456d8a6aeb Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Tue, 16 Jun 2020 19:32:18 -0700 Subject: [PATCH 2/3] appease the cops Signed-off-by: Ben Abrams --- .rubocop.yml | 24 ++++++++++++++++-------- bin/check-sqs-messages.rb | 9 +++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9928d6b4..784d9040 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,27 +1,28 @@ - +AllCops: + TargetRubyVersion: 2.3 MethodLength: - Max: 200 + Max: 200 LineLength: - Max: 225 + Max: 225 AbcSize: Max: 125 FileName: - Enabled: false + Enabled: false PerceivedComplexity: - Enabled: false + Enabled: false CyclomaticComplexity: - Enabled: false + Enabled: false ClassLength: - Enabled: false + Enabled: false IfUnlessModifier: - Enabled: false + Enabled: false RegexpLiteral: Enabled: false @@ -38,6 +39,13 @@ Style/FormatString: Style/FrozenStringLiteralComment: Enabled: false +Style/NumericPredicate: + Enabled: false + +# I think we probably want to change this at some point +Style/SafeNavigation: + Enabled: false + Style/ClassVars: Exclude: - test/**/*.rb diff --git a/bin/check-sqs-messages.rb b/bin/check-sqs-messages.rb index 5c075b09..00e37732 100755 --- a/bin/check-sqs-messages.rb +++ b/bin/check-sqs-messages.rb @@ -122,10 +122,11 @@ def run if messages.attributes.key(config[:metric]) messages = messages.attributes([config[:metric]]).to_i else - unknown <<~EOF - failed to pull metric #{config[:metric]} on queue: #{q}. - available attributes: #{messages.attributes} - EOF + failure_msg = <<~MESSAGE + failed to pull metric # {config[:metric]} on queue: #{q}. + available attributes: # {messages.attributes} + MESSAGE + unknown failure_msg end if (config[:crit_under] >= 0 && messages < config[:crit_under]) || (config[:crit_over] >= 0 && messages > config[:crit_over]) From 95c27fe55ec114bf20b39b0617cf1725b565e73b Mon Sep 17 00:00:00 2001 From: Ben Abrams Date: Tue, 16 Jun 2020 21:37:49 -0700 Subject: [PATCH 3/3] fixing auto linter correction problrems? Signed-off-by: Ben Abrams --- bin/check-sqs-messages.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/check-sqs-messages.rb b/bin/check-sqs-messages.rb index 00e37732..7125662e 100755 --- a/bin/check-sqs-messages.rb +++ b/bin/check-sqs-messages.rb @@ -123,8 +123,8 @@ def run messages = messages.attributes([config[:metric]]).to_i else failure_msg = <<~MESSAGE - failed to pull metric # {config[:metric]} on queue: #{q}. - available attributes: # {messages.attributes} + failed to pull metric #{config[:metric]} on queue: #{q}. + available attributes: #{messages.attributes} MESSAGE unknown failure_msg end