From dd0483736d6d2f194908eff73f36f50de1dd0197 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 17 Feb 2016 12:52:58 +0100 Subject: [PATCH] Except and log if an event could not be parsed correctly. If the called parser is not able to parser the given message for any event in the right way, except and log it as an error. Signed-off-by: Stefan Schantl --- guardian | 6 ++++++ modules/Parser.pm | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/guardian b/guardian index 7b4c23f..691ddc6 100644 --- a/guardian +++ b/guardian @@ -259,6 +259,12 @@ sub Worker ($) { # Put the required action into the queue. $queue->enqueue(@action); } + # If no action is returned by the Parser, the message + # could not be parser corretly. + else { + # Log failed parse attempt. + $logger->Log("err", "Error parsing event: \[$parser - @message\]"); + } } else { # Sleep for 10ms until the next round of the loop will start. sleep(0.01); diff --git a/modules/Parser.pm b/modules/Parser.pm index 9c3fc87..9ec0586 100644 --- a/modules/Parser.pm +++ b/modules/Parser.pm @@ -30,8 +30,16 @@ sub Parser ($$) { # Call responsible message parser. my $action = $logfile_parsers{$parser}->(@message); - # Return which action should be performed. - return "count $action"; + # If the parser successfully parsed the message, an action + # has been returned. + if ($action) { + # Return which action should be performed. + return "count $action"; + } + + # If the parser was not able to parse the the given message + # in the right way, return Nothing. + return; } # -- 2.39.2