108.8. External Programs (xm_exec)
This module provides two procedures which make it possible to execute external scripts or programs. These two procedures are provided through this extension module in order to keep the NXLog core small. Also, without this module loaded an administrator is not able to execute arbitrary scripts.
Note
|
The im_exec and om_exec modules also provide support for running external programs, though the purpose of these is to pipe data to and read data from programs. The procedures provided by the xm_exec module do not pipe log message data, but are intended for multiple invocations (though data can be still passed to the executed script/program as command line arguments). |
108.8.1. Configuration
The xm_exec module accepts only the common module directives.
108.8.2. Procedures
The following procedures are exported by xm_exec.
exec(string command, varargs args);
-
Execute command, passing it the supplied arguments, and wait for it to terminate. The command is executed in the caller module’s context. Note that the module calling this procedure will block until the process terminates. Use the exec_async() procedure to avoid this problem. All output written to standard output and standard error by the spawned process is discarded.
108.8.3. Examples
If the $raw_event
field matches the regular expression, an email
will be sent.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<Extension exec>
Module xm_exec
</Extension>
<Input tcp>
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>
<Output file>
Module om_file
File "/var/log/messages"
</Output>
<Route tcp_to_file>
Path tcp => file
</Route>
For another example, see File Rotation Based on Size.