- # Check Priority Level and skip the alert if it is to low.
- #if ($line =~ /.*\[Priority: (\d+)\].*/) {
- # return unless($1 < $priority);
- #}
-
- # Search for a line like xxx.xxx.xxx.xxx -> xxx.xxx.xxx.xxx
- if ($line =~ /(\d+\.\d+\.\d+\.\d+)+ -\> (\d+\.\d+\.\d+\.\d+)+/) {
- # Store the grabbed IP-address.
- $address = $1;
- }
-
- # Search for a line like xxx.xxx.xxx.xxx:xxx -> xxx.xxx.xxx.xxx:xxx
- elsif ($line =~ /(\d+\.\d+\.\d+\.\d+):\d+ -\> (\d+\.\d+\.\d+\.\d+):\d+/) {
- # Store the obtained IP-address.
- $address = $1;
- }
-
- # Obtain the reported reason.
- if ($line =~ /.*msg:\"(.*)\".*/) {
- # Store the extracted message.
- $message = $1;
+ # Remove any newlines.
+ chomp($line);
+
+ # A single alert contains multiple lines, push all of them
+ # a temporary array.
+ push(@alert, $line);
+
+ # Each alert ends with an empty line, if one is found,
+ # all lines of the current processed alert have been found
+ # and pushed to the temporary array.
+ if($line =~ /^\s*$/) {
+ # Variable to store the grabbed IP-address.
+ my $address;
+
+ # Loop through all lines of the current alert.
+ foreach my $line (@alert) {
+ # Check Priority Level and skip the alert if it is to low.
+ #if ($line =~ /.*\[Priority: (\d+)\].*/) {
+ # return unless($1 < $priority);
+ #}
+
+ # Search for a line like xxx.xxx.xxx.xxx -> xxx.xxx.xxx.xxx
+ if ($line =~ /(\d+\.\d+\.\d+\.\d+)+ -\> (\d+\.\d+\.\d+\.\d+)+/) {
+ # Store the grabbed IP-address.
+ $address = $1;
+ }
+
+ # Search for a line like xxx.xxx.xxx.xxx:xxx -> xxx.xxx.xxx.xxx:xxx
+ elsif ($line =~ /(\d+\.\d+\.\d+\.\d+):\d+ -\> (\d+\.\d+\.\d+\.\d+):\d+/) {
+ # Store the obtained IP-address.
+ $address = $1;
+ }
+
+ # Obtain the reported reason from the headline of the alert.
+ if ($line =~ /.*\] (.*) \[\*\*\]/) {
+ # Store the extracted message.
+ $message = $1;
+ }
+
+ # If the reason could not be determined, try to obtain it from a msg field.
+ elsif ($line =~ /.*msg:\"(.*)\".*/) {
+ # Store the extracted message.
+ $message = $1;
+ }
+ }
+
+ # Check if at least the IP-address information has been extracted.
+ if (defined ($address)) {
+ # Add the extracted values and event message for the computed
+ # event to the actions array.
+ push(@actions, "count $address $name $message");
+ }
+
+ # The alert has been processed, clear the temporary array for storing
+ # the next alert.
+ @alert = ();