- Introduction
- Deployment
- Configuration
- OS Support
- Integration
- Troubleshooting
- Enterprise Edition Reference Manual
- 127. Man Pages
- 128. Configuration
- 129. Language
- 130. Extension Modules
- 131. Input Modules
- 132. Processor Modules
- 133. Output Modules
- 133.1. Batched Compression (om_batchcompress)
- 133.2. Blocker (om_blocker)
- 133.3. DBI (om_dbi)
- 133.4. Elasticsearch (om_elasticsearch)
- 133.5. EventDB (om_eventdb)
- 133.6. Program (om_exec)
- 133.7. Files (om_file)
- 133.8. Go (om_go)
- 133.9. HTTP(s) (om_http)
- 133.10. Java (om_java)
- 133.11. Kafka (om_kafka)
- 133.12. Null (om_null)
- 133.13. ODBC (om_odbc)
- 133.14. Perl (om_perl)
- 133.15. Named Pipes (om_pipe)
- 133.16. Python (om_python)
- 133.17. Raijin (om_raijin)
- 133.18. Redis (om_redis)
- 133.19. Ruby (om_ruby)
- 133.20. TLS/SSL (om_ssl)
- 133.21. TCP (om_tcp)
- 133.22. UDP (om_udp)
- 133.23. UDP with IP Spoofing (om_udpspoof)
- 133.24. Unix Domain Sockets (om_uds)
- 133.25. WebHDFS (om_webhdfs)
- 133.26. ZeroMQ (om_zmq)
- NXLog Manager
- NXLog Add-Ons
133.19. Ruby (om_ruby)
This module provides support for forwarding log data with methods written in the Ruby language. See also the xm_ruby and im_ruby modules.
Note
|
To examine the supported platforms, see the list of installer packages in the Available Modules chapter. |
The Nxlog
module provides the following classes and methods.
- Nxlog.log_info(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_debug(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. It is instantiated by NXLog and passed to the method specified by the Call directive.
- 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.
- set_field(name, value)
-
This method sets the value of field name to value.
133.19.1. Configuration
The om_ruby module accepts the following directives in addition to the common module directives. The RubyCode directive is required.
- RubyCode
-
This mandatory directive specifies a file containing Ruby code. The om_ruby instance will call the method specified by the Call directive. The method must accept an Nxlog.LogData object as its only argument.
- Call
-
This optional directive specifies the Ruby method to call. The default is
write_data
.
133.19.2. Examples
This example uses a Ruby script to choose an output file according to the severity of the event. Normalized severity fields are added by most modules; see, for example, the xm_syslog $SeverityValue field.
Tip
|
See Using Dynamic Filenames for a way to implement this functionality natively. |
1
2
3
4
5
<Output out>
Module om_ruby
RubyCode ./modules/output/ruby/proc2.rb
Call write_data
</Output>
def write_data event
if event.get_field('SeverityValue') >= 4
Nxlog.log_debug('Writing out high severity event')
File.open('tmp/high_severity', 'a') do |file|
file.write("#{event.get_field('raw_event')}\n")
file.flush
end
else
Nxlog.log_debug('Writing out low severity event')
File.open('tmp/low_severity', 'a') do |file|
file.write("#{event.get_field('raw_event')}\n")
file.flush
end
end
end