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;
|
$module->{'timeout'} = $1;
|
||||||
} elsif ($line =~ /^\s*module_save\s+(\w+)$/) {
|
} elsif ($line =~ /^\s*module_save\s+(\w+)$/) {
|
||||||
$module->{'save'} = $1;
|
$module->{'save'} = $1;
|
||||||
|
} elsif ($line =~ /^\s*module_alert_template\s+(.*)$/) {
|
||||||
|
$module->{'alert_template'} = $1;
|
||||||
} elsif ($line =~ /^\s*module_condition\s+(.*)$/) {
|
} elsif ($line =~ /^\s*module_condition\s+(.*)$/) {
|
||||||
my $action = $1;
|
my $action = $1;
|
||||||
# Numeric comparison
|
# Numeric comparison
|
||||||
|
@ -1796,6 +1798,9 @@ sub write_module_xml ($@) {
|
||||||
# Module FF interval
|
# Module FF interval
|
||||||
$Xml .= " <module_ff_interval>" . $module->{'module_ff_interval'} . "</module_ff_interval>\n" if (defined ($module->{'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
|
# Data list
|
||||||
if ($#data > 0) {
|
if ($#data > 0) {
|
||||||
$Xml .= " <data><![CDATA[" . join('', @data) . "]]></data>\n";
|
$Xml .= " <data><![CDATA[" . join('', @data) . "]]></data>\n";
|
||||||
|
@ -2040,6 +2045,7 @@ sub init_module ($) {
|
||||||
$module->{'quiet'} = undef;
|
$module->{'quiet'} = undef;
|
||||||
$module->{'module_ff_interval'} = undef;
|
$module->{'module_ff_interval'} = undef;
|
||||||
$module->{'macros'} = {};
|
$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
|
# Description XML tag and column name don't match
|
||||||
$module_conf->{'descripcion'} = $module_conf->{'description'};
|
$module_conf->{'descripcion'} = $module_conf->{'description'};
|
||||||
$module_conf->{'descripcion'} = '' unless defined ($module_conf->{'descripcion'});
|
$module_conf->{'descripcion'} = '' unless defined ($module_conf->{'descripcion'});
|
||||||
|
@ -652,17 +655,19 @@ sub process_module_data ($$$$$$$$$) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assign alert-template if the spceicied one exists
|
# Assign alert-templates if exist
|
||||||
if( $initial_alert_template ) {
|
if( $initial_alert_template ) {
|
||||||
|
foreach my $individual_template (@{$initial_alert_template}){
|
||||||
my $id_alert_template = get_db_value ($dbh,
|
my $id_alert_template = get_db_value ($dbh,
|
||||||
'SELECT id FROM talert_templates WHERE talert_templates.name = ?',
|
'SELECT id FROM talert_templates WHERE talert_templates.name = ?',
|
||||||
safe_input($initial_alert_template) );
|
safe_input($individual_template) );
|
||||||
|
|
||||||
if( defined($id_alert_template) ) {
|
if( defined($id_alert_template) ) {
|
||||||
pandora_create_template_module ($pa_config, $dbh, $module->{'id_agente_modulo'}, $id_alert_template);
|
pandora_create_template_module ($pa_config, $dbh, $module->{'id_agente_modulo'}, $id_alert_template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
# Control NULL columns
|
# Control NULL columns
|
||||||
$module->{'descripcion'} = '' unless defined ($module->{'descripcion'});
|
$module->{'descripcion'} = '' unless defined ($module->{'descripcion'});
|
||||||
|
|
|
@ -619,11 +619,14 @@ sub print_message ($$$) {
|
||||||
# Returns the value of an XML tag from a hash returned by XMLin (one level
|
# Returns the value of an XML tag from a hash returned by XMLin (one level
|
||||||
# depth).
|
# depth).
|
||||||
##########################################################################
|
##########################################################################
|
||||||
sub get_tag_value ($$$) {
|
sub get_tag_value ($$$;$) {
|
||||||
my ($hash_ref, $tag, $def_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});
|
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
|
# Return the first found value
|
||||||
foreach my $value (@{$hash_ref->{$tag}}) {
|
foreach my $value (@{$hash_ref->{$tag}}) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue