Alerting
NXLog can be configured to generate alerts when specific conditions are met. Here are some ways alerting could be implemented.
Sending messages to an external program
The om_exec module can pipe messages to an external program or script, which will be executed once the om_exec module has started. The external script is required to run continuously until the om_exec module is stopped and the pipe is closed. This functionality can be used for alerting.
In this example Output, all messages not matching the regular expression are dropped, and remaining messages are piped to a custom alerter
script.
<Output out>
Module om_exec
Command /usr/bin/someprog
Arg -
</Output>
See also Sending to Executables.
Invoking a program for each message
The xm_exec module provides two procedures, exec() and exec_async(), for spawning an external program or script. The script is executed once for each call, and is expected to terminate when it has finished processing the message.
In this example Input, each message matching the regular expression is piped to a new instance of alerter
, which is executed asynchronously (does not block additional processing by the calling module).
<Extension _exec>
Module xm_exec
</Extension>
<Input in>
Module im_tcp
Host 0.0.0.0
Port 1514
<Exec>
if $raw_event =~ /alertcondition/
exec_async("/usr/local/sbin/alerter");
</Exec>
</Input>
In this example, an email is sent using exec_async() when the regular expression condition is met.
<Extension _exec>
Module xm_exec
</Extension>
<Input in>
Module im_tcp
Host 0.0.0.0
Port 1514
<Exec>
if $raw_event =~ /alertcondition/
{
exec_async("/bin/sh", "-c", 'echo "' + $Hostname + '\n\nRawEvent:\n' +
$raw_event + '"|/usr/bin/mail ' +
'-a "Content-Type: text/plain; charset=UTF-8" ' +
'-s "ALERT" user@domain.com');
}
</Exec>
</Input>
Generate an internal NXLog log message
NXLog can be configured to generate an internal log event when a specific condition is met. Internal log events can be generated with various severity levels using the log_error(), log_warning(), log_info(), and log_debug() procedures. Internal log messages will be written to the file specified by the global LogFile directive (according to the configured LogLevel) and will be generated by the im_internal module.
DEBUG level events are not generated by the im_internal module. |
In NXLog Enterprise Edition version 5, the log_info() procedure will truncate messages larger than 1024 bytes.
In subsequent versions, messages longer than specified at LogSizeLimit will be truncated.
|
If a message matches the regular expression, an internal log event is generated with level WARNING.
<Input in>
Module im_file
File "/var/log/app.log"
Exec if $raw_event =~ /alertcondition/ log_warning("ALERT");
</Input>