From d06a89b75dee933bbf08d9862f906d7d4b3d2e2b Mon Sep 17 00:00:00 2001 From: Daniel Toader Date: Sat, 14 Oct 2023 16:42:30 +0300 Subject: [PATCH] Add support for Solr 9.* replication-lag check --- CHANGELOG.md | 7 ++++++- README.md | 2 +- bin/check-solr-replication-lag.rb | 30 ++++++++++++++++++++++++------ lib/sensu-plugins-solr/version.rb | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 751205d..080cdac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins ## [Unreleased] +## [1.2.0] - 2023-10-14 +### Changed +- Changed solr replication lag check to also support solr 9.* (@danieltoader) + ## [1.1.0] - 2018-07-12 ### Added - Added solr replication lag check (@alexbumbacea) @@ -40,7 +44,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins ### Added - initial release -[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-solr/compare/1.1.0...HEAD +[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-solr/compare/1.2.0...HEAD +[1.2.0]: https://github.com/sensu-plugins/sensu-plugins-solr/compare/1.1.0...1.2.0 [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-solr/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-solr/compare/0.0.3...1.0.0 [0.0.3]: https://github.com/sensu-plugins/sensu-plugins-solr/compare/0.0.2...0.0.3 diff --git a/README.md b/README.md index f1dcd89..0d5a227 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,6 @@ ## Installation -[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html) +[Installation and Setup](https://docs.sensu.io/sensu-core/latest/installation/installing-plugins/) ## Notes diff --git a/bin/check-solr-replication-lag.rb b/bin/check-solr-replication-lag.rb index fba3ee0..b9f2932 100755 --- a/bin/check-solr-replication-lag.rb +++ b/bin/check-solr-replication-lag.rb @@ -56,11 +56,29 @@ class SolrCheckReplication < Sensu::Plugin::Check::CLI boolean: true, default: false - def get_url_json(url, notfoundok) - r = RestClient::Resource.new(url, timeout: 45) + option :username, + description: 'Username for HTTP Basic Authentication', + short: '-U USERNAME', + long: '--username USERNAME', + required: false + + option :password, + description: 'Password for HTTP Basic Authentication', + short: '-P PASSWORD', + long: '--password PASSWORD', + required: false + + def get_url_json(url, notfoundok, username = nil, password = nil) + resource_options = { timeout: 45 } + resource_options[:user] = username if username + resource_options[:password] = password if password + + r = RestClient::Resource.new(url, resource_options) JSON.parse(r.get) rescue Errno::ECONNREFUSED warning 'Connection refused' + rescue RestClient::Unauthorized + warning 'Unauthorized: Invalid credentials' rescue RestClient::RequestTimeout warning 'Connection timed out' rescue RestClient::ResourceNotFound @@ -76,11 +94,11 @@ def get_url_json(url, notfoundok) def run base_core_uri = "#{config[:protocol]}://#{config[:host]}:#{config[:port]}/solr/#{config[:core]}" uri = "#{base_core_uri}/replication?command=details&wt=json" - data = get_url_json(uri, config[:core_missing_ok]) + data = get_url_json(uri, config[:core_missing_ok], config[:username], config[:password]) details = data['details'] - if details['isSlave'] == 'true' - slave_details = details['slave'] - lag = (DateTime.parse(slave_details['currentDate']).to_time - DateTime.parse(slave_details['indexReplicatedAt']).to_time).to_i + if details['isFollower'] == 'true' || details['isSlave'] == 'true' + follower_details = details['follower'] || details['slave'] + lag = (DateTime.parse(follower_details['currentDate']).to_time - DateTime.parse(follower_details['indexReplicatedAt']).to_time).to_i if lag >= config[:critical] critical "Replication lag exceeds #{config[:critical]} seconds (#{lag})" elsif lag >= config[:warning] diff --git a/lib/sensu-plugins-solr/version.rb b/lib/sensu-plugins-solr/version.rb index c3a21c8..519f9d1 100644 --- a/lib/sensu-plugins-solr/version.rb +++ b/lib/sensu-plugins-solr/version.rb @@ -1,7 +1,7 @@ module SensuPluginsSolr module Version MAJOR = 1 - MINOR = 1 + MINOR = 2 PATCH = 0 VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')