Created
June 21, 2017 12:33
-
-
Save tanji/d42f12c0d926c47d330d1adc6acf1c27 to your computer and use it in GitHub Desktop.
Sensu check plugin for MariaDB / MySQL Replication Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# check-replication-manager.rb | |
# Copyright 2017 SIGNAL 18 <support@signal18.io> | |
# Released under the MIT License. Full text at https://opensource.org/licenses/MIT | |
require 'sensu-plugin/check/cli' | |
require 'json' | |
require 'net/http' | |
class MRMCheck < Sensu::Plugin::Check::CLI | |
check_name 'mrm_check' | |
def run | |
uri = URI('http://localhost:10001/servers') | |
res = Net::HTTP.get_response(uri) | |
srv_hash = JSON.parse(res.body) | |
srv_stdl = 0 | |
srv_fail = 0 | |
srv_mstr = 0 | |
srv_repl = 0 | |
srv_hash.each do |array| | |
if array['State'] == 'Standalone' | |
srv_stdl += 1 | |
elsif array['State'] == 'Failed' | |
srv_fail += 1 | |
elsif array['State'] == 'Master' | |
srv_mstr += 1 | |
elsif array['State'] == 'Slave' | |
srv_repl += 1 | |
end | |
end | |
if srv_fail > 0 | |
critical "Servers in failed status: #{srv_fail}" | |
elsif srv_stdl > 0 | |
warning "Servers not connected: #{srv_stdl}" | |
else | |
ok "#{srv_mstr} master and #{srv_repl} replica servers monitored" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment