2012-07-27 KIKUCHI Koichiro <koichiro@rworks.jp>

* lib/PandoraFMS/Core.pm: fixed bug: added missing decode_entities for
	 SNMP alert evaluation. Also cleaned source code style.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6818 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
koichirok 2012-07-27 03:10:13 +00:00
parent 99f4ca991d
commit d56491c1de
2 changed files with 49 additions and 44 deletions

View File

@ -1,3 +1,8 @@
2012-07-27 KIKUCHI Koichiro <koichiro@rworks.jp>
* 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 <miguel.dedios@artica.es> 2012-07-25 Miguel de Dios <miguel.dedios@artica.es>
* lib/PandoraFMS/DB.pm: cleaned source code style. * lib/PandoraFMS/DB.pm: cleaned source code style.

View File

@ -450,7 +450,7 @@ sub pandora_process_alert ($$$$$$$$;$) {
$alert->{'name'} . ")", $agent->{'id_grupo'}, $alert->{'name'} . ")", $agent->{'id_grupo'},
$agent->{'id_agente'}, $alert->{'priority'}, $id, $agent->{'id_agente'}, $alert->{'priority'}, $id,
(defined ($alert->{'id_agent_module'}) ? $alert->{'id_agent_module'} : 0), (defined ($alert->{'id_agent_module'}) ? $alert->{'id_agent_module'} : 0),
"alert_ceased", 0, $dbh); "alert_ceased", 0, $dbh);
} }
return; return;
} }
@ -636,7 +636,7 @@ sub pandora_execute_alert ($$$$$$$$;$) {
# Simple alert # Simple alert
if (defined ($alert->{'id_template_module'})) { if (defined ($alert->{'id_template_module'})) {
@actions = get_db_rows ($dbh, 'SELECT *, talert_template_module_actions.id AS id_alert_template_module_actions @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 WHERE talert_template_module_actions.id_alert_action = talert_actions.id
AND talert_actions.id_alert_command = talert_commands.id AND talert_actions.id_alert_command = talert_commands.id
AND talert_template_module_actions.id_alert_template_module = ? AND talert_template_module_actions.id_alert_template_module = ?
@ -815,13 +815,13 @@ sub pandora_execute_action ($$$$$$$$$;$) {
# Internal event # Internal event
} elsif ($action->{'name'} eq "Pandora FMS Event") { } elsif ($action->{'name'} eq "Pandora FMS Event") {
$field1 = subst_alert_macros ($field1, \%macros); $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); 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) # Validate event (field1: agent name; field2: module name)
} elsif ($action->{'name'} eq "Validate Event") { } elsif ($action->{'name'} eq "Validate Event") {
my $agent_id = -1; my $agent_id = -1;
my $module_id = -1; my $module_id = -1;
if($field1 ne '') { if($field1 ne '') {
$agent_id = get_agent_id ($dbh, $field1); $agent_id = get_agent_id ($dbh, $field1);
if($field2 ne '' && $agent_id != -1) { if($field2 ne '' && $agent_id != -1) {
$module_id = get_agent_module_id ($dbh, $field2, $agent_id); $module_id = get_agent_module_id ($dbh, $field2, $agent_id);
@ -1267,9 +1267,9 @@ Delete all actions of policy template module.
=cut =cut
########################################################################## ##########################################################################
sub pandora_delete_all_template_module_actions ($$) { 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'}); ($alert->{'times_fired'}, $alert->{'internal_counter'}, $alert->{'alert_type'});
# OID # OID
# Decode first, could be a complex regexp ! # Decode first, could be a complex regexp !
$alert->{'oid'} = decode_entities($alert->{'oid'}); $alert->{'oid'} = decode_entities($alert->{'oid'});
my $oid = $alert->{'oid'}; my $oid = $alert->{'oid'};
if ($oid ne '') { if ($oid ne '') {
next if ($trap_oid !~ m/^$oid$/i && $trap_oid_text !~ m/^$oid$/i); next if ($trap_oid !~ m/^$oid$/i && $trap_oid_text !~ m/^$oid$/i);
@ -1736,31 +1736,31 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
} }
# Trap value # Trap value
my $single_value = $alert->{'single_value'}; my $single_value = decode_entities($alert->{'single_value'});
if ($single_value ne '') { if ($single_value ne '') {
next if ($trap_value !~ m/^$single_value$/i); next if ($trap_value !~ m/^$single_value$/i);
$alert_data .= "Value: $trap_value "; $alert_data .= "Value: $trap_value ";
} }
# Agent IP # Agent IP
my $agent = $alert->{'agent'}; my $agent = decode_entities($alert->{'agent'});
if ($agent ne '') { if ($agent ne '') {
next if ($trap_agent !~ m/^$agent$/i ); next if ($trap_agent !~ m/^$agent$/i );
$alert_data .= "Agent: $agent"; $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; my %macros;
# Custom OID/value # 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'}); my $custom_oid = decode_entities($alert->{'custom_oid'});
if ($custom_oid ne '') { if ($custom_oid ne '') {
# No match # 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_f1_'} = $1 if (defined($1));
$macros{'_snmp_f2_'} = $2 if (defined($2)); $macros{'_snmp_f2_'} = $2 if (defined($2));
$macros{'_snmp_f3_'} = $3 if (defined($3)); $macros{'_snmp_f3_'} = $3 if (defined($3));
@ -1788,9 +1788,9 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
} }
# Replace macros # Replace macros
$alert->{'al_field1'} = subst_alert_macros ($alert->{'al_field1'}, \%macros); $alert->{'al_field1'} = subst_alert_macros ($alert->{'al_field1'}, \%macros);
$alert->{'al_field2'} = subst_alert_macros ($alert->{'al_field2'}, \%macros); $alert->{'al_field2'} = subst_alert_macros ($alert->{'al_field2'}, \%macros);
$alert->{'al_field3'} = subst_alert_macros ($alert->{'al_field3'}, \%macros); $alert->{'al_field3'} = subst_alert_macros ($alert->{'al_field3'}, \%macros);
# Check time threshold # Check time threshold
$alert->{'last_fired'} = '1970-01-01 00:00:00' unless defined ($alert->{'last_fired'}); $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'}, 'priority' => $alert->{'priority'},
); );
my %agent; my %agent;
my $this_agent = get_agent_from_addr ($dbh, $trap_agent); my $this_agent = get_agent_from_addr ($dbh, $trap_agent);
if (defined($this_agent)){ if (defined($this_agent)){
%agent = ( %agent = (
'nombre' => $this_agent->{'nombre'}, 'nombre' => $this_agent->{'nombre'},
'id_agente' => $this_agent->{'id_agente'}, 'id_agente' => $this_agent->{'id_agente'},
'direccion' => $trap_agent, 'direccion' => $trap_agent,
'id_grupo' => $this_agent->{'id_grupo'}, 'id_grupo' => $this_agent->{'id_grupo'},
'comentarios' => '' 'comentarios' => ''
); );
} else { } else {
%agent = ( %agent = (
'nombre' => $trap_agent, 'nombre' => $trap_agent,
'direccion' => $trap_agent, 'direccion' => $trap_agent,
'comentarios' => '', 'comentarios' => '',
'id_agente' => 0, 'id_agente' => 0,
'id_grupo' => 0 'id_grupo' => 0
); );
} }
# Execute alert # Execute alert
my $action = get_db_single_row ($dbh, 'SELECT * 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)); 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. # Generate an event, ONLY if our alert action is different from generate an event.
if ($action->{'id_alert_command'} != 3){ if ($action->{'id_alert_command'} != 3){
pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")", pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")",
0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh); 0, 0, $alert->{'priority'}, 0, 0, 'alert_fired', 0, $dbh);
} }
# Update alert status # Update alert status
db_do ($dbh, 'UPDATE talert_snmp SET times_fired = ?, last_fired = ?, internal_counter = ? WHERE id_as = ?', 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) $non_init = get_db_value ($dbh, "SELECT COUNT(tagente_estado.id_agente_estado)
FROM tagente_estado, tagente, tagente_modulo FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.id_grupo = $group AND tagente.disabled = 0 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_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
AND tagente_modulo.disabled = 0 AND tagente_modulo.disabled = 0
AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0"); AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0");