2

I'm writing an application which includes an rsyslog configuration which gets placed in /etc/rsyslog.d/.

Certain logmessages should be redirected to a named pipe, like so:

template (name="my_fmt" type="string" string="<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag% %msg%\n")
if ( ... ) then {
    action(type="ompipe" Pipe="/tmp/SITENAME/pipe" Template="my_fmt")
    stop
}

This works as intended. Unfortunately, the SITENAME in the above pipe's name is not known in advance and must be configured by the customer.

I could write instructions like "find any occurence of the word SITENAME in the file and replace it with your particular $sitename" or even deliver an sed command, but I don't like that approach. Instead, I'd like to set a constant at the beginning of the file and use it wherever need is. Like so:

set ACTUAL_SITE = "foo";

template (name="my_fmt" type="string" string="<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag% %msg%\n")
if ( ... ) then {
    action(type="ompipe" Pipe="/tmp/$ACTUAL_SITE/pipe" Template="my_fmt")
    stop
}

How can I do this? I (think I) tried all variants of $, %…% and %$…% in the Pipe="…" part but none worked. The value of ACTUAL_SITE never changes after initial installation. I just want to simplify the configuration for the customer and say "set the value of ACTUAL_SITE to your actual site's name" and not make him fiddling around with the rest of the file.

4

Outdated rsyslog versions (8.32 and lower) do not support what you try to do.

In current rsyslog versions, you can do this via backticks constants, see here.

To do so:

  • define an environment variable (or write a file) before rsyslog startup, usually by adding it to the startup script upon install on the target machine. Let's call this SITE_PIPE and do as follows:

    export SITEPIPE="/tmp/mysite/pipe"
    
  • then, use backticks as such:

    action(type="ompipe" Pipe=`echo $SITEPIPE` Template="my_fmt")
    

If you write a file, you can use this construct:

action(type="ompipe" Pipe=`cat pipenamefile` Template="my_fmt")

All of this should look familiar to how bash works.

An actual sample of this in action can be found inside our docker container. This here links to the container's rsyslog.conf.

But you can also look at the rest of the Docker definitions to get the whole picture.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.