Giter Club home page Giter Club logo

Comments (7)

lausser avatar lausser commented on August 19, 2024
criticalpatterns => {
   'door-open' => 'Door is open! (.)',
   'door-closed' => 'Door is closed! (.)' 
},

This is just an example. Here we see a hash with keys and values. Keys are identifiers which you later use as $ENV{CHECK_LOGFILES_PATTERN_KEY} in the supersmartscript. It tells you which of the patterns has matched. And the values of the criticalpatterns hash are the regular expressions.
Actually i do not understand why anybody would assume that this can work:

criticalpatterns => {'MemoryException: (\d+) bytes not available',
'TradeBase: not enough memory for index(.)'},

Ok, let me do your job, you can get a coffee in the meantime.

criticalpatterns => {
   'memory-exception' => 'MemoryException: (\d+) bytes not available',
   'tradebase' => 'TradeBase: not enough memory for index(.)',
},
...
script => sub {
  if ($ENV{CHECK_LOGFILES_PATTERN_KEY} eq 'memory-exception') {
    my $gigabytes = $ENV{CHECK_LOGFILES_CAPTURE_GROUP1} / (10241024*1024);
    if ($gigabytes > 3.5) {
      print $ENV{CHECK_LOGFILES_SERVICEOUTPUT};
      return 2;
    } else {
      return 0; 
    }
  } elsif ($ENV{CHECK_LOGFILES_PATTERN_KEY} eq 'tradebase') {
    # the second pattern matched. $ENV{CHECK_LOGFILES_CAPTURE_GROUP1} contains the index number
...
  }
},

The default way to define multiple criticalpatterns is
criticalpatterns => ['MemoryException: (\d+) bytes not available', 'TradeBase: not enough memory for index(.)'],
but as these two patterns, especially the capture group, are so different, you would need to execute a pattern match in the script again in order to find out which one has actually matched. The syntax with criticalpatterns as a hash helps you identify the matching one by putting the pattern identifier in $ENV{CHECK_LOGFILES_PATTERN_KEY}.

from check_logfiles.

AgentZoy avatar AgentZoy commented on August 19, 2024

THANKS YOU FOR YOUR TIME AND HELP

from check_logfiles.

AgentZoy avatar AgentZoy commented on August 19, 2024

Can you help How i can implement that check stays in critical until for example ok word is founded in log file
Now check works in this way
If in check moment it found critical pattern it's show critical
Nothing added to test log file
Net check run
State OK
I will try by myself but not sure that i will success

from check_logfiles.

lausser avatar lausser commented on August 19, 2024

from check_logfiles.

AgentZoy avatar AgentZoy commented on August 19, 2024

Aha I understand logic
Thanks

from check_logfiles.

AgentZoy avatar AgentZoy commented on August 19, 2024

He goes to ok state after second check
In log files are critical records
1st run result critical
2nd run result ok But no ok pattern exist in file
Why ?
config file now
okpatterns => ['ok'],
@searches = ({
logfile => "test.log",
criticalpatterns => {
'memory-exception' => 'MemoryException: (\d+) bytes not available',
'tradebase' => 'TradeBase: not enough memory for index',
},
okpatterns => ['ok'],
options => "supersmartscript,capturegroups,noprotocol",
script => sub {

if ($ENV{CHECK_LOGFILES_PATTERN_KEY} eq 'memory-exception') {
my $gigabytes = $ENV{CHECK_LOGFILES_CAPTURE_GROUP1} / (1024*1024*1024);
if ($gigabytes > 3.5) {
print $ENV{CHECK_LOGFILES_SERVICEOUTPUT};
return 2;
} else {
return 0;
}
} elsif ($ENV{CHECK_LOGFILES_PATTERN_KEY} eq 'tradebase') {
# the second pattern matched. $ENV{CHECK_LOGFILES_CAPTURE_GROUP1} contains the index number
return 2;
}
},

});
log file content
MemoryException: 4972844748 bytes not available

from check_logfiles.

AgentZoy avatar AgentZoy commented on August 19, 2024

Last that I want you help me
I want to take last logfile in log folder
I tested in this way before
./check_logfiles --logfile 'ls -tr | tail -1' --criticalpattern 'TradeBase: not enough memory for index'
It works
But how to execute it in config file
I tried in perl style but no one variant works

@searches = ({
logfile => qx/ls -tr | tail -1/,

from check_logfiles.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.