Skip to content

Commit

Permalink
add check_rabbitmq_sync.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
honza committed Aug 10, 2016
1 parent 8fafc27 commit 24d36c9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ An example Vagrant project has been included to get you started right away.
<td><a href="https://github.com/loxo33">loxo33</a></td>
<td><a href="https://github.com/honzatlusty/sysadmin/blob/master/check_fileage.py">upstream</a></td>
</tr>
<tr>
<td>check_rabbitmq_sync</td>
<td><a href="https://github.com/honzatlusty">Jan Tlusty</a></td>
<td><a href="https://github.com/honzatlusty/nagios-rabbitmq-sync">upstream</a></td>
</tr>



</table>
Expand Down
1 change: 1 addition & 0 deletions build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ check_topology-spouts 1.0
check_topology 1.0
check_zookeeper 1.0
check_fileage.py 1.0
check_rabbitmq_sync.rb 1.0

# vim: set ts=2 sw=2 et : #
84 changes: 84 additions & 0 deletions check_rabbitmq_sync.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env ruby

# Author: Jan Tlusty
# Email: honza@inuits.eu
# Date: Tue Aug 09 2016

require 'net/http'
require 'uri'
require 'json'
require 'optparse'


def usage(optparse)
puts optparse
raise OptionParser::MissingArgument
end

options = {}
optparse = OptionParser.new do |opts|
opts.on('-h', '--host HOST', "Mandatory Host") do |f|
options[:host] = f
end
opts.on('-u', '--user USER', "Mandatory User Name") do |f|
options[:user] = f
end
opts.on('-p', '--password PASSWORD', "Mandatory Password") do |f|
options[:password] = f
end
opts.on('-v', '--vhost VHOST', "Mandatory Vhost") do |f|
options[:vhost] = f
end
opts.on('-P', '--port PORT', "Mandatory Port") do |f|
options[:port] = f
end
end


optparse.parse!

if options[:host] !~ /^https?:\/\/.*/
options[:host] = 'http://' + options[:host]
end


if options[:host].nil? or options[:user].nil? or options[:password].nil? or options[:vhost].nil? or options[:port].nil?
usage(optparse)
end


begin
uri = URI::parse("#{options[:host]}:#{options[:port]}/api/queues/#{options[:vhost]}")
req = Net::HTTP::Get.new(uri)
req.basic_auth options[:user], options[:password]
res = Net::HTTP.start(uri.hostname, uri.port) {|http|
http.request(req)
}

rescue
puts 'Unable to log in to the app.'
exit 3
end

begin
json = JSON.parse(res.body)
msg=''
json.each do |queue|
if queue.key?('slave_nodes')
if queue['slave_nodes'].sort != queue['synchronised_slave_nodes'].sort
msg += "#{queue['name']}: slave_nodes = #{queue['slave_nodes'].sort}, synchronized slave nodes = #{queue['synchronised_slave_nodes'].sort} "
end
end
end
rescue
puts "Something went wrong, rabbitmq returned #{res.body}"
exit 3
end

if msg == ''
puts 'All slave nodes are synchronized'
exit 0
else
puts msg
exit 1
end

0 comments on commit 24d36c9

Please sign in to comment.