diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 1fb53307d4..a1898602de 100644 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -426,6 +426,8 @@ sub parse_conf_modules($) { $module->{'timeout'} = $1; } elsif ($line =~ /^\s*module_save\s+(\w+)$/) { $module->{'save'} = $1; + } elsif ($line =~ /^\s*module_alert_template\s+(.*)$/) { + $module->{'alert_template'} = $1; } elsif ($line =~ /^\s*module_condition\s+(.*)$/) { my $action = $1; # Numeric comparison @@ -1795,6 +1797,9 @@ sub write_module_xml ($@) { # Module FF interval $Xml .= " " . $module->{'module_ff_interval'} . "\n" if (defined ($module->{'module_ff_interval'})); + + # Module Alert template + $Xml .= " " . $module->{'alert_template'} . "\n" if (defined ($module->{'alert_template'})); # Data list if ($#data > 0) { @@ -2040,6 +2045,7 @@ sub init_module ($) { $module->{'quiet'} = undef; $module->{'module_ff_interval'} = undef; $module->{'macros'} = {}; + $module->{'alert_template'} = undef; } ################################################################################ diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm index 0ce085d2b6..04b8ffcb08 100644 --- a/pandora_server/lib/PandoraFMS/DataServer.pm +++ b/pandora_server/lib/PandoraFMS/DataServer.pm @@ -554,6 +554,9 @@ sub process_module_data ($$$$$$$$$) { } } + # Reload alert_template to get all alerts like an array + $module_conf->{'alert_template'} = get_tag_value ($data, 'alert_template', '', 1); + # Description XML tag and column name don't match $module_conf->{'descripcion'} = $module_conf->{'description'}; $module_conf->{'descripcion'} = '' unless defined ($module_conf->{'descripcion'}); @@ -652,14 +655,16 @@ sub process_module_data ($$$$$$$$$) { } } - # Assign alert-template if the spceicied one exists + # Assign alert-templates if exist if( $initial_alert_template ) { - my $id_alert_template = get_db_value ($dbh, - 'SELECT id FROM talert_templates WHERE talert_templates.name = ?', - safe_input($initial_alert_template) ); + foreach my $individual_template (@{$initial_alert_template}){ + my $id_alert_template = get_db_value ($dbh, + 'SELECT id FROM talert_templates WHERE talert_templates.name = ?', + safe_input($individual_template) ); - if( defined($id_alert_template) ) { - pandora_create_template_module ($pa_config, $dbh, $module->{'id_agente_modulo'}, $id_alert_template); + if( defined($id_alert_template) ) { + pandora_create_template_module ($pa_config, $dbh, $module->{'id_agente_modulo'}, $id_alert_template); + } } } } diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 9292db4acb..83818a71b1 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -619,11 +619,14 @@ sub print_message ($$$) { # Returns the value of an XML tag from a hash returned by XMLin (one level # depth). ########################################################################## -sub get_tag_value ($$$) { - my ($hash_ref, $tag, $def_value) = @_; +sub get_tag_value ($$$;$) { + my ($hash_ref, $tag, $def_value, $all_array) = @_; + $all_array = 0 unless defined ($all_array); return $def_value unless defined ($hash_ref->{$tag}) and ref ($hash_ref->{$tag}); + # If all array is required, returns the array + return $hash_ref->{$tag} if ($all_array == 1); # Return the first found value foreach my $value (@{$hash_ref->{$tag}}) {