tested against nsca-2.7 (client and server) (iv_key and password)

This commit is contained in:
Denis Knauf 2013-04-08 20:18:21 +02:00
parent 476d58d7ec
commit bdb441f237
6 changed files with 36 additions and 19 deletions

View file

@ -31,7 +31,7 @@ module NSCA
end
end
require 'lib/packet'
require 'lib/server'
require 'lib/client'
require 'lib/check'
require 'nsca/packet'
require 'nsca/server'
require 'nsca/client'
require 'nsca/check'

View file

@ -153,6 +153,21 @@ module NSCA
def unknown( status = nil, perfdatas = nil) new.unknown status, perfdatas 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
module Checks

View file

@ -67,7 +67,7 @@ module NSCA
# @param [String(length<512)] status Status-line inclusive optional Performance Data.
def build_packet 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
# Sends a check-result.
@ -78,7 +78,7 @@ module NSCA
# @param [Array<NSCA::Check::Base>] results
def send *results
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
@ -86,15 +86,12 @@ module NSCA
def close( *a) @socket.close( *a) end
end
attr_reader :socket_or_host, :port, :password
def initialize socket_or_host = nil, port = nil, password = nil, &connect
@socket_or_host, @port, @password = socket_or_host, port, password
end
def open &e
Connection.open @socket_or_host, @port, @password, &e
attr_reader :hostname, :port, :password
def initialize hostname = nil, port = nil, password = nil
@hostname, @port, @password = hostname, port, password
end
def open( &e) Connection.open @hostname, @port, @password, &e end
def send( *results) open {|conn| conn.send results } end
end
end

View file

@ -48,7 +48,8 @@ module NSCA
end
def fetch
@packet_version.parse read, @iv_key, @password
data = read
@packet_version.parse data, @iv_key, @password if data
end
def eof?() @socket.eof? end

View file

@ -1,8 +1,12 @@
require 'pathname'
$: << Pathname.new( __FILE__).dirname.join( '..', 'lib').to_s
module NSCA
def self.dummy_server port, password = nil, key = nil
require 'pathname'
load Pathname.new( __FILE__).dirname.join( '..', 'lib', 'nsca.rb').to_s
serv = NSCA::Server.new port, password: password, key: key
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.fetch
ensure

View file

@ -19,7 +19,7 @@ class TestNSCA < Test::Unit::TestCase
T0 = TestChecks::T0
T1 = TestChecks::T1
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")
return