tested against nsca-2.7 (client and server) (iv_key and password)
This commit is contained in:
parent
476d58d7ec
commit
bdb441f237
|
@ -31,7 +31,7 @@ module NSCA
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'lib/packet'
|
require 'nsca/packet'
|
||||||
require 'lib/server'
|
require 'nsca/server'
|
||||||
require 'lib/client'
|
require 'nsca/client'
|
||||||
require 'lib/check'
|
require 'nsca/check'
|
||||||
|
|
|
@ -153,6 +153,21 @@ module NSCA
|
||||||
def unknown( status = nil, perfdatas = nil) new.unknown status, perfdatas end
|
def unknown( status = nil, perfdatas = nil) new.unknown status, perfdatas end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class <<self
|
||||||
|
def create service, hostname = nil, perfdatas = nil
|
||||||
|
cl = Class.new Base
|
||||||
|
cl.init service, hostname, perfdatas
|
||||||
|
cl
|
||||||
|
end
|
||||||
|
|
||||||
|
def new service, hostname = nil, perfdatas = nil
|
||||||
|
cl = create service, hostname, perfdatas
|
||||||
|
clname = NSCA::Helper.class_name_gen service.to_s
|
||||||
|
self.const_set clname, cl if clname
|
||||||
|
cl
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Checks
|
module Checks
|
||||||
|
|
|
@ -67,7 +67,7 @@ module NSCA
|
||||||
# @param [String(length<512)] status Status-line inclusive optional Performance Data.
|
# @param [String(length<512)] status Status-line inclusive optional Performance Data.
|
||||||
def build_packet timestamp, return_code, hostname, service, status
|
def build_packet timestamp, return_code, hostname, service, status
|
||||||
packet = @packet_version.new timestamp || @timestamp, return_code, hostname, service, status
|
packet = @packet_version.new timestamp || @timestamp, return_code, hostname, service, status
|
||||||
packet.build @iv_key
|
packet.build @iv_key, @password
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sends a check-result.
|
# Sends a check-result.
|
||||||
|
@ -78,7 +78,7 @@ module NSCA
|
||||||
# @param [Array<NSCA::Check::Base>] results
|
# @param [Array<NSCA::Check::Base>] results
|
||||||
def send *results
|
def send *results
|
||||||
results.flatten.each do |r|
|
results.flatten.each do |r|
|
||||||
send r.timestamp, r.retcode, r.hostname, r.service, r.text
|
send_packet r.timestamp, r.retcode, r.hostname, r.service, r.text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -86,15 +86,12 @@ module NSCA
|
||||||
def close( *a) @socket.close( *a) end
|
def close( *a) @socket.close( *a) end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :socket_or_host, :port, :password
|
attr_reader :hostname, :port, :password
|
||||||
def initialize socket_or_host = nil, port = nil, password = nil, &connect
|
def initialize hostname = nil, port = nil, password = nil
|
||||||
@socket_or_host, @port, @password = socket_or_host, port, password
|
@hostname, @port, @password = hostname, port, password
|
||||||
end
|
|
||||||
|
|
||||||
def open &e
|
|
||||||
Connection.open @socket_or_host, @port, @password, &e
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def open( &e) Connection.open @hostname, @port, @password, &e end
|
||||||
def send( *results) open {|conn| conn.send results } end
|
def send( *results) open {|conn| conn.send results } end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,7 +48,8 @@ module NSCA
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
@packet_version.parse read, @iv_key, @password
|
data = read
|
||||||
|
@packet_version.parse data, @iv_key, @password if data
|
||||||
end
|
end
|
||||||
|
|
||||||
def eof?() @socket.eof? end
|
def eof?() @socket.eof? end
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
module NSCA
|
|
||||||
def self.dummy_server port, password = nil, key = nil
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
load Pathname.new( __FILE__).dirname.join( '..', 'lib', 'nsca.rb').to_s
|
$: << Pathname.new( __FILE__).dirname.join( '..', 'lib').to_s
|
||||||
serv = NSCA::Server.new port, password: password, key: key
|
|
||||||
|
module NSCA
|
||||||
|
def self.dummy_server *args
|
||||||
|
Dir[ Pathname.new( __FILE__).dirname.join( '..', 'lib', '**').to_s].each_entry do |l|
|
||||||
|
load l if /\.rb$/ =~ l
|
||||||
|
end
|
||||||
|
serv = NSCA::Server.new *args
|
||||||
sock = serv.accept
|
sock = serv.accept
|
||||||
sock.fetch
|
sock.fetch
|
||||||
ensure
|
ensure
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TestNSCA < Test::Unit::TestCase
|
||||||
T0 = TestChecks::T0
|
T0 = TestChecks::T0
|
||||||
T1 = TestChecks::T1
|
T1 = TestChecks::T1
|
||||||
T2 = TestChecks::T2
|
T2 = TestChecks::T2
|
||||||
NSCA.destinations << NSCA::Client.new( 'localhost', 5667, 2)
|
NSCA.destinations << NSCA::Client.new( 'localhost', 5667, password: 'abcdefghijkl')
|
||||||
NSCA.send TestChecks::T0.new( 1, "0123456789"*51+"AB")
|
NSCA.send TestChecks::T0.new( 1, "0123456789"*51+"AB")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue