From 061b3d1f8c3ddda47125e5a2721ac375bb0c54be Mon Sep 17 00:00:00 2001 From: Aleksandra Jachowicz Date: Thu, 27 Apr 2023 16:56:33 +0200 Subject: [PATCH 1/2] Add option to pass check when file with given prefix is not found --- bin/check-s3-object.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bin/check-s3-object.rb b/bin/check-s3-object.rb index 41fd55f0..a8af3f00 100755 --- a/bin/check-s3-object.rb +++ b/bin/check-s3-object.rb @@ -108,6 +108,12 @@ class CheckS3Object < Sensu::Plugin::Check::CLI long: '--ok-on-multiple-objects', boolean: true + option :ok_no_file, + description: 'OK if file with given prefix is not found', + long: '--ok-no-file', + boolean: true, + default: false + def aws_config { access_key_id: config[:aws_access_key], secret_access_key: config[:aws_secret_access_key], @@ -167,7 +173,12 @@ def run output = output.next_page while output.next_page? if output.contents.size.to_i < 1 - critical "Object with prefix \"#{key_search}\" not found in bucket #{config[:bucket_name]}" + object_not_found = "Object with prefix \"#{key_search}\" not found in bucket #{config[:bucket_name]}" + if config[:ok_no_file] + ok object_not_found + else + critical object_not_found + end end if output.contents.size.to_i > 1 From deef22c90b07c56260f8caaafb03a7bf06d39f5b Mon Sep 17 00:00:00 2001 From: Aleksandra Jachowicz Date: Fri, 12 May 2023 12:27:37 +0200 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dd74fe0..9f8cddd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ 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] +### Added +- `check-s3-object.rb` - Added `--ok-no-file` option (@jaszka) ## 18.6.0 ### Added