From: Stefan Schantl Date: Tue, 19 Jan 2016 11:51:05 +0000 (+0100) Subject: Use Events module to perform various actions. X-Git-Tag: 2.0~48 X-Git-Url: http://git.ipfire.org/?p=people%2Fstevee%2Fguardian.git;a=commitdiff_plain;h=e8528a98bf9b0a604bc4c4a38c055fadd0ab3183 Use Events module to perform various actions. Guardian now uses the Events module to perform various actions, based on the recieved event by a parser or the socket. Periodly guardian is calling the "RemoveBlocks" function from the Events module to release the block of an IP address if the configured BlockTime has been passed. Signed-off-by: Stefan Schantl --- diff --git a/guardian b/guardian index 2a5b460..07e0c14 100644 --- a/guardian +++ b/guardian @@ -30,6 +30,7 @@ use Time::HiRes qw[ time sleep ]; require Guardian::Base; require Guardian::Config; require Guardian::Daemon; +require Guardian::Events; require Guardian::Logger; require Guardian::Parser; require Guardian::Socket; @@ -86,6 +87,9 @@ $mainsettings{Logger} = $logger; # Redirect perls "die" messages to the logger before exiting. $SIG{__DIE__} = sub { $logger->Log("err", "@_"); }; +# Initialize the event handler. +my $events = Guardian::Events->Init(%mainsettings); + # Shared hash between the main process and all threads. It will store all # monitored files and their current file position. my %monitored_files :shared = (); @@ -124,10 +128,18 @@ while(1) { # Log processed event. $logger->Log("debug", "QUEUE - Processed event: $event"); + # Send event data to the events parser to determine + # if any action is required. + $events->CheckAction($event); + # Drop processed event from queue. $queue->dequeue(); } + # Call RemoveBlocks routine from the Events module to check + # if items from the block list can be dropped. + $events->RemoveBlocks(); + # Sleep 10ms to reduce the load of the main process. sleep(0.01); }