2010-08-10 Ramon Novoa <rnovoa@artica.es>
* lib/PandoraFMS/SNMPServer.pm: Added support for SNMP filters. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3124 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
e58d4e4fbf
commit
5e6aed9fe8
|
@ -1,3 +1,7 @@
|
|||
2010-08-10 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* lib/PandoraFMS/SNMPServer.pm: Added support for SNMP filters.
|
||||
|
||||
2010-08-10 Sancho Lerena <slerena@artica.es>
|
||||
|
||||
* lib/PandoraFMS/Config.pm: Updated build and development version.
|
||||
|
|
|
@ -114,6 +114,7 @@ sub pandora_snmptrapd {
|
|||
while (my $line = <SNMPLOGFILE>) {
|
||||
$last_line++;
|
||||
$last_size = (stat ($log_file))[7];
|
||||
chomp ($line);
|
||||
|
||||
# Update index file
|
||||
open INDEXFILE, '>' . $idx_file;
|
||||
|
@ -124,7 +125,7 @@ sub pandora_snmptrapd {
|
|||
next if ($line =~ m/NET-SNMP/);
|
||||
|
||||
# Unknown data
|
||||
next if ($line !~ m/\[\*\*\]/);
|
||||
next if ($line !~ m/\[\*\*\]/ || matches_filter ($dbh, $pa_config, $line) == 1);
|
||||
|
||||
logger($pa_config, "Reading trap '$line'", 10);
|
||||
my ($date, $time, $source, $oid, $type, $type_desc, $value, $data) = ('', '', '', '', '', '', '', '');
|
||||
|
@ -173,5 +174,24 @@ sub stop () {
|
|||
$self->SUPER::stop ();
|
||||
}
|
||||
|
||||
########################################################################################
|
||||
# Returns 1 if the given string matches any SNMP filter, 0 otherwise.
|
||||
########################################################################################
|
||||
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 = $filter->{'filter'};
|
||||
if ($string =~ m/$regexp/i) {
|
||||
logger($pa_config, "Trap '$string' matches filter '$regexp'. Discarding...", 10);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
|
Loading…
Reference in New Issue