diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 209cacf4e0..b2ce5ee3d1 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,7 @@ +2010-02-25 Sancho Lerena + + * lib/PandoraFMS/Core.pm: Implemented new alert type "onChange". + 2010-02-25 Pablo de la ConcepciĆ³n * conf/pandora_server.conf: New option, update_parent to let the diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3f376edbd4..8ed4b36d65 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -157,14 +157,14 @@ our @ServerTypes = qw (dataserver networkserver snmpconsole reconserver pluginse our @AlertStatus = ('Execute the alert', 'Do not execute the alert', 'Do not execute the alert, but increment its internal counter', 'Cease the alert', 'Recover the alert', 'Reset internal counter'); ########################################################################## -=head2 C<< pandora_generate_alerts (I<$pa_config> I<$data> I<$status> I<$agent> I<$module> I<$utimestamp> I<$dbh>) >> +=head2 C<< pandora_generate_alerts (I<$pa_config> I<$data> I<$status> I<$agent> I<$module> I<$utimestamp> I<$dbh> I<$extraMacros> I<$last_data_value>) >> Generate alerts for a given I<$module>. =cut ########################################################################## -sub pandora_generate_alerts ($$$$$$$;$) { - my ($pa_config, $data, $status, $agent, $module, $utimestamp, $dbh, $extraMacros) = @_; +sub pandora_generate_alerts ($$$$$$$;$$) { + my ($pa_config, $data, $status, $agent, $module, $utimestamp, $dbh, $extraMacros, $last_data_value) = @_; # Do not generate alerts for disabled groups if (is_group_disabled ($dbh, $agent->{'id_grupo'})) { @@ -180,7 +180,7 @@ sub pandora_generate_alerts ($$$$$$$;$) { foreach my $alert (@alerts) { my $rc = pandora_evaluate_alert($pa_config, $agent, $data, $status, $alert, - $utimestamp, $dbh); + $utimestamp, $dbh, $last_data_value); pandora_process_alert ($pa_config, $data, $agent, $module, $alert, $rc, $dbh, $extraMacros); @@ -208,7 +208,7 @@ B: =cut ########################################################################## sub pandora_evaluate_alert ($$$$$$$) { - my ($pa_config, $agent, $data, $last_status, $alert, $utimestamp, $dbh) = @_; + my ($pa_config, $agent, $data, $last_status, $alert, $utimestamp, $dbh, $last_data_value) = @_; logger ($pa_config, "Evaluating alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "'.", 10); @@ -263,6 +263,19 @@ sub pandora_evaluate_alert ($$$$$$$) { $data <= $alert->{'max_value'}); } } + + if ($alert->{'type'} eq "onchange") { + + if (is_numeric($last_data_value)){ + if ($last_data_value == $data){ + return $status; + } + } else { + if ($last_data_value eq $data){ + return $status; + } + } + } return $status if ($alert->{'type'} eq "equal" && $data != $alert->{'value'}); return $status if ($alert->{'type'} eq "not_equal" && $data == $alert->{'value'}); @@ -701,6 +714,7 @@ sub pandora_process_module ($$$$$$$$$;$) { my $last_status = $agent_status->{'last_status'}; my $status = $agent_status->{'estado'}; my $status_changes = $agent_status->{'status_changes'}; + my $last_data_value = $agent_status->{'datos'}; # Get new status my $new_status = get_module_status ($processed_data, $module, $module_type); @@ -722,7 +736,7 @@ sub pandora_process_module ($$$$$$$$$;$) { # Generate alerts if (pandora_inhibit_alerts ($pa_config, $agent, $dbh) == 0) { - pandora_generate_alerts ($pa_config, $processed_data, $status, $agent, $module, $utimestamp, $dbh, $extraMacros); + pandora_generate_alerts ($pa_config, $processed_data, $status, $agent, $module, $utimestamp, $dbh, $extraMacros, $last_data_value); } # tagente_estado.last_try defaults to NULL, should default to '0000-00-00 00:00:00'