Class: Nrpeclient::CheckNrpe
- Inherits:
-
Object
- Object
- Nrpeclient::CheckNrpe
- Defined in:
- lib/nrpeclient/check_nrpe.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :host => '0.0.0.0', :port => '5666', :ssl => false }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CheckNrpe
constructor
A new instance of CheckNrpe.
- #send(message) ⇒ Object
- #send_command(command, *args) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CheckNrpe
Returns a new instance of CheckNrpe.
13 14 15 16 17 18 19 20 21 |
# File 'lib/nrpeclient/check_nrpe.rb', line 13 def initialize(={}) @options = DEFAULT_OPTIONS.merge() if @options[:ssl] @ssl_context = OpenSSL::SSL::SSLContext.new :SSLv23 @ssl_context.ciphers = 'ADH' @ssl_context.cert = OpenSSL::X509::Certificate.new(File.open(@options.fetch(:ssl_cert))) if !@options[:ssl_cert].nil? @ssl_context.key = OpenSSL::PKey::RSA.new(File.open(@options.fetch(:ssl_key))) if !@options[:ssl_key].nil? end end |
Instance Method Details
#send(message) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nrpeclient/check_nrpe.rb', line 23 def send() query = Nrpeclient::NrpePacket.new query.packet_type = :query query.buffer = query.result_code = Nrpeclient::STATUS_UNKNOWN begin socket = TCPSocket.open(@options[:host], @options[:port]) if @options[:ssl] socket = OpenSSL::SSL::SSLSocket.new(socket, @ssl_context) socket.sync_close = true socket.connect end socket.write(query.to_bytes) response = Nrpeclient::NrpePacket.read(socket, !@options[:ssl]) socket.close return response rescue Errno::ETIMEDOUT raise 'NRPE request timed out' end end |
#send_command(command, *args) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/nrpeclient/check_nrpe.rb', line 45 def send_command(command, *args) = command args.each do |arg| += '!' + arg end return self.send() end |