diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 4cde12d5f5..2b642323bd 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2012-07-27 KIKUCHI Koichiro + + * lib/PandoraFMS/Core.pm: fixed bug: added missing decode_entities for + SNMP alert evaluation. Also cleaned source code style. + 2012-07-25 Miguel de Dios * lib/PandoraFMS/DB.pm: cleaned source code style. diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 91308dcefc..f19ae0390f 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -450,7 +450,7 @@ sub pandora_process_alert ($$$$$$$$;$) { $alert->{'name'} . ")", $agent->{'id_grupo'}, $agent->{'id_agente'}, $alert->{'priority'}, $id, (defined ($alert->{'id_agent_module'}) ? $alert->{'id_agent_module'} : 0), - "alert_ceased", 0, $dbh); + "alert_ceased", 0, $dbh); } return; } @@ -636,7 +636,7 @@ sub pandora_execute_alert ($$$$$$$$;$) { # Simple alert if (defined ($alert->{'id_template_module'})) { @actions = get_db_rows ($dbh, 'SELECT *, talert_template_module_actions.id AS id_alert_template_module_actions - FROM talert_template_module_actions, talert_actions, talert_commands + FROM talert_template_module_actions, talert_actions, talert_commands WHERE talert_template_module_actions.id_alert_action = talert_actions.id AND talert_actions.id_alert_command = talert_commands.id AND talert_template_module_actions.id_alert_template_module = ? @@ -815,13 +815,13 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Internal event } elsif ($action->{'name'} eq "Pandora FMS Event") { - $field1 = subst_alert_macros ($field1, \%macros); - pandora_event ($pa_config, $field1, (defined ($agent) ? $agent->{'id_grupo'} : 0), (defined ($agent) ? $agent->{'id_agente'} : 0), $alert->{'priority'}, 0, 0, "alert_fired", 0, $dbh); + $field1 = subst_alert_macros ($field1, \%macros); + pandora_event ($pa_config, $field1, (defined ($agent) ? $agent->{'id_grupo'} : 0), (defined ($agent) ? $agent->{'id_agente'} : 0), $alert->{'priority'}, 0, 0, "alert_fired", 0, $dbh); # Validate event (field1: agent name; field2: module name) } elsif ($action->{'name'} eq "Validate Event") { - my $agent_id = -1; - my $module_id = -1; - if($field1 ne '') { + my $agent_id = -1; + my $module_id = -1; + if($field1 ne '') { $agent_id = get_agent_id ($dbh, $field1); if($field2 ne '' && $agent_id != -1) { $module_id = get_agent_module_id ($dbh, $field2, $agent_id); @@ -1267,9 +1267,9 @@ Delete all actions of policy template module. =cut ########################################################################## sub pandora_delete_all_template_module_actions ($$) { - my ($dbh, $template_module_id) = @_; + my ($dbh, $template_module_id) = @_; - return db_do ($dbh, 'DELETE FROM talert_template_module_actions WHERE id_alert_template_module = ?', $template_module_id); + return db_do ($dbh, 'DELETE FROM talert_template_module_actions WHERE id_alert_template_module = ?', $template_module_id); } ########################################################################## @@ -1715,8 +1715,8 @@ 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'}); + # 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); @@ -1736,31 +1736,31 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { } # Trap value - my $single_value = $alert->{'single_value'}; + my $single_value = decode_entities($alert->{'single_value'}); if ($single_value ne '') { next if ($trap_value !~ m/^$single_value$/i); $alert_data .= "Value: $trap_value "; } # Agent IP - my $agent = $alert->{'agent'}; + my $agent = decode_entities($alert->{'agent'}); if ($agent ne '') { next if ($trap_agent !~ m/^$agent$/i ); $alert_data .= "Agent: $agent"; } - # Specific SNMP Trap alert macros for regexp selectors in trap info + # Specific SNMP Trap alert macros for regexp selectors in trap info my %macros; # Custom OID/value - # Decode first, this could be a complex regexp ! + # Decode first, this could be a complex regexp ! my $custom_oid = decode_entities($alert->{'custom_oid'}); if ($custom_oid ne '') { # No match - next if ($trap_custom_oid !~ m/^$custom_oid$/i); + next if ($trap_custom_oid !~ m/^$custom_oid$/i); - # Match! + # Match! $macros{'_snmp_f1_'} = $1 if (defined($1)); $macros{'_snmp_f2_'} = $2 if (defined($2)); $macros{'_snmp_f3_'} = $3 if (defined($3)); @@ -1788,9 +1788,9 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { } # Replace macros - $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); + $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); # Check time threshold $alert->{'last_fired'} = '1970-01-01 00:00:00' unless defined ($alert->{'last_fired'}); @@ -1824,27 +1824,27 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { 'priority' => $alert->{'priority'}, ); - my %agent; + my %agent; - my $this_agent = get_agent_from_addr ($dbh, $trap_agent); - if (defined($this_agent)){ - %agent = ( - 'nombre' => $this_agent->{'nombre'}, - 'id_agente' => $this_agent->{'id_agente'}, - 'direccion' => $trap_agent, - 'id_grupo' => $this_agent->{'id_grupo'}, - 'comentarios' => '' - ); - } else { - %agent = ( - 'nombre' => $trap_agent, - 'direccion' => $trap_agent, - 'comentarios' => '', - 'id_agente' => 0, - 'id_grupo' => 0 - ); - } - + my $this_agent = get_agent_from_addr ($dbh, $trap_agent); + if (defined($this_agent)){ + %agent = ( + 'nombre' => $this_agent->{'nombre'}, + 'id_agente' => $this_agent->{'id_agente'}, + 'direccion' => $trap_agent, + 'id_grupo' => $this_agent->{'id_grupo'}, + 'comentarios' => '' + ); + } else { + %agent = ( + 'nombre' => $trap_agent, + 'direccion' => $trap_agent, + 'comentarios' => '', + 'id_agente' => 0, + 'id_grupo' => 0 + ); + } + # Execute alert my $action = get_db_single_row ($dbh, 'SELECT * @@ -1857,10 +1857,10 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { pandora_execute_action ($pa_config, $trap_rcv_full, \%agent, \%alert, 1, $action, undef, $dbh, $timestamp, \%macros) if (defined ($action)); # Generate an event, ONLY if our alert action is different from generate an event. - if ($action->{'id_alert_command'} != 3){ - pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")", + if ($action->{'id_alert_command'} != 3){ + pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")", 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh); - } + } # Update alert status db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, last_fired = ?, internal_counter = ? WHERE id_as = ?', @@ -2599,7 +2599,7 @@ sub pandora_group_statistics ($$) { $non_init = get_db_value ($dbh, "SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = $group AND tagente.disabled = 0 - AND tagente.id_agente = tagente_estado.id_agente + AND tagente.id_agente = tagente_estado.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0");