rsyslog conditional forwarding for remote logs












2















I have a rsyslog Server which have the below settings,Where its getting all the remote Linux systems logs and network logs.



# cat /etc/rsyslog.conf 
$ModLoad imudp
$UDPServerRun 514
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$template noida-dc, "/scratch/rsyslog/%HOSTNAME%/messages.log"
authpriv.* ?noida-dc
*.info,mail.none,authpriv.none,cron.none ?noida-dc
$IncludeConfig /etc/rsyslog.d/*.conf


Whereas Linux system logs are log as they are storing into /scratch/rsyslog with their hostames by creating a directory with hostnames itself and then creating a message file within it, that's fine.



However, i want to segregate the network logs which basically creates a Folder by Month names like Jan Feb Mar and then creates a message.log as well but as network logs do not have hostnames it Just creating a dir based on the moth name and keeping the only one file into it thats messages.log, my wish is to have these network logs to a different Directory like /scratch/network .



Below is message format within the network log directory Dec



Dec  2 19:04:22 Dec 02 13:34:22.768 cisco-apic-1 %LOG_-3-SYSTEM_MSG


So, Is there a way to tell rsyslog if remote message contains Dec or Jan then must go to /scratch/network.



What i tried as Follows but not working.



$template mynets,"/scratch/network/%HOSTNAME%/messages.log"
if $fromhost contains 'cisco-apic-1' then -?mynets
& stop


&



$template mynets,"/scratch/network/%HOSTNAME%/messages.log"
if $fromhost startswith 'Dec' then -?mynets
& stop


Linux Distro is : Centos 6










share|improve this question





























    2















    I have a rsyslog Server which have the below settings,Where its getting all the remote Linux systems logs and network logs.



    # cat /etc/rsyslog.conf 
    $ModLoad imudp
    $UDPServerRun 514
    $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
    $template noida-dc, "/scratch/rsyslog/%HOSTNAME%/messages.log"
    authpriv.* ?noida-dc
    *.info,mail.none,authpriv.none,cron.none ?noida-dc
    $IncludeConfig /etc/rsyslog.d/*.conf


    Whereas Linux system logs are log as they are storing into /scratch/rsyslog with their hostames by creating a directory with hostnames itself and then creating a message file within it, that's fine.



    However, i want to segregate the network logs which basically creates a Folder by Month names like Jan Feb Mar and then creates a message.log as well but as network logs do not have hostnames it Just creating a dir based on the moth name and keeping the only one file into it thats messages.log, my wish is to have these network logs to a different Directory like /scratch/network .



    Below is message format within the network log directory Dec



    Dec  2 19:04:22 Dec 02 13:34:22.768 cisco-apic-1 %LOG_-3-SYSTEM_MSG


    So, Is there a way to tell rsyslog if remote message contains Dec or Jan then must go to /scratch/network.



    What i tried as Follows but not working.



    $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
    if $fromhost contains 'cisco-apic-1' then -?mynets
    & stop


    &



    $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
    if $fromhost startswith 'Dec' then -?mynets
    & stop


    Linux Distro is : Centos 6










    share|improve this question



























      2












      2








      2








      I have a rsyslog Server which have the below settings,Where its getting all the remote Linux systems logs and network logs.



      # cat /etc/rsyslog.conf 
      $ModLoad imudp
      $UDPServerRun 514
      $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
      $template noida-dc, "/scratch/rsyslog/%HOSTNAME%/messages.log"
      authpriv.* ?noida-dc
      *.info,mail.none,authpriv.none,cron.none ?noida-dc
      $IncludeConfig /etc/rsyslog.d/*.conf


      Whereas Linux system logs are log as they are storing into /scratch/rsyslog with their hostames by creating a directory with hostnames itself and then creating a message file within it, that's fine.



      However, i want to segregate the network logs which basically creates a Folder by Month names like Jan Feb Mar and then creates a message.log as well but as network logs do not have hostnames it Just creating a dir based on the moth name and keeping the only one file into it thats messages.log, my wish is to have these network logs to a different Directory like /scratch/network .



      Below is message format within the network log directory Dec



      Dec  2 19:04:22 Dec 02 13:34:22.768 cisco-apic-1 %LOG_-3-SYSTEM_MSG


      So, Is there a way to tell rsyslog if remote message contains Dec or Jan then must go to /scratch/network.



      What i tried as Follows but not working.



      $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
      if $fromhost contains 'cisco-apic-1' then -?mynets
      & stop


      &



      $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
      if $fromhost startswith 'Dec' then -?mynets
      & stop


      Linux Distro is : Centos 6










      share|improve this question
















      I have a rsyslog Server which have the below settings,Where its getting all the remote Linux systems logs and network logs.



      # cat /etc/rsyslog.conf 
      $ModLoad imudp
      $UDPServerRun 514
      $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
      $template noida-dc, "/scratch/rsyslog/%HOSTNAME%/messages.log"
      authpriv.* ?noida-dc
      *.info,mail.none,authpriv.none,cron.none ?noida-dc
      $IncludeConfig /etc/rsyslog.d/*.conf


      Whereas Linux system logs are log as they are storing into /scratch/rsyslog with their hostames by creating a directory with hostnames itself and then creating a message file within it, that's fine.



      However, i want to segregate the network logs which basically creates a Folder by Month names like Jan Feb Mar and then creates a message.log as well but as network logs do not have hostnames it Just creating a dir based on the moth name and keeping the only one file into it thats messages.log, my wish is to have these network logs to a different Directory like /scratch/network .



      Below is message format within the network log directory Dec



      Dec  2 19:04:22 Dec 02 13:34:22.768 cisco-apic-1 %LOG_-3-SYSTEM_MSG


      So, Is there a way to tell rsyslog if remote message contains Dec or Jan then must go to /scratch/network.



      What i tried as Follows but not working.



      $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
      if $fromhost contains 'cisco-apic-1' then -?mynets
      & stop


      &



      $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
      if $fromhost startswith 'Dec' then -?mynets
      & stop


      Linux Distro is : Centos 6







      rsyslog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 19 '18 at 8:27









      Rui F Ribeiro

      39.5k1479132




      39.5k1479132










      asked Dec 19 '18 at 7:24









      pygopygo

      696




      696






















          1 Answer
          1






          active

          oldest

          votes


















          1














          I admit I do not fully understand what your intent is. Nevertheless, I may have a solution.



          First of all, "Dec", "Jan", ... usually stem back to the syslog header if and only if it is traditional RFC3164 syslog. With newer systems you do not have that indication. Also, many systems violate the syslog standard and you may also not find these strings inside the message.



          Assuming they are present, and further assuming they are in the syslog header: then they are NOT part of $msg or $fromhost. To make it smooth and easy, you can simply check $rawmsg, which is the message as it was seen on the wire. This is in unparsed form, and it is an inferior way to handle such things, but the good thing is it works without understanding the full theory.



          So you could say:



          $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
          if $rawmsg contains 'Dec ' then -?mynets
          & stop


          Note that I added at least a a space after 'Dec' because otherwise it would match anything containing that string (e.g. 'Decimal').



          This probably works, but it depends on a number of things that you should not take for granted. A much better way is e.g. to check if $fromhost-ip is different from the local host. Or, even better, creating a dedicated ruleset for remote logs. But that's not up to the original questions, so let's leave that out.






          share|improve this answer
























          • @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

            – pygo
            Jan 11 at 8:23











          • $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

            – pygo
            Jan 11 at 15:35













          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%2f489846%2frsyslog-conditional-forwarding-for-remote-logs%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









          1














          I admit I do not fully understand what your intent is. Nevertheless, I may have a solution.



          First of all, "Dec", "Jan", ... usually stem back to the syslog header if and only if it is traditional RFC3164 syslog. With newer systems you do not have that indication. Also, many systems violate the syslog standard and you may also not find these strings inside the message.



          Assuming they are present, and further assuming they are in the syslog header: then they are NOT part of $msg or $fromhost. To make it smooth and easy, you can simply check $rawmsg, which is the message as it was seen on the wire. This is in unparsed form, and it is an inferior way to handle such things, but the good thing is it works without understanding the full theory.



          So you could say:



          $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
          if $rawmsg contains 'Dec ' then -?mynets
          & stop


          Note that I added at least a a space after 'Dec' because otherwise it would match anything containing that string (e.g. 'Decimal').



          This probably works, but it depends on a number of things that you should not take for granted. A much better way is e.g. to check if $fromhost-ip is different from the local host. Or, even better, creating a dedicated ruleset for remote logs. But that's not up to the original questions, so let's leave that out.






          share|improve this answer
























          • @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

            – pygo
            Jan 11 at 8:23











          • $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

            – pygo
            Jan 11 at 15:35


















          1














          I admit I do not fully understand what your intent is. Nevertheless, I may have a solution.



          First of all, "Dec", "Jan", ... usually stem back to the syslog header if and only if it is traditional RFC3164 syslog. With newer systems you do not have that indication. Also, many systems violate the syslog standard and you may also not find these strings inside the message.



          Assuming they are present, and further assuming they are in the syslog header: then they are NOT part of $msg or $fromhost. To make it smooth and easy, you can simply check $rawmsg, which is the message as it was seen on the wire. This is in unparsed form, and it is an inferior way to handle such things, but the good thing is it works without understanding the full theory.



          So you could say:



          $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
          if $rawmsg contains 'Dec ' then -?mynets
          & stop


          Note that I added at least a a space after 'Dec' because otherwise it would match anything containing that string (e.g. 'Decimal').



          This probably works, but it depends on a number of things that you should not take for granted. A much better way is e.g. to check if $fromhost-ip is different from the local host. Or, even better, creating a dedicated ruleset for remote logs. But that's not up to the original questions, so let's leave that out.






          share|improve this answer
























          • @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

            – pygo
            Jan 11 at 8:23











          • $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

            – pygo
            Jan 11 at 15:35
















          1












          1








          1







          I admit I do not fully understand what your intent is. Nevertheless, I may have a solution.



          First of all, "Dec", "Jan", ... usually stem back to the syslog header if and only if it is traditional RFC3164 syslog. With newer systems you do not have that indication. Also, many systems violate the syslog standard and you may also not find these strings inside the message.



          Assuming they are present, and further assuming they are in the syslog header: then they are NOT part of $msg or $fromhost. To make it smooth and easy, you can simply check $rawmsg, which is the message as it was seen on the wire. This is in unparsed form, and it is an inferior way to handle such things, but the good thing is it works without understanding the full theory.



          So you could say:



          $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
          if $rawmsg contains 'Dec ' then -?mynets
          & stop


          Note that I added at least a a space after 'Dec' because otherwise it would match anything containing that string (e.g. 'Decimal').



          This probably works, but it depends on a number of things that you should not take for granted. A much better way is e.g. to check if $fromhost-ip is different from the local host. Or, even better, creating a dedicated ruleset for remote logs. But that's not up to the original questions, so let's leave that out.






          share|improve this answer













          I admit I do not fully understand what your intent is. Nevertheless, I may have a solution.



          First of all, "Dec", "Jan", ... usually stem back to the syslog header if and only if it is traditional RFC3164 syslog. With newer systems you do not have that indication. Also, many systems violate the syslog standard and you may also not find these strings inside the message.



          Assuming they are present, and further assuming they are in the syslog header: then they are NOT part of $msg or $fromhost. To make it smooth and easy, you can simply check $rawmsg, which is the message as it was seen on the wire. This is in unparsed form, and it is an inferior way to handle such things, but the good thing is it works without understanding the full theory.



          So you could say:



          $template mynets,"/scratch/network/%HOSTNAME%/messages.log"
          if $rawmsg contains 'Dec ' then -?mynets
          & stop


          Note that I added at least a a space after 'Dec' because otherwise it would match anything containing that string (e.g. 'Decimal').



          This probably works, but it depends on a number of things that you should not take for granted. A much better way is e.g. to check if $fromhost-ip is different from the local host. Or, even better, creating a dedicated ruleset for remote logs. But that's not up to the original questions, so let's leave that out.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 11 at 7:58









          Rainer GerhardsRainer Gerhards

          762




          762













          • @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

            – pygo
            Jan 11 at 8:23











          • $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

            – pygo
            Jan 11 at 15:35





















          • @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

            – pygo
            Jan 11 at 8:23











          • $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

            – pygo
            Jan 11 at 15:35



















          @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

          – pygo
          Jan 11 at 8:23





          @ Rainer, I'm elated to have your response and explanation on the post, i'll check the things you mentioned and will revert for your expertise in case requires. Thx a mile.

          – pygo
          Jan 11 at 8:23













          $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

          – pygo
          Jan 11 at 15:35







          $rawmsg would be good one use , i'm afraid if there is way i can define the moth names in a variable like ['Dec ', 'Jan ', 'Feb ', 'March ' ] So, if $rawmsg have anything from these names those can be forwarded to the mynets .

          – pygo
          Jan 11 at 15:35




















          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%2f489846%2frsyslog-conditional-forwarding-for-remote-logs%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

          How to make a Squid Proxy server?

          第一次世界大戦

          Touch on Surface Book