Skip to content
Browse files

Extra require to work around ri usage issues

  • Loading branch information...
1 parent 74f5ea3 commit 0c3f757960749081f3a2805b0943967a7d82a42b @alibby alibby committed Feb 25, 2009
Showing with 1 addition and 140 deletions.
  1. +1 −140 check_raid
View
141 check_raid
@@ -41,147 +41,8 @@
#
require 'getoptlong'
+require 'rdoc/ri/ri_paths'
require 'rdoc/usage'
-require 'ostruct';
-require 'yaml';
-require 'socket';
-
-class Checker < OpenStruct
- include Socket::Constants
-
- def initialize
- super
- self.warning=100
- self.critical=1
- self.host='localhost'
- end
-
- def read_from_yml(file)
- yml = YAML::load_file(file)
- yml.each_pair do |k,v|
- self.send("#{k}=",v)
- end
- end
-
- def ports;( port.to_i .. (port.to_i + servers.to_i - 1 ) ).to_a; end
-
- def check
- return if self.checked
- self.checked = true
- self.failed_connects=Hash.new
-
- ports.each do |p|
- socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
- sockaddr = Socket.pack_sockaddr_in( p, host )
- begin
- socket.connect( sockaddr )
- rescue Errno::ECONNREFUSED => e
- self.failed_connects.store(p,e.message)
- end
- end
- end
-
- def warning; super.to_f; end
-
- def critical; super.to_f; end
-
- def count_up
- self.check
- self.ports.size - self.failed_connects.keys.size
- end
-
- def count_down
- self.check
- self.failed_connects.keys.size
- end
-
- def percent_up
- self.check
- return 0 if count_up === 0
- ( count_up.to_f / servers.to_f ) * 100
- end
-end
-
-@checker = Checker.new
-
-begin
- opts = GetoptLong.new(
- [ '--help', "-h", GetoptLong::NO_ARGUMENT ],
- [ '--crit', '-c', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--warn', '-w', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--servers', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--host', '-H', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--port', '-p', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--yml', '-y', GetoptLong::REQUIRED_ARGUMENT ]
- ).each do |opt,arg|
- case opt
- when '--help', '-h'
- RDoc::usage
-
- when '--warn','-w'
- @checker.warn = arg
-
- when '--crit','-c'
- @checker.crit = arg
-
- when '--servers','-s'
- @checker.servers = arg
-
- when '--port','-p'
- @checker.port = arg
-
- when '--host', '-H'
- @checker.host = arg
-
- when '--yml', '-y'
- @checker.read_from_yml arg
- end
- end
-rescue GetoptLong::InvalidOption => e
- puts e.to_s
- exit 3
-end
-
-unless @checker.servers
- puts "Please supply number of servers via yaml or --servers"
- exit 3
-end
-
-unless @checker.port
- puts "Please supply base servers via yaml or --port"
- exit 3
-end
-
-if @checker.percent_up === 100
- puts "OKAY: #{@checker.count_up}/#{@checker.servers} servers up!"
- exit 0
-elsif @checker.percent_up < @checker.critical
- puts "CRITICAL: CLUSTER DOWN"
- exit 2
-elsif @checker.percent_up < @checker.warning
- puts "WARNING: #{@checker.count_up}/#{@checker.servers} servers up!"
- exit 1
-else
- puts "UNKNOWN status"
- exit 3
-end
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
require 'ostruct'
class String

0 comments on commit 0c3f757

Please sign in to comment.
Something went wrong with that request. Please try again.