From efd8c850a06c8118c9c95590bb90f1d9d3517973 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Wed, 25 Oct 2017 16:47:58 +0200 Subject: [PATCH] Added new filter function to snmp traps --- pandora_server/lib/PandoraFMS/SNMPServer.pm | 38 ++++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index bc7b3a708a..2ea002bb1b 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -345,22 +345,34 @@ sub pandora_snmptrapd { sub matches_filter ($$$) { my ($dbh, $pa_config, $string) = @_; - # Get filters - my @filters = get_db_rows ($dbh, 'SELECT filter FROM tsnmp_filter'); - foreach my $filter (@filters) { - my $regexp = safe_output($filter->{'filter'}) ; - my $eval_result; + my @filter_unique_functions = get_db_rows ($dbh, 'SELECT DISTINCT(unified_filters_id) FROM tsnmp_filter ORDER BY unified_filters_id'); - # eval protects against server down (by invalid regular expressions) - $eval_result = eval { - $string =~ m/$regexp/i ; - }; + foreach my $filter_unique_func (@filter_unique_functions) { + # Get filters + my @filters = get_db_rows ($dbh, 'SELECT filter FROM tsnmp_filter WHERE unified_filters_id = ' . $filter_unique_func->{'unified_filters_id'}); - if ($eval_result) { - logger($pa_config, "Trap '$string' matches filter '$regexp'. Discarding...", 10); - return 1; - } + my $eval_acum = 1; + foreach my $filter (@filters) { + my $regexp = safe_output($filter->{'filter'}) ; + my $eval_result; + # eval protects against server down (by invalid regular expressions) + $eval_result = eval { + $string =~ m/$regexp/i ; + }; + + if ($eval_result && $eval_acum) { + $eval_acum = 1; + } + else { + $eval_acum = 0; + last; + } + } + + if ($eval_acum) { + return 1; + } } return 0;