diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 8ed0a6c6c5..fd0a7508aa 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,17 @@ +2011-08-17 Sancho Lerena + + * SNMPServer.pm: Custom value and custom type are not used anymore. + All extended info comes into custom_oid which stores now all the + raw info. + + * Core.pm: pandora_evaluate_snmp_alerts() function now uses complex + regular expression and new macros to allow complex SNMP trap alerts + which takes information from the trap info and puts on the alert. + + * DataServer.pm: Fixed notice about undefined GIS position desc. + + * pandora_db.pl: Version update. + 2011-08-17 Ramon Novoa * lib/PandoraFMS/NetworkServer.pm: Convert text obj tags to OIDs. diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index dda143ab14..a8bde6d78e 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1590,15 +1590,16 @@ sub pandora_module_keep_alive_nd { } ########################################################################## -=head2 C<< pandora_evaluate_snmp_alerts (I<$pa_config>, I<$trap_id>, I<$trap_agent>, I<$trap_oid>, I<$trap_oid_text>, I<$value>, I<$trap_custom_oid>, I<$trap_custom_value>, I<$dbh>) >> +=head2 C<< pandora_evaluate_snmp_alerts (I<$pa_config>, I<$trap_id>, I<$trap_agent>, I<$trap_oid>, I<$trap_oid_text>, I<$value>, I<$trap_custom_oid>, I<$dbh>) >> Execute alerts that apply to the given SNMP trap. =cut ########################################################################## -sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { +sub pandora_evaluate_snmp_alerts ($$$$$$$$) { my ($pa_config, $trap_id, $trap_agent, $trap_oid, - $trap_oid_text, $trap_value, $trap_custom_oid, $trap_custom_value, $dbh) = @_; + $trap_oid_text, $trap_value, $trap_custom_oid, $dbh) = @_; + # Get all SNMP alerts my @snmp_alerts = get_db_rows ($dbh, 'SELECT * FROM talert_snmp'); @@ -1613,28 +1614,57 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { ($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'}); # OID + # Decode first, could be a complex regexp ! + $alert->{'oid'} = decode_entities($alert->{'oid'}); my $oid = $alert->{'oid'}; if ($oid ne '') { next if ($trap_oid !~ m/^$oid$/i && $trap_oid_text !~ m/^$oid$/i); $alert_data .= "OID: $oid "; } - # Custom OID/value - my $custom_oid = $alert->{'custom_oid'}; - if ($custom_oid ne '') { - if ($trap_value =~ m/^$custom_oid$/i){ - $alert_data .= " Trap Value: $trap_value"; - - } elsif ($trap_custom_value =~ m/^$custom_oid$/i){ - $alert_data .= " Trap Value: $trap_custom_value"; + # Specific SNMP Trap alert macros for regexp selectors in trap info + my $snmp_f1 = ""; + my $snmp_f2 = ""; + my $snmp_f3 = ""; + + # Custom OID/value + # Decode first, this could be a complex regexp ! + + $alert->{'custom_oid'} = decode_entities($alert->{'custom_oid'}); + my $custom_oid = $alert->{'custom_oid'}; + + if ($custom_oid ne '') { + if ($trap_custom_oid =~ m/^$custom_oid$/i){ + $alert_data .= " Custom: $trap_custom_oid"; + + # Let's capture some data using regexp selectors ! + + if (defined($1)){ + $snmp_f1 = $1; + } + if (defined($2)){ + $snmp_f2 = $2; + } + if (defined($3)){ + $snmp_f3 = $3; + } - } elsif ($trap_custom_oid =~ m/^$custom_oid$/i){ - $alert_data .= " Trap Value: $trap_custom_oid"; } else { next; } } + # SANCHO DEBUG + + my %macros; + $macros{_snmp_f1_} = $snmp_f1; + $macros{_snmp_f2_} = $snmp_f2; + $macros{_snmp_f3_} = $snmp_f3; + + $alert->{'al_field1'} = subst_alert_macros ($alert->{'al_field1'}, \%macros); + $alert->{'al_field2'} = subst_alert_macros ($alert->{'al_field2'}, \%macros); + $alert->{'al_field3'} = subst_alert_macros ($alert->{'al_field3'}, \%macros); + # Agent IP my $agent = $alert->{'agent'}; if ($agent ne '') { @@ -1702,7 +1732,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { WHERE talert_actions.id_alert_command = talert_commands.id AND talert_actions.id = ?', $alert->{'id_alert'}); - my $trap_rcv_full = $trap_oid . " " . $trap_value. " ". $trap_custom_oid . " " . $trap_custom_value; + my $trap_rcv_full = $trap_oid . " " . $trap_value. " ". $trap_custom_oid; pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh, $timestamp) if (defined ($action)); diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index b85d2a827d..4487bfa3bc 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -241,11 +241,13 @@ sub process_xml_data ($$$$$) { my $doc = $xs1->XMLin($content); $position_description = safe_input ($doc->{result}{content}); - } else { - $position_description = ''; # Default value } } + if (!defined($position_description)){ + $position_description = ""; + } + logger($pa_config, "Getting GIS Data=timezone_offset=$timezone_offset longitude=$longitude latitude=$latitude altitude=$altitude position_description=$position_description", 8); } diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index a8dc3b929b..67ad794b2b 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -151,12 +151,12 @@ sub pandora_snmptrapd { $value = limpia_cadena ($value); my ($custom_oid, $custom_type, $custom_value) = ('', '', ''); - ($custom_oid, $custom_type, $custom_value) = ($1, $2, limpia_cadena ($3)) if ($data =~ m/([0-9\.]*)\s\=\s([A-Za-z0-9]*)\:\s(.+)/); + + # custom_type, custom_value is not used since 4.0 version, all custom data goes on custom_oid + $custom_oid = $data; # Try to save as much information as possible if the trap could not be parsed $oid = $type_desc if ($oid eq '' || $oid eq '.'); - $custom_value = $type_desc if ($custom_oid eq '' || $custom_oid eq '.'); - $custom_value = $data if ($custom_value eq ''); # Insert the trap into the DB if (! defined(enterprise_hook ('snmp_insert_trap', [$pa_config, $source, $oid, $type, $value, $custom_oid, $custom_value, $custom_type, $timestamp, $self->getServerID (), $dbh]))) { @@ -165,7 +165,7 @@ sub pandora_snmptrapd { logger ($pa_config, "Received SNMP Trap from $source", 4); # Evaluate alerts for this trap - pandora_evaluate_snmp_alerts ($pa_config, $trap_id, $source, $oid, $oid, $value, $custom_oid, $custom_value, $dbh); + pandora_evaluate_snmp_alerts ($pa_config, $trap_id, $source, $oid, $oid, $value, $custom_oid, $dbh); } } diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl index 48fc5b3934..cb631d102e 100755 --- a/pandora_server/util/pandora_db.pl +++ b/pandora_server/util/pandora_db.pl @@ -30,7 +30,7 @@ use PandoraFMS::Tools; use PandoraFMS::DB; # version: define current version -my $version = "4.0 PS100310"; +my $version = "4.0 PS110810"; # Pandora server configuration my %conf;