From 316a94c57be9e38e5d96dd1b8152cd12d56cbbe9 Mon Sep 17 00:00:00 2001 From: kperronne Date: Thu, 3 Aug 2017 12:02:01 -0700 Subject: [PATCH 1/4] Allow querying specific node for check-rabbitmq-node-health --- CHANGELOG.md | 1 + bin/check-rabbitmq-node-health.rb | 35 +++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be9d490..e889301 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang ## [Unreleased] ### Added +- Proper node definition support for node health check (@Infraded) - ruby 2.4 support (@majormoses) ### Fixed diff --git a/bin/check-rabbitmq-node-health.rb b/bin/check-rabbitmq-node-health.rb index 162c607..812eff4 100755 --- a/bin/check-rabbitmq-node-health.rb +++ b/bin/check-rabbitmq-node-health.rb @@ -29,6 +29,7 @@ require 'json' require 'rest_client' require 'inifile' +require 'socket' # main plugin class class CheckRabbitMQNodeHealth < Sensu::Plugin::Check::CLI @@ -56,6 +57,21 @@ class CheckRabbitMQNodeHealth < Sensu::Plugin::Check::CLI long: '--port PORT', default: '15672' + option :node_prefix, + description: 'RabbitMQ node prefix (eg. rabbit in rabbit@hostname)', + long: '--prefix NODENAME', + default: 'rabbit' + + option :node_use_fqdn, + description: 'Use FQDN for determining node hostname', + long: '--fqdn', + boolean: true, + default: false + + option :node_host, + description: 'RabbitMQ node name override (eg. hostname in rabbit@hostname)', + long: '--nodehost HOSTNAME' + option :ssl, description: 'Enable SSL for connection to the API', long: '--ssl', @@ -142,6 +158,20 @@ def node_healthy? password = config[:password] ssl = config[:ssl] verify_ssl = config[:verify_ssl_off] + node_prefix = config[:node_prefix] + + # Determine node hostname to query, as this may not be the same as connection hostname + if config[:node_host] + # Statically set by config + node_host = config[:node_host] + elsif config[:node_use_fqdn] + # Resolved from system running check, full FQDN, the same as RABBITMQ_USE_LONGNAME + node_host = Socket.gethostname + else + # Default of short hostname, resolved from system + node_host = Socket.gethostname.partition('.').first + end + if config[:ini] ini = IniFile.load(config[:ini]) section = ini['auth'] @@ -154,14 +184,15 @@ def node_healthy? begin url_prefix = ssl ? 'https' : 'http' + node = "#{node_prefix}@#{node_host}" resource = RestClient::Resource.new( - "#{url_prefix}://#{host}:#{port}/api/nodes", + "#{url_prefix}://#{host}:#{port}/api/nodes/#{node}", user: username, password: password, verify_ssl: !verify_ssl ) # Parse our json data - nodeinfo = JSON.parse(resource.get)[0] + nodeinfo = JSON.parse(resource.get) # Determine % memory consumed pmem = format('%.2f', nodeinfo['mem_used'].fdiv(nodeinfo['mem_limit']) * 100) From c607224853153a5b3160061188974b9354fd73d0 Mon Sep 17 00:00:00 2001 From: kperronne Date: Thu, 3 Aug 2017 12:33:51 -0700 Subject: [PATCH 2/4] Better changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e889301..a4809f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang ## [Unreleased] ### Added -- Proper node definition support for node health check (@Infraded) +- check-rabbitmq-node-health: Proper node definition support (@Infraded) - ruby 2.4 support (@majormoses) ### Fixed From e5a57145fd72b7056ab1a8132f94b8c33719f93c Mon Sep 17 00:00:00 2001 From: kperronne Date: Thu, 3 Aug 2017 12:52:38 -0700 Subject: [PATCH 3/4] Fix option alignment --- bin/check-rabbitmq-node-health.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/check-rabbitmq-node-health.rb b/bin/check-rabbitmq-node-health.rb index 812eff4..2fd57ff 100755 --- a/bin/check-rabbitmq-node-health.rb +++ b/bin/check-rabbitmq-node-health.rb @@ -152,12 +152,12 @@ def run end def node_healthy? - host = config[:host] - port = config[:port] - username = config[:username] - password = config[:password] - ssl = config[:ssl] - verify_ssl = config[:verify_ssl_off] + host = config[:host] + port = config[:port] + username = config[:username] + password = config[:password] + ssl = config[:ssl] + verify_ssl = config[:verify_ssl_off] node_prefix = config[:node_prefix] # Determine node hostname to query, as this may not be the same as connection hostname From de5d93b8c0160e1c4176d3c2296f1c4ccb25c290 Mon Sep 17 00:00:00 2001 From: kperronne Date: Thu, 3 Aug 2017 13:23:55 -0700 Subject: [PATCH 4/4] Rubocop conditional cleanup --- bin/check-rabbitmq-node-health.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/check-rabbitmq-node-health.rb b/bin/check-rabbitmq-node-health.rb index 2fd57ff..239e859 100755 --- a/bin/check-rabbitmq-node-health.rb +++ b/bin/check-rabbitmq-node-health.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby # encoding: UTF-8 + # # RabbitMQ check node health plugin # === @@ -161,16 +162,16 @@ def node_healthy? node_prefix = config[:node_prefix] # Determine node hostname to query, as this may not be the same as connection hostname - if config[:node_host] - # Statically set by config - node_host = config[:node_host] - elsif config[:node_use_fqdn] - # Resolved from system running check, full FQDN, the same as RABBITMQ_USE_LONGNAME - node_host = Socket.gethostname - else - # Default of short hostname, resolved from system - node_host = Socket.gethostname.partition('.').first - end + node_host = if config[:node_host] + # Statically set by config + config[:node_host] + elsif config[:node_use_fqdn] + # Resolved from system running check, full FQDN, the same as RABBITMQ_USE_LONGNAME + Socket.gethostname + else + # Default of short hostname, resolved from system + Socket.gethostname.partition('.').first + end if config[:ini] ini = IniFile.load(config[:ini])