Merge branch 'ent-5355-9422-9700-actualizacion-de-umbrales-mediante-xml' into 'develop'

Forced thresholds ENT

See merge request artica/pandorafms!3314
This commit is contained in:
Daniel Rodriguez 2020-08-14 09:22:47 +02:00
commit e5d4208ac9
3 changed files with 97 additions and 13 deletions

View File

@ -52,8 +52,10 @@ our @EXPORT = qw(
db_string
db_text
db_update
db_update_hash
db_update_get_values
set_update_agent
set_update_agentmodule
get_action_id
get_addr_id
get_agent_addr_id
@ -912,17 +914,21 @@ sub get_db_rows_limit ($$$;@) {
}
##########################################################################
## Updates agent fields using field => value
## Be careful, no filter is done.
## Updates using hashed data.
## $dbh database connector (active)
## $tablename table name
## $id hashref as { 'primary_key_id' => "value" }
## $data hashref as { 'field1' => "value", 'field2' => "value"}
##########################################################################
sub set_update_agent {
my ($dbh, $agent_id, $data) = @_;
sub db_update_hash {
my ($dbh, $tablename, $id, $data) = @_;
return undef unless (defined($tablename) && $tablename ne "");
return undef unless (defined($agent_id) && $agent_id > 0);
return undef unless (ref($data) eq "HASH");
# Build update query
my $query = 'UPDATE tagente SET ';
my $query = 'UPDATE `'.$tablename.'` SET ';
my @values;
foreach my $field (keys %{$data}) {
@ -933,12 +939,50 @@ sub set_update_agent {
chop($query);
$query .= ' WHERE id_agente = ? ';
push @values, $agent_id;
my @keys = keys %{$id};
my $k = shift @keys;
$query .= ' WHERE '.$k.' = ? ';
push @values, $id->{$k};
return db_update($dbh, $query, @values);
}
##########################################################################
## Updates agent fields using field => value
## Be careful, no filter is done.
##########################################################################
sub set_update_agent {
my ($dbh, $agent_id, $data) = @_;
return undef unless (defined($agent_id) && $agent_id > 0);
return undef unless (ref($data) eq "HASH");
return db_update_hash(
$dbh,
'tagente',
{ 'id_agente' => $agent_id },
$data
);
}
##########################################################################
## Updates agent fields using field => value
## Be careful, no filter is done.
##########################################################################
sub set_update_agentmodule {
my ($dbh, $agentmodule_id, $data) = @_;
return undef unless (defined($agentmodule_id) && $agentmodule_id > 0);
return undef unless (ref($data) eq "HASH");
return db_update_hash(
$dbh,
'tagente_modulo',
{ 'id_agente_modulo' => $agentmodule_id },
$data
);
}
##########################################################################
## SQL delete with a LIMIT clause.

View File

@ -633,6 +633,9 @@ sub process_module_data ($$$$$$$$$$) {
# Get module parameters, matching column names in tagente_modulo
my $module_conf;
# Extra usable fields but not supported at DB level.
my $extra = {};
# Supported tags
my $tags = {'name' => 0, 'data' => 0, 'type' => 0, 'description' => 0, 'max' => 0,
'min' => 0, 'descripcion' => 0, 'post_process' => 0, 'module_interval' => 0, 'min_critical' => 0,
@ -642,7 +645,9 @@ sub process_module_data ($$$$$$$$$$) {
'unknown_instructions' => '', 'tags' => '', 'critical_inverse' => 0, 'warning_inverse' => 0, 'quiet' => 0,
'module_ff_interval' => 0, 'alert_template' => '', 'crontab' => '', 'min_ff_event_normal' => 0,
'min_ff_event_warning' => 0, 'min_ff_event_critical' => 0, 'ff_timeout' => 0, 'each_ff' => 0, 'module_parent' => 0,
'module_parent_unlink' => 0, 'cron_interval' => 0, 'ff_type' => 0};
'module_parent_unlink' => 0, 'cron_interval' => 0, 'ff_type' => 0, 'min_warning_forced' => 0, 'max_warning_forced' => 0,
'min_critical_forced' => 0, 'max_critical_forced' => 0, 'str_warning_forced' => 0, 'str_critical_forced' => 0
};
# Other tags will be saved here
$module_conf->{'extended_info'} = '';
@ -693,6 +698,14 @@ sub process_module_data ($$$$$$$$$$) {
$module_conf->{'disabled_types_event'} = '' unless defined ($module_conf->{'disabled_types_event'});
$module_conf->{'module_macros'} = '' unless defined ($module_conf->{'module_macros'});
# Extract extra fields.
foreach my $pk (keys %{$module_conf}) {
if ($pk =~ /_forced$/) {
$extra->{$pk} = $module_conf->{$pk};
delete $module_conf->{$pk};
}
}
# Get module data or create it if it does not exist
my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente = ? AND ' . db_text ('nombre') . ' = ?', $agent->{'id_agente'}, safe_input($module_name));
if (! defined ($module)) {
@ -825,7 +838,13 @@ sub process_module_data ($$$$$$$$$$) {
# Update module configuration if in learning mode and not a policy module
if ((($agent->{'modo'} eq '1') || ($agent->{'modo'} eq '2')) && $policy_linked == 0) {
update_module_configuration ($pa_config, $dbh, $module, $module_conf);
update_module_configuration(
$pa_config,
$dbh,
$module,
$module_conf,
$extra
);
}
# Module disabled!
@ -898,8 +917,8 @@ sub get_macros_for_data($$){
##########################################################################
# Update module configuration in tagente_modulo if necessary.
##########################################################################
sub update_module_configuration ($$$$) {
my ($pa_config, $dbh, $module, $module_conf) = @_;
sub update_module_configuration ($$$$$) {
my ($pa_config, $dbh, $module, $module_conf, $extra) = @_;
# Update if at least one of the configuration tokens has changed
foreach my $conf_token ('descripcion', 'extended_info', 'module_interval') {
@ -917,6 +936,9 @@ sub update_module_configuration ($$$$) {
$module->{'extended_info'} = $module_conf->{'extended_info'} if (defined($module_conf->{'extended_info'})) ;
$module->{'descripcion'} = ($module_conf->{'descripcion'} eq '') ? $module->{'descripcion'} : $module_conf->{'descripcion'};
$module->{'module_interval'} = ($module_conf->{'module_interval'} eq '') ? $module->{'module_interval'} : $module_conf->{'module_interval'};
# Enterprise updates.
enterprise_hook('update_module_fields', [$dbh, $pa_config, $module, $extra]);
}
###############################################################################

View File

@ -672,6 +672,24 @@ sub print_module {
if (! (empty ($data->{warning_inverse}))) {
$xml_module .= "\t<warning_inverse><![CDATA[" . $data->{warning_inverse} . "]]></warning_inverse>\n";
}
if (! (empty($data->{min_warning})) ) {
$xml_module .= "\t<min_warning_forced><![CDATA[" . $data->{min_warning_forced} . "]]></min_warning_forced>\n";
}
if (! (empty($data->{max_warning})) ) {
$xml_module .= "\t<max_warning_forced><![CDATA[" . $data->{max_warning_forced} . "]]></max_warning_forced>\n";
}
if (! (empty ($data->{min_critical})) ) {
$xml_module .= "\t<min_critical_forced><![CDATA[" . $data->{min_critical_forced} . "]]></min_critical_forced>\n";
}
if (! (empty ($data->{max_critical})) ){
$xml_module .= "\t<max_critical_forced><![CDATA[" . $data->{max_critical_forced} . "]]></max_critical_forced>\n";
}
if (! (empty ($data->{str_warning}))) {
$xml_module .= "\t<str_warning_forced><![CDATA[" . $data->{str_warning_forced} . "]]></str_warning_forced>\n";
}
if (! (empty ($data->{str_critical}))) {
$xml_module .= "\t<str_critical_forced><![CDATA[" . $data->{str_critical_forced} . "]]></str_critical_forced>\n";
}
if (! (empty ($data->{max}))) {
$xml_module .= "\t<max><![CDATA[" . $data->{max} . "]]></max>\n";
}