From c693c172058ea6072bd4eaefb497f73dcaf8249a Mon Sep 17 00:00:00 2001 From: slerena Date: Mon, 28 Sep 2009 15:53:06 +0000 Subject: [PATCH] 2009-09-28 Sancho Lerena * lib/PandoraFMS/Config.pm: Updatged build. * lib/PandoraFMS/Core.pm: Added new macro fields for alerts: id_agent, alert_priority, alert name and module name. Also fixed a problem in macro substitution when recursive fields was used. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1986 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 9 +++++++++ pandora_server/lib/PandoraFMS/Config.pm | 2 +- pandora_server/lib/PandoraFMS/Core.pm | 20 +++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index afc29fb192..e54c8433dc 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,12 @@ +2009-09-28 Sancho Lerena + + * lib/PandoraFMS/Config.pm: Updatged build. + + * lib/PandoraFMS/Core.pm: Added new macro fields for alerts: + id_agent, alert_priority, alert name and module name. Also + fixed a problem in macro substitution when recursive fields + was used. + 2009-09-25 Sancho Lerena * pandora_server.spec: Some fixes to SUSE RPM. diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm index f906107c6c..cd0b7df19d 100644 --- a/pandora_server/lib/PandoraFMS/Config.pm +++ b/pandora_server/lib/PandoraFMS/Config.pm @@ -37,7 +37,7 @@ our @EXPORT = qw( # version: Defines actual version of Pandora Server for this module only my $pandora_version = "3.0-dev"; -my $pandora_build = "PS090915"; +my $pandora_build = "PS090928"; our $VERSION = $pandora_version." ".$pandora_build; # Setup hash diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 4472d803e3..80ba7d2391 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -395,7 +395,7 @@ sub pandora_execute_alert ($$$$$$$) { # Execute actions foreach my $action (@actions) { logger($pa_config, "Alert (" . $alert->{'name'} . ") executed for agent " . $agent->{'nombre'}, 2); - pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $dbh); + pandora_execute_action ($pa_config, $data, $agent, $alert, $alert_mode, $action, $module, $dbh); } # Generate an event @@ -409,9 +409,9 @@ sub pandora_execute_alert ($$$$$$$) { ########################################################################## # Execute the given action. ########################################################################## -sub pandora_execute_action ($$$$$$$) { +sub pandora_execute_action ($$$$$$$$) { my ($pa_config, $data, $agent, $alert, - $alert_mode, $action, $dbh) = @_; + $alert_mode, $action, $module, $dbh) = @_; my $field1 = $action->{'field1'} ne "" ? $action->{'field1'} : $alert->{'field1'}; my $field2 = $action->{'field2'} ne "" ? $action->{'field2'} : $alert->{'field2'}; @@ -427,23 +427,31 @@ sub pandora_execute_action ($$$$$$$) { $field2 = decode_entities ($field2); $field3 = decode_entities ($field3); + # Thanks to people of Cordoba univ. for the patch for adding module and + # id_agent macros to the alert. + # Alert macros my %macros = (_field1_ => $field1, _field2_ => $field2, _field3_ => $field3, _agent_ => (defined ($agent)) ? $agent->{'nombre'} : '', _address_ => (defined ($agent)) ? $agent->{'direccion'} : '', - _timestamp_ => localtime(), + _timestamp_ => strftime ("%Y-%m-%d %H:%M:%S", localtime()), _data_ => $data, + _alert_ => $alert->{'name'}, _alert_description_ => $alert->{'description'}, _alert_threshold_ => $alert->{'time_threshold'}, _alert_times_fired_ => $alert->{'times_fired'}, + _alert_priority_ => $alert->{'priority'}, + _module_ => (defined ($module)) ? $module->{'nombre'} : '', + _id_agent_ => (defined ($agent)) ? $module->{'id_agente'} : '', ); # User defined alerts if ($action->{'internal'} == 0) { my $command = decode_entities(subst_alert_macros ($action->{'command'}, \%macros)); + $command = subst_alert_macros ($command, \%macros); eval { system ($command); @@ -458,7 +466,9 @@ sub pandora_execute_action ($$$$$$$) { # Internal Audit } elsif ($action->{'name'} eq "Internal Audit") { + $field1 = subst_alert_macros ($field1, \%macros); + pandora_audit ($pa_config, $field1, defined ($agent) ? $agent->{'nombre'} : 'N/A', 'Alert (' . $alert->{'description'} . ')', $dbh); # Email @@ -917,7 +927,7 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$) { WHERE talert_actions.id_alert_command = talert_commands.id AND talert_actions.id = ?', $alert->{'id_alert'}); - pandora_execute_action ($pa_config, '', undef, \%alert, 1, $action, $dbh) if (defined ($action)); + pandora_execute_action ($pa_config, '', undef, \%alert, 1, $action, undef, $dbh) if (defined ($action)); # Generate an event pandora_event ($pa_config, "SNMP alert fired (" . $alert->{'description'} . ")",