How to configure pattern option of check-log.rb in a check definition?

logging/check-log.rb runs quite well when I execute it from shell directly, like this:

./check-log.rb -f /usr/local/freeswitch/log/freeswitch.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r

CheckLog OK: 0 warnings, 0 criticals for pattern \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*.

but when I add the same command in the check definition. It’s not working, the server report a error on this command, here is my check definition:
{
“checks”: {
“check_log”: {
“handlers”: [“print_timestamp”],
“command”: “/etc/sensu/plugins/check-log.rb -f /var/log/mysql/error.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r”,
“interval”: 10,
“subscribers”: [ “webservers” ]
}
}
}

{“timestamp”:“2015-03-20T11:08:14.681567+0800”,“level”:“warn”,“message”:“loading config file”,“file”:"/etc/sensu/conf.d/check_log.json"}
{“timestamp”:“2015-03-20T11:08:14.681638+0800”,“level”:“warn”,“message”:“config file must be valid json”,“file”:"/etc/sensu/conf.d/check_log.json",“error”:“lexical error: inside a string, ‘\’ occurs before a character which it may not.\n
/var/log/mysql/error.log -q '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\\n
(right here) ------^\n”}
{“timestamp”:“2015-03-20T11:08:14.681703+0800”,“level”:“warn”,“message”:“ignoring config file”,“file”:"/etc/sensu/conf.d/check_log.json"}

How should I configure the pattern option for check-log.rb exactlly?

I believe the command is passed to a shell. So you need to escape '' properly.

Try ‘\’ (e.g. ‘\d’ instead of ‘\d’)

···

On Friday, March 20, 2015 at 3:25:32 PM UTC+11, Timothy John wrote:

logging/check-log.rb runs quite well when I execute it from shell directly, like this:

./check-log.rb -f /usr/local/freeswitch/log/freeswitch.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r

CheckLog OK: 0 warnings, 0 criticals for pattern \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*.

but when I add the same command in the check definition. It’s not working, the server report a error on this command, here is my check definition:
{
“checks”: {
“check_log”: {
“handlers”: [“print_timestamp”],
“command”: “/etc/sensu/plugins/check-log.rb -f /var/log/mysql/error.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r”,
“interval”: 10,
“subscribers”: [ “webservers” ]
}
}
}

