Search code examples
nxlog

run bash script when ERROR spotted in logs in nxlog


I am trying to run a script every time an error is found in logs

<Extension _exec>
    Module  xm_exec
</Extension>

<Input in>
    Module  im_file
    File    "/home/rafal/gitprojects/mst-sender/hub.cloudradar-error.log"
        <Exec>
        if $raw_event =~ /(\S+)\ (.+) \[ERROR (.+)/
        {
                exec_async("/bin/sh", "/home/rafal/gitprojects/mst-sender/run.sh");
        }

        </Exec>
</Input>

From their documentation it looks like it should exec async if regex matches but I am seeing only the following log WARNING not starting unused module in and the script is not executed. I don't need to output it, only run that script.

[UPDATE]added route

<Output out1>
    Module  om_null
</Output>

<Route 1>
    # Basic route
    Path    in => out1
</Route>

Solution

  • I don't need to output it, only run that script.

    You need to.
    What you can do is to create a route with om_null so that the output is discarded.