add new functionality flipflop

Former-commit-id: 00a71df0d228833dbe7211504e11418d91622d93
This commit is contained in:
Daniel Barbero Martin 2019-03-28 17:33:49 +01:00
parent e3222626dc
commit 33197df731

View File

@ -1605,15 +1605,16 @@ sub pandora_process_module ($$$$$$$$$;$) {
$current_interval = $module->{'module_interval'}; $current_interval = $module->{'module_interval'};
} }
#Update module status # Update module status.
my $min_ff_event = $module->{'min_ff_event'}; my $min_ff_event = $module->{'min_ff_event'};
my $current_utimestamp = time (); my $current_utimestamp = time ();
my $ff_timeout = $module->{'ff_timeout'}; my $ff_timeout = $module->{'ff_timeout'};
my $ff_warning = $module->{'ff_warning'};
my $ff_critical = $module->{'ff_critical'};
my $ff_normal = $module->{'ff_normal'};
if ($module->{'ff_type'} == 0) { # Counters.
my $ff_warning = $agent_status->{'ff_warning'};
my $ff_critical = $agent_status->{'ff_critical'};
my $ff_normal = $agent_status->{'ff_normal'};
if ($module->{'each_ff'}) { if ($module->{'each_ff'}) {
$min_ff_event = $module->{'min_ff_event_normal'} if ($new_status == 0); $min_ff_event = $module->{'min_ff_event_normal'} if ($new_status == 0);
$min_ff_event = $module->{'min_ff_event_critical'} if ($new_status == 1); $min_ff_event = $module->{'min_ff_event_critical'} if ($new_status == 1);
@ -1622,25 +1623,35 @@ sub pandora_process_module ($$$$$$$$$;$) {
if ($last_known_status == $new_status) { if ($last_known_status == $new_status) {
# Avoid overflows # Avoid overflows
$status_changes = $min_ff_event if ($status_changes > $min_ff_event); $status_changes = $min_ff_event if ($status_changes > $min_ff_event && $module->{'ff_type'} == 0);
$status_changes++; $status_changes++;
if ($module_type =~ m/async/ && $min_ff_event != 0 && $ff_timeout != 0 && ($utimestamp - $ff_start_utimestamp) > $ff_timeout) { if ($module_type =~ m/async/ && $min_ff_event != 0 && $ff_timeout != 0 && ($utimestamp - $ff_start_utimestamp) > $ff_timeout) {
$status_changes = 0; # Only type ff with counters.
$status_changes = 0 if ($module->{'ff_type'} == 0);
$ff_start_utimestamp = $utimestamp; $ff_start_utimestamp = $utimestamp;
# Reset counters because expired timeout.
$ff_normal = 0;
$ff_critical = 0;
$ff_warning = 0;
} }
} }
else { else {
$status_changes = 0; # Only type ff with counters.
$status_changes = 0 if ($module->{'ff_type'} == 0);
$ff_start_utimestamp = $utimestamp if ($module_type =~ m/async/); $ff_start_utimestamp = $utimestamp if ($module_type =~ m/async/);
} }
# Active ff interval if ($module->{'ff_type'} == 0) {
# Active ff interval.
if ($module->{'module_ff_interval'} != 0 && $status_changes < $min_ff_event) { if ($module->{'module_ff_interval'} != 0 && $status_changes < $min_ff_event) {
$current_interval = $module->{'module_ff_interval'}; $current_interval = $module->{'module_ff_interval'};
} }
# Change status # Change status.
if ($status_changes >= $min_ff_event && $known_status != $new_status) { if ($status_changes >= $min_ff_event && $known_status != $new_status) {
generate_status_event ($pa_config, $processed_data, $agent, $module, $new_status, $status, $known_status, $dbh); generate_status_event ($pa_config, $processed_data, $agent, $module, $new_status, $status, $known_status, $dbh);
$status = $new_status; $status = $new_status;
@ -1654,19 +1665,21 @@ sub pandora_process_module ($$$$$$$$$;$) {
} }
} }
} else { } else {
# Independent min_ff_event for all. if ($status == $new_status) {
if ($module->{'each_ff'}) { # If the status is equal to the previous status reset the counters.
$min_ff_event = $module->{'min_ff_event_normal'} if ($new_status == 0);
$min_ff_event = $module->{'min_ff_event_critical'} if ($new_status == 1);
$min_ff_event = $module->{'min_ff_event_warning'} if ($new_status == 2);
}
if ($last_known_status == $new_status) {
$ff_normal = 0; $ff_normal = 0;
$ff_critical = 0; $ff_critical = 0;
$ff_warning = 0; $ff_warning = 0;
} else { } else {
# Status change. # Sequential critical and normal status are needed
# if don't, reset counters.
if ($last_known_status == 1 && $new_status != 1) {
$ff_critical = 0;
} elsif ($last_known_status == 0 && $new_status != 0) {
$ff_normal = 0;
}
# Increase counters.
$ff_critical++ if ($new_status == 1); $ff_critical++ if ($new_status == 1);
$ff_warning++ if ($new_status == 2); $ff_warning++ if ($new_status == 2);
$ff_normal++ if ($new_status == 0); $ff_normal++ if ($new_status == 0);
@ -1675,10 +1688,27 @@ sub pandora_process_module ($$$$$$$$$;$) {
if ( ($new_status == 0 && $ff_normal >= $min_ff_event) if ( ($new_status == 0 && $ff_normal >= $min_ff_event)
|| ($new_status == 1 && $ff_critical >= $min_ff_event) || ($new_status == 1 && $ff_critical >= $min_ff_event)
|| ($new_status == 2 && $ff_warning >= $min_ff_event)) { || ($new_status == 2 && $ff_warning >= $min_ff_event)) {
# Change status generate event.
generate_status_event ($pa_config, $processed_data, $agent, $module, $new_status, $status, $known_status, $dbh);
$status = $new_status; $status = $new_status;
# Update module status count.
$mark_for_update = 1;
# Safe mode execution.
if ($agent->{'safe_mode_module'} == $module->{'id_agente_modulo'}) {
safe_mode($pa_config, $agent, $module, $new_status, $known_status, $dbh);
}
# Reset counters because change status.
$ff_normal = 0; $ff_normal = 0;
$ff_critical = 0; $ff_critical = 0;
$ff_warning = 0; $ff_warning = 0;
} else {
# Active ff interval
if ($module->{'module_ff_interval'} != 0) {
$current_interval = $module->{'module_ff_interval'};
}
} }
} }
@ -1696,6 +1726,11 @@ sub pandora_process_module ($$$$$$$$$;$) {
generate_status_event ($pa_config, $processed_data, $agent, $module, $known_status, $status, $known_status, $dbh); generate_status_event ($pa_config, $processed_data, $agent, $module, $known_status, $status, $known_status, $dbh);
$status = $known_status; $status = $known_status;
# reset counters because change status.
$ff_normal = 0;
$ff_critical = 0;
$ff_warning = 0;
# Update module status count. # Update module status count.
$mark_for_update = 1; $mark_for_update = 1;
} }