]> git.ipfire.org Git - people/stevee/guardian.git/commitdiff
Except and log if an event could not be parsed correctly.
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 17 Feb 2016 11:52:58 +0000 (12:52 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 17 Feb 2016 11:52:58 +0000 (12:52 +0100)
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 <stefan.schantl@ipfire.org>
guardian
modules/Parser.pm

index 7b4c23fae7b86c7e2d5b1ea7a726a23b03baf2f9..691ddc66e1f0013add0fd5245f7864d70931d049 100644 (file)
--- a/guardian
+++ b/guardian
@@ -259,6 +259,12 @@ sub Worker ($) {
                                # Put the required action into the queue.
                                $queue->enqueue(@action);
                        }
                                # 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);
                } else {
                        # Sleep for 10ms until the next round of the loop will start.
                        sleep(0.01);
index 9c3fc87130204d8bbb674a4afdb7eecb2c0041d2..9ec058693ee8866aa82ce0979a2eba2f2f5a5d93 100644 (file)
@@ -30,8 +30,16 @@ sub Parser ($$) {
        # Call responsible message parser.
        my $action = $logfile_parsers{$parser}->(@message);
 
        # 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;
 }
 
 #
 }
 
 #