{“timestamp”:“2015-03-20T11:08:14.681567+0800”,“level”:“warn”,“message”:“loading config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
{“timestamp”:“2015-03-20T11:08:14.681638+0800”,“level”:“warn”,“message”:“config file must be valid json”,“file”:“/etc/sensu/conf.d/check_log.json”,“error”:“lexical error: inside a string, ‘\’ occurs before a character which it may not.\n
/var/log/mysql/error.log -q '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\\n
(right here) ------^\n”}
{“timestamp”:“2015-03-20T11:08:14.681703+0800”,“level”:“warn”,“message”:“ignoring config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
How should I configure the pattern option for check-log.rb exactlly?

Is this the way to search into the log file and match against a pattern? I want to check if the word “ERROR” is in the log file. Whatever I do, I tells me that there are no ERRORS. Even if a make a new logfile with only the text “ERROR”, it keeps telling me that there are no warnings or criticals.

Any help please?

···

Op vrijdag 20 maart 2015 05:25:32 UTC+1 schreef Tim John:

logging/check-log.rb runs quite well when I execute it from shell directly, like this:

./check-log.rb -f /usr/local/freeswitch/log/freeswitch.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r

CheckLog OK: 0 warnings, 0 criticals for pattern \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*.

but when I add the same command in the check definition. It’s not working, the server report a error on this command, here is my check definition:
{
“checks”: {
“check_log”: {
“handlers”: [“print_timestamp”],
“command”: “/etc/sensu/plugins/check-log.rb -f /var/log/mysql/error.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r”,
“interval”: 10,
“subscribers”: [ “webservers” ]
}
}
}

{“timestamp”:“2015-03-20T11:08:14.681567+0800”,“level”:“warn”,“message”:“loading config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
{“timestamp”:“2015-03-20T11:08:14.681638+0800”,“level”:“warn”,“message”:“config file must be valid json”,“file”:“/etc/sensu/conf.d/check_log.json”,“error”:“lexical error: inside a string, ‘\’ occurs before a character which it may not.\n
/var/log/mysql/error.log -q '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\\n
(right here) ------^\n”}
{“timestamp”:“2015-03-20T11:08:14.681703+0800”,“level”:“warn”,“message”:“ignoring config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
How should I configure the pattern option for check-log.rb exactlly?

I want to do the same thing actually. Match the word ERROR. I need to learn my regex better. Any good tutorials?

···

On Tuesday, June 30, 2015 at 9:54:40 AM UTC-5, Romario Lodder wrote:

Is this the way to search into the log file and match against a pattern? I want to check if the word “ERROR” is in the log file. Whatever I do, I tells me that there are no ERRORS. Even if a make a new logfile with only the text “ERROR”, it keeps telling me that there are no warnings or criticals.

Any help please?

Op vrijdag 20 maart 2015 05:25:32 UTC+1 schreef Tim John:

logging/check-log.rb runs quite well when I execute it from shell directly, like this:

./check-log.rb -f /usr/local/freeswitch/log/freeswitch.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r

CheckLog OK: 0 warnings, 0 criticals for pattern \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*.

but when I add the same command in the check definition. It’s not working, the server report a error on this command, here is my check definition:
{
“checks”: {
“check_log”: {
“handlers”: [“print_timestamp”],
“command”: “/etc/sensu/plugins/check-log.rb -f /var/log/mysql/error.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r”,
“interval”: 10,
“subscribers”: [ “webservers” ]
}
}
}

{“timestamp”:“2015-03-20T11:08:14.681567+0800”,“level”:“warn”,“message”:“loading config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
{“timestamp”:“2015-03-20T11:08:14.681638+0800”,“level”:“warn”,“message”:“config file must be valid json”,“file”:“/etc/sensu/conf.d/check_log.json”,“error”:“lexical error: inside a string, ‘\’ occurs before a character which it may not.\n
/var/log/mysql/error.log -q '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\\n
(right here) ------^\n”}
{“timestamp”:“2015-03-20T11:08:14.681703+0800”,“level”:“warn”,“message”:“ignoring config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
How should I configure the pattern option for check-log.rb exactlly?

To match the word error I think the Regex is a simple /ERROR/

That should match any occurrences of the word, “ERROR”.

I’m attempting to parse a log for the word interface like this:

/opt/sensu/embedded/bin/ruby check-log.rb -F /var/log/messages -q ‘/interface/’

But I need to figure out how to get the occurrences of the word to fire a warning/critical.

Any ideas?

···

On Tuesday, August 4, 2015 at 1:10:27 PM UTC-5, James Jelinek wrote:

I want to do the same thing actually. Match the word ERROR. I need to learn my regex better. Any good tutorials?

On Tuesday, June 30, 2015 at 9:54:40 AM UTC-5, Romario Lodder wrote:

Is this the way to search into the log file and match against a pattern? I want to check if the word “ERROR” is in the log file. Whatever I do, I tells me that there are no ERRORS. Even if a make a new logfile with only the text “ERROR”, it keeps telling me that there are no warnings or criticals.

Any help please?

Op vrijdag 20 maart 2015 05:25:32 UTC+1 schreef Tim John:

logging/check-log.rb runs quite well when I execute it from shell directly, like this:

./check-log.rb -f /usr/local/freeswitch/log/freeswitch.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r

CheckLog OK: 0 warnings, 0 criticals for pattern \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*.

but when I add the same command in the check definition. It’s not working, the server report a error on this command, here is my check definition:
{
“checks”: {
“check_log”: {
“handlers”: [“print_timestamp”],
“command”: “/etc/sensu/plugins/check-log.rb -f /var/log/mysql/error.log -q ‘\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} \d{4} [Warning] .*’ -r”,
“interval”: 10,
“subscribers”: [ “webservers” ]
}
}
}

{“timestamp”:“2015-03-20T11:08:14.681567+0800”,“level”:“warn”,“message”:“loading config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
{“timestamp”:“2015-03-20T11:08:14.681638+0800”,“level”:“warn”,“message”:“config file must be valid json”,“file”:“/etc/sensu/conf.d/check_log.json”,“error”:“lexical error: inside a string, ‘\’ occurs before a character which it may not.\n
/var/log/mysql/error.log -q '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\\n
(right here) ------^\n”}
{“timestamp”:“2015-03-20T11:08:14.681703+0800”,“level”:“warn”,“message”:“ignoring config file”,“file”:“/etc/sensu/conf.d/check_log.json”}
How should I configure the pattern option for check-log.rb exactlly?