From 7ee00ca3541f8bb6eec686542eb1c1deadeb33ae Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 20 Jan 2009 23:42:21 +0000 Subject: [PATCH] 2009-01-21 Ramon Novoa * lib/PandoraFMS/DB.pm: Take into account the alert option 'matches_value'. * bin/pandora_server: Added support for forced alert execution. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1373 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 7 +++++++ pandora_server/bin/pandora_server | 28 ++++++++++++++++++++++++++++ pandora_server/lib/PandoraFMS/DB.pm | 25 +++++++++++++++++++------ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 935f97bb73..0959aa3119 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,10 @@ +2009-01-21 Ramon Novoa + + * lib/PandoraFMS/DB.pm: Take into account the alert option + 'matches_value'. + + * bin/pandora_server: Added support for forced alert execution. + 2009-01-20 Sancho Lerena * Config.pm: Now works without breaking the server :-). Show verbose info diff --git a/pandora_server/bin/pandora_server b/pandora_server/bin/pandora_server index 6e112e19dc..dd7d20fcdf 100755 --- a/pandora_server/bin/pandora_server +++ b/pandora_server/bin/pandora_server @@ -95,6 +95,8 @@ while (1) { pandora_serverkeepaliver (\%pa_config, 0, $dbh); # Disabled until we can finish code from editor and update server code pandora_planned_downtime (\%pa_config, $dbh); + # Ececute forced alerts + pandora_exec_forced_alerts (\%pa_config, $dbh); keep_alive_check (\%pa_config, $dbh); threads->yield; sleep ($pa_config{"server_threshold"}); @@ -451,3 +453,29 @@ sub process_module_data { logger($pa_config, "ERROR: Received data from an unknown module ($tipo_modulo)", 2); } } + +########################################################################## +## SUB pandora_exec_forced_alerts ($pa_config, $dbh) +## Execute forced alerts. +########################################################################## + +sub pandora_exec_forced_alerts { + my $pa_config = $_[0]; + my $dbh = $_[1]; + + # Get alerts marked for forced execution (even disabled alerts) + my @alerts = get_db_all_rows ("SELECT talert_template_modules.id as id_template_module, talert_template_modules.*, talert_templates.*, tagente.* + FROM talert_template_modules, talert_templates, tagente, tagente_modulo + WHERE talert_template_modules.id_alert_template = talert_templates.id + AND talert_template_modules.id_agent_module = tagente_modulo.id_agente_modulo + AND tagente_modulo.id_agente = tagente.id_agente + AND force_execution = 1", $dbh); + + foreach my $alert (@alerts) { + execute_alert ($pa_config, $alert, $alert->{'id_agente'}, $alert->{'id_grupo'}, $alert->{'nombre'}, + '', 1, $dbh); + + # Reset the force_execution flag, even if the alert could not be executed + db_do ("UPDATE talert_template_modules SET force_execution = 0 WHERE id = " . $alert->{'id_template_module'}, $dbh); + } +} diff --git a/pandora_server/lib/PandoraFMS/DB.pm b/pandora_server/lib/PandoraFMS/DB.pm index acc1d573b1..0e8e2d58c1 100644 --- a/pandora_server/lib/PandoraFMS/DB.pm +++ b/pandora_server/lib/PandoraFMS/DB.pm @@ -223,10 +223,17 @@ sub pandora_evaluate_alert (%$%$$$) { elsif ($alert_data->{'type'} eq "max" && $module_data <= $alert_data->{'max_value'}) { return $status; } - elsif ($alert_data->{'type'} eq "max_min" - && $module_data >= $alert_data->{'min_value'} - && $module_data <= $alert_data->{'max_value'}) { - return $status; + elsif ($alert_data->{'type'} eq "max_min") { + if ($alert_data->{'matches_value'} == 1 && + $module_data <= $alert_data->{'min_value'} && + $module_data >= $alert_data->{'max_value'}) { + return $status; + } + + if ($module_data >= $alert_data->{'min_value'} && + $module_data <= $alert_data->{'max_value'}) { + return $status; + } } elsif ($alert_data->{'type'} eq "equal" && $module_data == $alert_data->{'value'}) { return $status; @@ -234,8 +241,14 @@ sub pandora_evaluate_alert (%$%$$$) { elsif ($alert_data->{'type'} eq "not_equal" && $module_data != $alert_data->{'value'}) { return $status; } - elsif ($alert_data->{'type'} eq "regex" && $module_data !~ m/$alert_data->{'alert_text'}/i) { - return $status; + elsif ($alert_data->{'type'} eq "regex") { + if ($alert_data->{'matches_value'} == 1 && $module_data =~ m/$alert_data->{'alert_text'}/i) { + return $status; + } + + if ($module_data !~ m/$alert_data->{'alert_text'}/i) { + return $status; + } } #if ($id_module_type == -1) {