How to set and use constants in rsyslog (RainerScript)?












1















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.










share|improve this question



























    1















    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.










    share|improve this question

























      1












      1








      1


      1






      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.










      share|improve this question














      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.







      rsyslog






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 22 '18 at 14:21









      PerlDuckPerlDuck

      1237




      1237






















          1 Answer
          1






          active

          oldest

          votes


















          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.






          share|improve this answer

























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f439286%2fhow-to-set-and-use-constants-in-rsyslog-rainerscript%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            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.






            share|improve this answer






























              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.






              share|improve this answer




























                4












                4








                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.






                share|improve this answer















                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.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 5 mins ago









                Pang

                11715




                11715










                answered Apr 24 '18 at 11:06









                Rainer GerhardsRainer Gerhards

                762




                762






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f439286%2fhow-to-set-and-use-constants-in-rsyslog-rainerscript%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Loup dans la culture

                    How to solve the problem of ntp “Unable to contact time server” from KDE?

                    ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux