Module: NSCA

Defined in:
lib/nsca.rb,
lib/nsca/check.rb,
lib/nsca/client.rb,
lib/nsca/packet.rb,
lib/nsca/server.rb

Defined Under Namespace

Modules: Check, Checks, Helper, PerformanceData Classes: Client, Packet, PacketV3, PacketV3__2_9, ReturnCode, Server

Class Method Summary collapse

Class Method Details

.crc32(msg) ⇒ Object



65
66
67
# File 'lib/nsca.rb', line 65

def crc32 msg
	NSCA::Helper.crc32_stream[ msg]
end

.cstr2str(str, maxlen = nil) ⇒ Object



82
# File 'lib/nsca.rb', line 82

def cstr2str( str, maxlen = nil)  str[ 0, str.index( ?\0) || ((maxlen||str.length+1)-1)]  end

.destinationsObject



54
# File 'lib/nsca.rb', line 54

def destinations()  @destinations ||= []  end

.nstr2str(str, maxlen = nil) ⇒ Object



83
# File 'lib/nsca.rb', line 83

def nstr2str( str, maxlen = nil)  str[ 0, str.index( ' ') || ((maxlen||str.length+1)-1)].gsub( "\x00", ' ')  end

.rand_padding(str, maxlen) ⇒ Object



75
# File 'lib/nsca.rb', line 75

def rand_padding( str, maxlen) str + SecureRandom.random_bytes( maxlen - str.length) end

.send(*results) ⇒ Object



56
57
58
59
# File 'lib/nsca.rb', line 56

def send *results
	NSCA.destinations.each {|server| server.send *results }
	self
end

.str2cstr(str, maxlen = nil) ⇒ Object

Builds a null terminated, null padded string of length maxlen



70
71
72
73
74
# File 'lib/nsca.rb', line 70

def str2cstr str, maxlen = nil
	str = str.to_s
	str = str.to_s[0..(maxlen-2)]  if maxlen
	"#{str}\x00"
end

.str2cstr_rand_padding(str, maxlen = nil) ⇒ Object



76
# File 'lib/nsca.rb', line 76

def str2cstr_rand_padding( str, maxlen = nil) rand_padding str2cstr( str, maxlen), maxlen end

.str2nstr(str, maxlen = nil) ⇒ Object



77
78
79
80
# File 'lib/nsca.rb', line 77

def str2nstr str, maxlen = nil
	str = str.to_s.gsub ' ', "\x00"
	"#{str} "
end

.str2nstr_rand_padding(str, maxlen = nil) ⇒ Object



81
# File 'lib/nsca.rb', line 81

def str2nstr_rand_padding( str, maxlen = nil) rand_padding str2nstr( str, maxlen), maxlen end

.xor(key, msg = nil, key_a = nil) ⇒ Object



61
62
63
# File 'lib/nsca.rb', line 61

def xor key, msg = nil, key_a = nil
	NSCA::Helper.xor_stream( key_a || key)[ msg]
end