Rsyslog concatenate postfix output












0















I'm trying to concatenate postfix log output with rsyslog directly. This is my template.



template(name="TestMailTemplate" type="list"){
property(name="timestamp" dateFormat="rfc3339")
constant(value=" ")
property(name="hostname")
constant(value=" ")
property(name="syslogtag")
constant(value=" ")
property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" )
property(name="msg" droplastlf="on" )
constant(value="n")


Where this property property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" ) outputs the value I want if matched: e.g. 9BDCED186



I would then like to use this to match other log lines, to produce final output. From this:



2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 9BDCED186: uid=1004 from=<support@mycompany.com>
2019-01-03T17:02:00+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: from=<support@mycompany.com>, size=94699, nrcpt=1 (queue active)
2019-01-03T17:02:10+00:00 mail2 postfix/smtp[25428]: 9BDCED186 9BDCED186: to=<someone@otherdomain.com>, relay=mx4.mail.otherdomain.com[*.*.*.*]:25, delay=9.9, delays=0.13/0/6.3/3.4, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as **********)
2019-01-03T17:02:10+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: removed


To this:



2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 from=<support@mycompany.com> size=94699 to=<someone@otherdomain.com> relay... status=sent


I've done an equivalent in bash, but it's a dirty solution with lots of pipes. Is this possible with rsyslog|rainerscript? How would I declare the variable as say 9BDCED186 and clear it once the removed line has been processed?



I appreciate that this is in part a coding question, but I feel more closely aligned with rsyslog configuration.










share|improve this question





























    0















    I'm trying to concatenate postfix log output with rsyslog directly. This is my template.



    template(name="TestMailTemplate" type="list"){
    property(name="timestamp" dateFormat="rfc3339")
    constant(value=" ")
    property(name="hostname")
    constant(value=" ")
    property(name="syslogtag")
    constant(value=" ")
    property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" )
    property(name="msg" droplastlf="on" )
    constant(value="n")


    Where this property property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" ) outputs the value I want if matched: e.g. 9BDCED186



    I would then like to use this to match other log lines, to produce final output. From this:



    2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 9BDCED186: uid=1004 from=<support@mycompany.com>
    2019-01-03T17:02:00+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: from=<support@mycompany.com>, size=94699, nrcpt=1 (queue active)
    2019-01-03T17:02:10+00:00 mail2 postfix/smtp[25428]: 9BDCED186 9BDCED186: to=<someone@otherdomain.com>, relay=mx4.mail.otherdomain.com[*.*.*.*]:25, delay=9.9, delays=0.13/0/6.3/3.4, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as **********)
    2019-01-03T17:02:10+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: removed


    To this:



    2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 from=<support@mycompany.com> size=94699 to=<someone@otherdomain.com> relay... status=sent


    I've done an equivalent in bash, but it's a dirty solution with lots of pipes. Is this possible with rsyslog|rainerscript? How would I declare the variable as say 9BDCED186 and clear it once the removed line has been processed?



    I appreciate that this is in part a coding question, but I feel more closely aligned with rsyslog configuration.










    share|improve this question



























      0












      0








      0








      I'm trying to concatenate postfix log output with rsyslog directly. This is my template.



      template(name="TestMailTemplate" type="list"){
      property(name="timestamp" dateFormat="rfc3339")
      constant(value=" ")
      property(name="hostname")
      constant(value=" ")
      property(name="syslogtag")
      constant(value=" ")
      property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" )
      property(name="msg" droplastlf="on" )
      constant(value="n")


      Where this property property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" ) outputs the value I want if matched: e.g. 9BDCED186



      I would then like to use this to match other log lines, to produce final output. From this:



      2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 9BDCED186: uid=1004 from=<support@mycompany.com>
      2019-01-03T17:02:00+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: from=<support@mycompany.com>, size=94699, nrcpt=1 (queue active)
      2019-01-03T17:02:10+00:00 mail2 postfix/smtp[25428]: 9BDCED186 9BDCED186: to=<someone@otherdomain.com>, relay=mx4.mail.otherdomain.com[*.*.*.*]:25, delay=9.9, delays=0.13/0/6.3/3.4, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as **********)
      2019-01-03T17:02:10+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: removed


      To this:



      2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 from=<support@mycompany.com> size=94699 to=<someone@otherdomain.com> relay... status=sent


      I've done an equivalent in bash, but it's a dirty solution with lots of pipes. Is this possible with rsyslog|rainerscript? How would I declare the variable as say 9BDCED186 and clear it once the removed line has been processed?



      I appreciate that this is in part a coding question, but I feel more closely aligned with rsyslog configuration.










      share|improve this question
















      I'm trying to concatenate postfix log output with rsyslog directly. This is my template.



      template(name="TestMailTemplate" type="list"){
      property(name="timestamp" dateFormat="rfc3339")
      constant(value=" ")
      property(name="hostname")
      constant(value=" ")
      property(name="syslogtag")
      constant(value=" ")
      property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" )
      property(name="msg" droplastlf="on" )
      constant(value="n")


      Where this property property(name="msg" regex.expression="([A-Z0-9]{9})" regex.type="ERE" regex.match="0" ) outputs the value I want if matched: e.g. 9BDCED186



      I would then like to use this to match other log lines, to produce final output. From this:



      2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 9BDCED186: uid=1004 from=<support@mycompany.com>
      2019-01-03T17:02:00+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: from=<support@mycompany.com>, size=94699, nrcpt=1 (queue active)
      2019-01-03T17:02:10+00:00 mail2 postfix/smtp[25428]: 9BDCED186 9BDCED186: to=<someone@otherdomain.com>, relay=mx4.mail.otherdomain.com[*.*.*.*]:25, delay=9.9, delays=0.13/0/6.3/3.4, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as **********)
      2019-01-03T17:02:10+00:00 mail2 postfix/qmgr[27972]: 9BDCED186 9BDCED186: removed


      To this:



      2019-01-03T17:02:00+00:00 mail2 postfix/pickup[8786]: 9BDCED186 from=<support@mycompany.com> size=94699 to=<someone@otherdomain.com> relay... status=sent


      I've done an equivalent in bash, but it's a dirty solution with lots of pipes. Is this possible with rsyslog|rainerscript? How would I declare the variable as say 9BDCED186 and clear it once the removed line has been processed?



      I appreciate that this is in part a coding question, but I feel more closely aligned with rsyslog configuration.







      logs postfix rsyslog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 4 at 15:44









      Jeff Schaller

      39.3k1054125




      39.3k1054125










      asked Jan 4 at 15:01









      itChiitChi

      135




      135






















          0






          active

          oldest

          votes











          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%2f492498%2frsyslog-concatenate-postfix-output%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f492498%2frsyslog-concatenate-postfix-output%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

          Morgemoulin

          Scott Moir

          Souastre