-
-
Save ober/8e3384e3e5a442e6cf3c to your computer and use it in GitHub Desktop.
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 | |
require 'rubygems' | |
require 'xenapi' | |
require 'pp' | |
class Net::HTTP | |
alias_method :old_initialize, :initialize | |
def initialize(*args) | |
old_initialize(*args) | |
@ssl_context = OpenSSL::SSL::SSLContext.new | |
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
end | |
end | |
@config = YAML.load(File.read("/etc/secrets")) | |
REAL = 51_539_607_552 | |
crit = 95 | |
warn = 85 | |
critout = '' | |
warnout = '' | |
okout = '' | |
servers = { | |
'linbsd1' => nil, | |
'linbsd2' => nil, | |
'linbsd3' => nil, | |
'linbsd4' => nil, | |
} | |
servers.keys.each do |s| | |
total = 0 | |
client = XenApi::Client.new("https://#{s}:443") | |
client.login_with_password('root', @config[s][:password]) | |
client.VM_metrics.get_all_records.each_pair { |k,v| total += v["memory_actual"].to_i } | |
client.logout | |
servers[s] = total | |
end | |
servers.each_pair do |k,v| | |
used = (((REAL - v)/REAL.to_f) * 100).to_i | |
if used > crit | |
critout << "\tCRIICAL: #{k} using #{used}% total memory" | |
elsif used > warn | |
warnout << "\tWARNING: #{k} using #{used}% total memory" | |
else | |
okout << "\tOK: #{k} using #{used}% total memory" | |
end | |
end | |
critout = nil if critout.empty? | |
warnout = nil if warnout.empty? | |
if critout | |
puts critout | |
exit(1) | |
elsif warnout | |
puts warnout | |
exit(1) | |
else | |
puts okout | |
exit(0) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment