From 5731f640f81385cd16c1ad93a7adcd7f285a2e00 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Fri, 19 Nov 2010 10:48:27 +0000 Subject: [PATCH] 2010-11-19 Ramon Novoa * lib/PandoraFMS/Core.pm: Fixed regexp alerts. The patch to detect malformed regular expressions made them malfunction. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3603 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 5 +++++ pandora_server/lib/PandoraFMS/Core.pm | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 66371ab9a7..28f69ef82a 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2010-11-19 Ramon Novoa + + * lib/PandoraFMS/Core.pm: Fixed regexp alerts. The patch to detect + malformed regular expressions made them malfunction. + 2010-11-18 Ramon Novoa * lib/PandoraFMS/Core.pm, diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 66edc0bc65..81b9d3769e 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -298,16 +298,21 @@ sub pandora_evaluate_alert ($$$$$$$) { return $status if ($alert->{'type'} eq "equal" && $data != $alert->{'value'}); return $status if ($alert->{'type'} eq "not_equal" && $data == $alert->{'value'}); if ($alert->{'type'} eq "regex") { + + # Make sure the regexp is valid eval { local $SIG{'__DIE__'}; - if ($alert->{'matches_value'} == 1) { - return $status if ($data !~ m/$alert->{'value'}/i); - } else { - return $status if ($data =~ m/$alert->{'value'}/i); - } + $data =~ m/$alert->{'value'}/i; }; if ($@) { logger ($pa_config, "Error evaluating alert '" . $alert->{'name'} . "' for agent '" . $agent->{'nombre'} . "': '" . $alert->{'value'} . "' is not a valid regular expression.", 10); + return $status; + } + + if ($alert->{'matches_value'} == 1) { + return $status if ($data !~ m/$alert->{'value'}/i); + } else { + return $status if ($data =~ m/$alert->{'value'}/i); } }