Skip to content

Instantly share code, notes, and snippets.

@pooza
Last active December 3, 2016 21:53
Show Gist options
  • Save pooza/1b89a4c3bba03c432502c623cfac8443 to your computer and use it in GitHub Desktop.
Save pooza/1b89a4c3bba03c432502c623cfac8443 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
# これは最初に書いた古いバージョン。
# 現在運用中の新しいやつはここ。
# https://github.com/pooza/ginseng/blob/master/bin/nagios/check-df.rb
require 'net/ssh'
require 'timeout'
require 'optparse'
options = ARGV.getopts('H:u:', 'key:', 'mountpoint:', 'seconds:')
options['key'] ||= '~/.ssh/id_rsa'
options['mountpoint'] ||= '/'
options['seconds'] ||= 20
begin
Timeout.timeout(options['seconds']) do
Net::SSH.start(options['H'], options['u'], :keys => [options['key']]) do |ssh|
result = ssh.exec!("df #{options['mountpoint']}").each_line.to_a[1].split(/\s+/)
usage = result[4].sub!(/%$/, '').to_i
if 90 < usage
print "NG #{usage}%"
exit 2
elsif 80 < usage
print "WARN #{usage}%"
exit 1
end
print "OK #{usage}%"
end
end
rescue => e
print "NG #{e.class} #{e.message}"
exit 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment