Ruby (im_ruby)
This module provides support for collecting log data with methods written in the Ruby language. See also the xm_ruby and om_ruby modules.
To examine the supported platforms, see the list of installation packages. |
This module provides the following classes and methods.
- Nxlog.log_debug(msg)
-
Send the message msg to the internal logger at DEBUG log level. This method does the same as the core log_debug() procedure.
- Nxlog.log_info(msg)
-
Send the message msg to the internal logger at INFO log level. This method does the same as the core log_info() procedure.
- Nxlog.log_warning(msg)
-
Send the message msg to the internal logger at WARNING log level. This method does the same as the core log_warning() procedure.
- Nxlog.log_error(msg)
-
Send the message msg to the internal logger at ERROR log level. This method does the same as the core log_error() procedure.
- class Nxlog.LogData
-
This class represents an event.
- field_names()
-
This method returns an array with the names of all the fields currently in the event record.
- get_field(name)
-
This method returns the value of the field name in the event.
- post()
-
This method will submit the LogData event to NXLog Agent for processing by the next module in the route.
- set_field(name, value)
-
This method sets the value of field name to value.
Configuration
The im_ruby module accepts the following directives in addition to the common module directives. The RubyCode directive is required.
Required directives
The following directives are required for the module to start.
This mandatory directive specifies a file containing Ruby code. The im_ruby instance will call the method specified by the Call directive. The method must accept an Nxlog.Module object as its only argument. |
Examples
In this example, events are generated by a simple Ruby method that increments a counter.
Because this Ruby method does not set the $raw_event
field, it would be reasonable to use to_json() or some other way to preserve the fields for further processing.
<Input in>
Module im_ruby
RubyCode ./modules/input/ruby/input2.rb
Call read_data
</Input>
$index = 0
def read_data(mod)
Nxlog.log_debug('Creating new event via input.rb')
$index += 1
event = mod.logdata_new
event.set_field('Counter', $index)
event.set_field('Message', "This is message #{$index}")
event.post
mod.set_read_timer 0.3
end