Class: Fluent::NscaOutput

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

Overview

Fluentd output plugin to send service checks to an NSCA / Nagios monitoring servers.

Constant Summary collapse

MAX_HOST_NAME_BYTES =

The maximum bytes for host names.

64
MAX_SERVICE_DESCRIPTION_BYTES =

The maximum bytes for service descriptions.

128
MAX_PLUGIN_OUTPUT_BYTES =

The maximum bytes for plugin outputs.

512
OK =

OK return code (0).

0
WARNING =

WARNING return code (1).

1
CRITICAL =

CRITICAL return code (2).

2
UNKNOWN =

UNKNOWN return code (3).

3
VALID_RETURN_CODES =

Mapping from the permitted return code representations to the normalized return codes.

{
  # OK
  OK => OK, OK.to_s => OK, 'OK' => OK,

  # WARNING
  WARNING => WARNING, WARNING.to_s => WARNING, 'WARNING' => WARNING,

  # CRITICAL
  CRITICAL => CRITICAL, CRITICAL.to_s => CRITICAL, 'CRITICAL' => CRITICAL,

  # UNKNOWN
  UNKNOWN => UNKNOWN, UNKNOWN.to_s => UNKNOWN, 'UNKNOWN' => UNKNOWN
}

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/fluent/plugin/out_nsca.rb', line 105

def configure(conf)
  super
  @host_name ||= Socket.gethostname
  reject_host_name_option_exceeding_max_bytes
  reject_service_description_option_exceeding_max_bytes
  reject_plugin_output_option_exceeding_max_bytes
end

#format(tag, time, record) ⇒ Object



143
144
145
# File 'lib/fluent/plugin/out_nsca.rb', line 143

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

#write(chunk) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/fluent/plugin/out_nsca.rb', line 149

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