Search code examples
linuxshellloggingrsyslog

Pass comand line parameters to shell script via omprog (rsyslog module)


Having bad times with passing system log message to shell script as command line parameter via rsyslog module omprog.

My /etc/rsyslog.conf:

module(load="omprog")
if $syslogtag contains 'user'
then action(type="omprog" binary="/usr/bin/test")

My /usr/bin/test:

#!/bin/sh
printf "\n$(date): $1" >> /home/user/sink

On running

logger qqq

I get 'qqq' in /var/log/messages and current timestamp in /home/user/sink.
Upon running

/usr/bin/test some_message

I get in /home/user/sink current timestamp along with 'some_message'. But as soon as I modify action string in /etc/rsyslog.conf to
either

then action(type="omprog" binary="/usr/bin/test some_message")

or

then action(type="omprog" binary="/usr/bin/test \"$msg\"")

I get logger parameter in system log, but nothing in /home/user/sink. Stuck on that issue for whole day already, any help is highly appreciated.


Solution

  • further info on action parameters not being able to be generated dynamically -- https://github.com/rsyslog/rsyslog/issues/1149

    --

    rgerhards commented on Sep 21, 2016
    
    The key problem is: what shall the action do if a parameter changes? e.g. shut
    down existing connection and create a new one? If so, shall it really do this 
    if parameters frequently change?
    
    IMHO to handle this decently, the plugin itself must handle these kinds of 
    dynamic properties and act accordingly. So there is no generic solution possible.