Added several alert_templates support TICKET: #3310
and agent reads module_alert_template in conf file
This commit is contained in:
parent
18e2eb54a0
commit
6ff8c09772
|
@ -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_ff_interval>" . $module->{'module_ff_interval'} . "</module_ff_interval>\n" if (defined ($module->{'module_ff_interval'}));
|
||||
|
||||
# Module Alert template
|
||||
$Xml .= " <alert_template>" . $module->{'alert_template'} . "</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;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}}) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue