Rsyslog Logging – Specify Action Parameters from Environment Variables

elasticsearchloggingrsyslog

I'm using rsyslog to send logs to elasticsearch. It all works well in my local environment, but now I'm trying to make it more generic and inject environment variables where needed.

As part of my rsyslog.conf is this omelasticsearch action:

action(
    type="omelasticsearch"
    server=<somehow use $ES_HOST here>
    template="haproxy"
    bulkmode="on"
    searchIndex="haproxy-index"
    dynSearchIndex="on"
    usehttps="on"
    asyncrepl="on"
    uid=<somehow use $ES_USER here>
    pwd=<somehow use $ES_PASSWORD here>
)

I tried using getenv() and setting variables, but I couldn't find a way to inject said variable into the parameters of my action.

Did I miss something simple, or is that just not doable?

Best Answer

Turns out you can shell out from the config file by using backticks.

action(
    type="omelasticsearch"
    server=`echo $ES_HOST`
    template="haproxy"
    bulkmode="on"
    searchIndex="haproxy-index"
    dynSearchIndex="on"
    usehttps="on"
    uid=`echo $ES_USER`
    pwd=`echo $ES_PASSWORD`
)