Class: Fluent::NscaOutput

Inherits:
BufferedOutput
  • Object
show all
Defined in:
lib/fluent/plugin/out_nsca.rb

Constant Summary collapse

MAX_HOST_NAME_BYTES =

These max bytes are specified in the pack string in send_nsca library

64
MAX_SERVICE_DESCRIPTION_BYTES =
128
MAX_PLUGIN_OUTPUT_BYTES =
512
@@valid_return_codes =
{
  0 => 0, 1 => 1, 2 => 2, 3 => 3,
  '0' => 0, '1' => 1, '2' => 2, '3' => 3,
  'OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3
}

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/fluent/plugin/out_nsca.rb', line 60

def configure(conf)
  super
  @host_name ||= Socket.gethostname
  warn_if_host_name_exceeds_max_bytes(@host_name)
  warn_if_service_description_exceeds_max_bytes(@service_description)
  warn_if_plugin_output_exceeds_max_bytes(@plugin_output)
end

#format(tag, time, record) ⇒ Object



98
99
100
# File 'lib/fluent/plugin/out_nsca.rb', line 98

def format(tag, time, record)
  [tag, time, record].to_msgpack
end

#write(chunk) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/fluent/plugin/out_nsca.rb', line 103

def write(chunk)
  results = []
  chunk.msgpack_each { |(tag, time, record)|
    nsca_check = SendNsca::NscaConnection.new({
      :nscahost => @server,
      :port => @port,
      :password => @password,
      :hostname => determine_host_name(record),
      :service => determine_service_description(tag, record),
      :return_code => determine_return_code(record),
      :status => determine_plugin_output(record)
    })
    results.push(nsca_check.send_nsca)
  }

  # Returns the results of send_nsca for tests
  return results
end