Compare Array of IPs with rsyslog












1















There is a list of IPs (their quantity is changing every few minutes) stored in a log-file. The logfile only contains unique IPs (sort -u):



IP-Pool.log [Example]:
192.168.1.1
192.168.1.2
10.1.1.0
.
.


I would like to filter occuring connection events with rsyslog and sort them by:




  • Events where $msg contains one IP of Array[IP-Pool-List]

  • Events where $msg doesn't contain any IP of Array[IP-Pool-List]


Therefore I would have to put the IPs into an array so they can be compared but I haven't found a way to do so.



if $msg contains 'connection-event-id' then {

if $msg contains 'Array[IP-Pool-List] then {
-/var/log/event_contains_ip.log
STOP
}
else{
-/var/log/event_doesnt_contain_ip.log
STOP
}

}


Would I also have to restart the rsyslogd service in order to refresh the array [IP-Pool-List], since the file is changing every few minutes ?



Is there a way to solve this with rsyslog, or is there an easier/better way to do this ?



EDIT



I used crontab and inotifywait to keep the IP-Pool-File up to date.



@reboot inotifywait -q -m -e modify /var/log/client-ips.log | 
while read -r filename events; do sort -u /var/log/client-ips.log
-o /var/log/ips-unique.log ;done


I also asked this question via mail to the "rsyslog-community" their contact mail is listed at the bottom of the rsyslog documentation (https://lists.adiscon.net/mailman/listinfo/rsyslog)
They gave me the advise to use "Lookup-Tables" to solve this. Currently reading how to use them correctly. Since I am a slow learner, this should take a while.



EDIT 2



A new plan is starting to form:




  • To get Lookup-Table going, I need to create a JSON-File, which
    contains the values I am going to build my filter with

  • Update the JSON File with "reload_lookup_table" or "JQ", whenever a new IP is added to the
    IP-Pool-List.

  • Use RSYSLOG Lookup-Table to filter for the given IPs and split the
    results into two seperate log files | Match.log | NoMatch.log


Hope it'll work this way.



Happy New Year
peacemaker










share|improve this question





























    1















    There is a list of IPs (their quantity is changing every few minutes) stored in a log-file. The logfile only contains unique IPs (sort -u):



    IP-Pool.log [Example]:
    192.168.1.1
    192.168.1.2
    10.1.1.0
    .
    .


    I would like to filter occuring connection events with rsyslog and sort them by:




    • Events where $msg contains one IP of Array[IP-Pool-List]

    • Events where $msg doesn't contain any IP of Array[IP-Pool-List]


    Therefore I would have to put the IPs into an array so they can be compared but I haven't found a way to do so.



    if $msg contains 'connection-event-id' then {

    if $msg contains 'Array[IP-Pool-List] then {
    -/var/log/event_contains_ip.log
    STOP
    }
    else{
    -/var/log/event_doesnt_contain_ip.log
    STOP
    }

    }


    Would I also have to restart the rsyslogd service in order to refresh the array [IP-Pool-List], since the file is changing every few minutes ?



    Is there a way to solve this with rsyslog, or is there an easier/better way to do this ?



    EDIT



    I used crontab and inotifywait to keep the IP-Pool-File up to date.



    @reboot inotifywait -q -m -e modify /var/log/client-ips.log | 
    while read -r filename events; do sort -u /var/log/client-ips.log
    -o /var/log/ips-unique.log ;done


    I also asked this question via mail to the "rsyslog-community" their contact mail is listed at the bottom of the rsyslog documentation (https://lists.adiscon.net/mailman/listinfo/rsyslog)
    They gave me the advise to use "Lookup-Tables" to solve this. Currently reading how to use them correctly. Since I am a slow learner, this should take a while.



    EDIT 2



    A new plan is starting to form:




    • To get Lookup-Table going, I need to create a JSON-File, which
      contains the values I am going to build my filter with

    • Update the JSON File with "reload_lookup_table" or "JQ", whenever a new IP is added to the
      IP-Pool-List.

    • Use RSYSLOG Lookup-Table to filter for the given IPs and split the
      results into two seperate log files | Match.log | NoMatch.log


    Hope it'll work this way.



    Happy New Year
    peacemaker










    share|improve this question



























      1












      1








      1








      There is a list of IPs (their quantity is changing every few minutes) stored in a log-file. The logfile only contains unique IPs (sort -u):



      IP-Pool.log [Example]:
      192.168.1.1
      192.168.1.2
      10.1.1.0
      .
      .


      I would like to filter occuring connection events with rsyslog and sort them by:




      • Events where $msg contains one IP of Array[IP-Pool-List]

      • Events where $msg doesn't contain any IP of Array[IP-Pool-List]


      Therefore I would have to put the IPs into an array so they can be compared but I haven't found a way to do so.



      if $msg contains 'connection-event-id' then {

      if $msg contains 'Array[IP-Pool-List] then {
      -/var/log/event_contains_ip.log
      STOP
      }
      else{
      -/var/log/event_doesnt_contain_ip.log
      STOP
      }

      }


      Would I also have to restart the rsyslogd service in order to refresh the array [IP-Pool-List], since the file is changing every few minutes ?



      Is there a way to solve this with rsyslog, or is there an easier/better way to do this ?



      EDIT



      I used crontab and inotifywait to keep the IP-Pool-File up to date.



      @reboot inotifywait -q -m -e modify /var/log/client-ips.log | 
      while read -r filename events; do sort -u /var/log/client-ips.log
      -o /var/log/ips-unique.log ;done


      I also asked this question via mail to the "rsyslog-community" their contact mail is listed at the bottom of the rsyslog documentation (https://lists.adiscon.net/mailman/listinfo/rsyslog)
      They gave me the advise to use "Lookup-Tables" to solve this. Currently reading how to use them correctly. Since I am a slow learner, this should take a while.



      EDIT 2



      A new plan is starting to form:




      • To get Lookup-Table going, I need to create a JSON-File, which
        contains the values I am going to build my filter with

      • Update the JSON File with "reload_lookup_table" or "JQ", whenever a new IP is added to the
        IP-Pool-List.

      • Use RSYSLOG Lookup-Table to filter for the given IPs and split the
        results into two seperate log files | Match.log | NoMatch.log


      Hope it'll work this way.



      Happy New Year
      peacemaker










      share|improve this question
















      There is a list of IPs (their quantity is changing every few minutes) stored in a log-file. The logfile only contains unique IPs (sort -u):



      IP-Pool.log [Example]:
      192.168.1.1
      192.168.1.2
      10.1.1.0
      .
      .


      I would like to filter occuring connection events with rsyslog and sort them by:




      • Events where $msg contains one IP of Array[IP-Pool-List]

      • Events where $msg doesn't contain any IP of Array[IP-Pool-List]


      Therefore I would have to put the IPs into an array so they can be compared but I haven't found a way to do so.



      if $msg contains 'connection-event-id' then {

      if $msg contains 'Array[IP-Pool-List] then {
      -/var/log/event_contains_ip.log
      STOP
      }
      else{
      -/var/log/event_doesnt_contain_ip.log
      STOP
      }

      }


      Would I also have to restart the rsyslogd service in order to refresh the array [IP-Pool-List], since the file is changing every few minutes ?



      Is there a way to solve this with rsyslog, or is there an easier/better way to do this ?



      EDIT



      I used crontab and inotifywait to keep the IP-Pool-File up to date.



      @reboot inotifywait -q -m -e modify /var/log/client-ips.log | 
      while read -r filename events; do sort -u /var/log/client-ips.log
      -o /var/log/ips-unique.log ;done


      I also asked this question via mail to the "rsyslog-community" their contact mail is listed at the bottom of the rsyslog documentation (https://lists.adiscon.net/mailman/listinfo/rsyslog)
      They gave me the advise to use "Lookup-Tables" to solve this. Currently reading how to use them correctly. Since I am a slow learner, this should take a while.



      EDIT 2



      A new plan is starting to form:




      • To get Lookup-Table going, I need to create a JSON-File, which
        contains the values I am going to build my filter with

      • Update the JSON File with "reload_lookup_table" or "JQ", whenever a new IP is added to the
        IP-Pool-List.

      • Use RSYSLOG Lookup-Table to filter for the given IPs and split the
        results into two seperate log files | Match.log | NoMatch.log


      Hope it'll work this way.



      Happy New Year
      peacemaker







      arrays json jq lookup-tables rsyslog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 7 at 11:31







      peacemaker

















      asked Jan 3 at 12:34









      peacemakerpeacemaker

      368




      368
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fstackoverflow.com%2fquestions%2f54022393%2fcompare-array-of-ips-with-rsyslog%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 Stack Overflow!


          • 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%2fstackoverflow.com%2fquestions%2f54022393%2fcompare-array-of-ips-with-rsyslog%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

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas