class NSCA::PacketV3
Constants
- END_OF_TRANSMISSION
- HOSTNAME_LENGTH
- NAGIOS_VERSION
- PACKET_VERSION
- PACK_LENGTH
- PACK_STRING
these line describes the data package: typedef struct data_packet_struct{
int16_t packet_version; /* two padding bytes (because aligning): xx */ u_int32_t crc32_value; u_int32_t timestamp; int16_t return_code; char host_name[MAX_HOSTNAME_LENGTH]; char svc_description[MAX_DESCRIPTION_LENGTH]; char plugin_output[MAX_PLUGINOUTPUT_LENGTH]; /* two extra padding-xx, too. */
}data_packet;
- PLUGIN_OUTPUT_LENGTH
- SERVICE_LENGTH
Public Class Methods
parse(entry, no_verification_checks = nil)
click to toggle source
# File lib/nsca/packet.rb, line 73 def self.parse entry, no_verification_checks = nil entry = entry.to_s.dup ver, crc32sum, *x = entry.unpack( PACK_STRING) x[2] = NSCA::cstr2str x[2] x[3] = NSCA::cstr2str x[3] x[4] = NSCA::cstr2str x[4] raise VersionCheckFailed, "Packet version 3 expected. (recv: #{ver})" \ unless no_verification_checks or 3 == ver entry[4..7] = ?\x00*4 crc32 = NSCA::crc32 entry raise CSC32CheckFailed, "crc32-check failed. packet seems to be broken: #{crc32sum.inspect} != #{crc32.inspect}" \ unless no_verification_checks or crc32sum == crc32 new *x end
Public Instance Methods
build(slf = nil)
click to toggle source
Builds a check-result-line for NSCA
.
Will be terminated by end-of-terminate.
# File lib/nsca/packet.rb, line 56 def build slf = nil cl = (slf || self).class entry = [ cl::PACKET_VERSION, 0, # crc32 (unknown yet) (timestamp || Time.now).to_i, return_code.to_i, NSCA::str2cstr_rand_padding( hostname || `hostname -f`, cl::HOSTNAME_LENGTH), NSCA::str2cstr_rand_padding( service, cl::SERVICE_LENGTH), NSCA::str2cstr_rand_padding( status, cl::PLUGIN_OUTPUT_LENGTH) # incl perfdata ] # generate crc32 and put it at entry[2...6] entry[1] = NSCA::crc32 entry.pack( cl::PACK_STRING) entry = entry.pack cl::PACK_STRING entry end