Program (om_exec)
This module will execute a program or script on startup and write (pipe) log data to its standard input.
Unless OutputType is set to something else, only the contents of the $raw_event
field are sent over the pipe.
The execution of the program or script will terminate when the module is stopped, which usually happens when NXLog exits and the pipe is closed.
To examine the supported platforms, see the list of installer packages in the Available Modules chapter. |
The program or script is started when NXLog starts and must not exit until the module is stopped. To invoke a program or script for each log message, use xm_exec instead. |
Configuration
The om_exec module accepts the following directives in addition to the common module directives. The Command directive is required.
- Command
-
This mandatory directive specifies the name of the program or script to be executed.
Programs, scripts, and commands are executed under the context of the user running NXLog. When NXLog is running as a service, the service user will be used. If the program, script, or command accesses environment variables, make sure that these are available for the NXLog user.
- Restart
-
Restart the process if it exits. There is a one second delay before it is restarted to avoid a denial-of-service when a process is not behaving. Looping should be implemented in the script itself. This directive is only to provide some safety against malfunctioning scripts and programs. This boolean directive defaults to FALSE: the Command will not be restarted if it exits.
Examples
This configuration reads logs from a file and writes the log lines to the standard input of an application. The Command directive specifies the path to the application executable and the Arg directive specifies an application argument.
<Input log_file>
Module im_file
File '/path/to/log/file'
</Input>
<Output myapp>
Module om_exec
Command /path/to/myapp
# On Windows the path to the application executable
# should include the file extension.
#Command C:\Program Files\MyApp\myapp.exe
Arg --level=info
</Output>
This configuration reads logs from a file and writes the log lines to the
standard output using the Linux
cat command-line tool.
The Command directive specifies the
path to the Linux system shell. The first Arg directive
passes the -c
argument to the shell and the second Arg directive specifies
the command to execute.
<Input log_file>
Module im_file
File '/path/to/log/file'
</Input>
<Output stdout>
Module om_exec
Command /bin/sh
Arg -c
Arg cat $1
</Output>
This configuration reads logs from a file and pipes the log lines to a Python script. The Command directive specifies the path to the Python executable and the Arg directive specifies the path to the script.
<Input log_file>
Module im_file
File '/path/to/log/file'
</Input>
<Output python_script>
Module om_exec
Command C:\Python39\python.exe
Arg C:\Scripts\myscript.py
</Output>
To execute commands under a specific shell, the Command directive should specify the path to the shell executable. The commands to execute can be passed as arguments according to the shell being used. The configuration below executes PowerShell commands from a file.
<Input log_file>
Module im_file
File '/path/to/log/file'
</Input>
<Output powershell_script>
Module om_exec
Command C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arg C:\Scripts\myscript.ps1
</Output>