lausser / check_logfiles

A plugin (monitoring-plugin, not nagios-plugin, see also http://is.gd/PP1330) which scans logfiles for patterns.
https://omd.consol.de/docs/plugins/check_logfiles/
GNU General Public License v2.0
46 stars 27 forks source link

Scan log and alarm when pattern is found X in row #38

Closed Rohlik closed 6 years ago

Rohlik commented 6 years ago

It is possible to scan logfile for a pattern and alarm when it is found X in row?

For example I have this log:

2018-01-13 14:53:56.468  INFO 4607 [http-nio-6011-exec-1] --- c.m.fare.comm.resource.CoreResImpl       : Core handshake
2018-01-13 14:54:07.557  INFO 4607 [pool-2-thread-1] --- c.m.f.fs.service.TrnSendingServiceImpl   : Na core odeslano 0 transakci
2018-01-13 14:54:37.549  INFO 4607 [pool-2-thread-1] --- c.m.f.fs.service.TrnSendingServiceImpl   : Na core odeslano 0 transakci
2018-01-13 14:55:04.197  INFO 4607 [http-nio-6011-exec-3] --- c.m.fare.comm.resource.CoreResImpl       : Core handshake
2018-01-13 14:55:07.552  INFO 4607 [pool-2-thread-1] --- c.m.f.fs.service.TrnSendingServiceImpl   : Na core odeslano 0 transakci
2018-01-13 14:55:37.621  INFO 4607 [pool-2-thread-1] --- c.m.f.fs.service.TrnSendingServiceImpl   : Na core odeslano 0 transakci
2018-01-13 14:56:07.560  INFO 4607 [pool-2-thread-1] --- c.m.f.fs.service.TrnSendingServiceImpl   : Na core odeslano 0 transakci
2018-01-13 14:56:37.553  INFO 4607 [pool-2-thread-1] --- c.m.f.fs.service.TrnSendingServiceImpl   : Na core odeslano 0 transakci
2018-01-13 14:57:04.297  INFO 4607 [http-nio-6011-exec-5] --- c.m.fare.comm.resource.CoreResImpl       : Core handshake

and I want critical state occur only if pattern Na core odeslano 0 transakci is found 4 or more in a row.

Thx for your time.

lausser commented 6 years ago

Only when you add some own code:

my $counter = 0;

@searches = ({
...
   criticalpatterns => ["Core handshake", "Na core odeslano 0"],
   options => "supersmartscript",
   script => sub {
      # every time a criticalpattern matches, we land here
     my $line = $ENV{CHECK_LOGFILES_SERVICEOUTPUT};
      if ($line =~ /handshake/) {
         counter = 0;
         return 0;
      } elsif ($line =~ /transakci/) {
        if ($counter >= 4) {
          $counter = 0;
          print "4 times in a row Na core odeslano 0 transakci";
          return 2;
        } else {
          $counter++;
          return 0;   # only increase the counter. occurrence 1, 2, 3 have no effect else
        }
      }     else {
         # if you have more than just these two types of text, then you must write 
         # criticalpatterns => [".*"]
        return 0; # forget this line
      }
   },
Rohlik commented 6 years ago

Thx so much