Skip to content

Commit

Permalink
Add support for Solr 9.* replication-lag check
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltoader authored and majormoses committed Oct 16, 2023
1 parent 84be544 commit d06a89b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 24 additions & 6 deletions bin/check-solr-replication-lag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/sensu-plugins-solr/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module SensuPluginsSolr
module Version
MAJOR = 1
MINOR = 1
MINOR = 2
PATCH = 0

VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
Expand Down

0 comments on commit d06a89b

Please sign in to comment.