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, ReturnCode, Server

Class Method Summary collapse

Class Method Details

.crc32(msg) ⇒ Object



12
13
14
15
16
# File 'lib/nsca/packet.rb', line 12

def crc32 msg
	(msg.each_byte.inject 0xFFFFFFFF do |r,b|
		8.times.inject( r^b) {|r,_i| (r>>1) ^ (0xEDB88320 * (r&1)) }
	end) ^ 0xFFFFFFFF
end

.cstr2str(str, maxlen = nil) ⇒ Object



24
# File 'lib/nsca/packet.rb', line 24

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

.destinationsObject



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

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

.send(*results) ⇒ Object



27
28
29
30
# File 'lib/nsca.rb', line 27

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



19
20
21
22
23
# File 'lib/nsca/packet.rb', line 19

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

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



3
4
5
6
7
8
9
10
# File 'lib/nsca/packet.rb', line 3

def xor key, msg, key_a = nil
	key_a ||= key.unpack 'C*'
	l = key_a.length
	return msg  if l < 1
	# Slice the message in parts of length key_a.length.
	# XOR each char of a part with char at the same index in key_a.
	msg.unpack( 'C*').each_with_index.map {|c,i| c^key_a[i%l] }.pack 'C*'
end