]> git.ipfire.org Git - people/stevee/guardian.git/blame - modules/Parser.pm
Allow to configure the used parser for a monitored file.
[people/stevee/guardian.git] / modules / Parser.pm
CommitLineData
88d9af2c
SS
1package Guardian::Parser;
2use strict;
3use warnings;
4
5use Exporter qw(import);
6
cfe5a220 7our @EXPORT_OK = qw(IsSupportedParser Parser);
88d9af2c 8
cfe5a220
SS
9# This hash contains all supported parsers and which function
10# has to be called to parse messages in the right way.
88d9af2c 11my %logfile_parsers = (
cfe5a220 12 "snort" => \&message_parser_snort,
88d9af2c
SS
13);
14
15#
16## The main parsing function.
17#
18## It is used to determine which sub-parser has to be used to
19## parse the given message in the right way and to return if
20## any action should be performed.
21#
22sub Parser ($$) {
cfe5a220 23 my ($parser, @message) = @_;
88d9af2c
SS
24
25 # If no responsible message parser could be found, just return nothing.
cfe5a220 26 unless (exists($logfile_parsers{$parser})) {
88d9af2c
SS
27 return;
28 }
29
cfe5a220
SS
30 # Call responsible message parser.
31 my $action = $logfile_parsers{$parser}->(@message);
88d9af2c
SS
32
33 # Return which action should be performed.
ebd440a9 34 return "count $action";
88d9af2c
SS
35}
36
cfe5a220
SS
37#
38## IsSupportedParser function.
39#
40## This very tiny function checks if a given parser name is available and
41## therefore a supported parser.
42#
43## To perform these check, the function is going to lookup if a key in the
44## hash of supported parsers is available
45#
46sub IsSupportedParser ($) {
47 my $parser = $_[0];
48
49 # Check if a key for the given parser exists in the hash of logfile_parsers.
50 if(exists($logfile_parsers{$parser})) {
51 # Found a valid parser, so return nothing.
52 return 1;
53 }
54
55 # Return "False" if we got here, and therefore no parser
56 # is available.
57 return;
58}
59
88d9af2c
SS
60#
61## The Snort message parser.
62#
63## This subfunction is responsible for parsing sort alerts and determine if
64## an action should be performed.
65#
66sub message_parser_snort($) {
67 my @message = @_;
68
69 # XXX
70 # Currently this parser just returns a simple message.
ebd440a9 71 return "$message[0] SNORT A simple Snort Message";
88d9af2c
SS
72}
73
741;