#8732 Added autoconfiguration scheduled 2

This commit is contained in:
Daniel Maya 2022-07-12 12:37:22 +02:00
parent 994c76a39b
commit 26cfde6687
1 changed files with 55 additions and 2 deletions

View File

@ -139,9 +139,12 @@ sub pandora_startup () {
# Start the policy queue thread.
start_server_thread(\&pandora_process_policy_queue, [\%Config]) if ($Config{'__enterprise_enabled'} == 1 && $Config{'policy_manager'} == 1);
# Start agent autoconfiguration thread.
start_server_thread(\&pandora_agent_autoconfiguration_scheduled, [\%Config]) if ($Config{'__enterprise_enabled'} == 1 && $Config{'autoconfigure_agents'} == 1);
pandora_audit (\%Config, $Config{'rb_product_name'} . ' Server Daemon starting', 'SYSTEM', 'System', $DBH);
# Load servers
if (!is_metaconsole(\%Config)) {
pandora_reset_server (\%Config, $DBH);
@ -308,6 +311,56 @@ sub pandora_stop_netflow_daemon () {
return 0;
}
sub pandora_agent_autoconfiguration_scheduled($) {
my $pa_config = shift;
my %pa_config = %{$pa_config};
my $dbh = db_connect ($pa_config{'dbengine'}, $pa_config{'dbname'}, $pa_config{'dbhost'}, $pa_config{'dbport'},
$pa_config{'dbuser'}, $pa_config{'dbpass'});
while ($THRRUN == 1) {
my @autoconfig = get_db_rows (
$dbh,
'SELECT *, DATE_FORMAT(DATE_ADD(periodically_time_from, INTERVAL 5 MINUTE), "%H:%i:%S") AS time_minutes FROM tautoconfig
WHERE executed = 0 AND type_execution LIKE "scheduled" AND disabled = 0'
);
# Get current time.
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time());
my $time = sprintf ("%.2d:%.2d:%.2d", $hour, $min, $sec);
foreach my $conf (@autoconfig) {
if (($conf->{'type_periodicity'} eq 'monthly' && $conf->{'periodically_day_from'} eq $mday) ||
($conf->{'type_periodicity'} eq 'weekly' && (($conf->{'sunday'} eq 1 && $wday eq 0) ||
($conf->{'monday'} eq 1 && $wday eq 1) || ($conf->{'tuesday'} eq 1 && $wday eq 2) ||
($conf->{'wednesday'} eq 1 && $wday eq 3) || ($conf->{'thursday'} eq 1 && $wday eq 4) ||
($conf->{'friday'} eq 1 && $wday eq 5) || ($conf->{'saturday'} eq 1 && $wday eq 6)))
) {
if ($time ge $conf->{'periodically_time_from'} && $time le $conf->{'time_minutes'}) {
# Get agents.
my @agents = get_db_rows(
$dbh,
'SELECT id_agente, alias, id_grupo, id_os, os_version, direccion, nombre AS agent_name FROM tagente
WHERE `disabled` = 0'
);
foreach my $agent (@agents) {
my $match = enterprise_hook('autoconf_evaluate_rules', [$pa_config, $dbh, $agent, $conf->{'id'}, $agent->{'id_agente'}, 1]);
if (defined($match) && $match > 0) {
enterprise_hook('autoconf_execute_actions', [$pa_config, $dbh, $agent->{'id_agente'}, $agent, $conf->{'id'}]);
}
}
}
}
}
sleep (300);
}
db_disconnect($dbh);
}
########################################################################################
# Additional tasks executed periodically by the Pandora FMS Server
########################################################################################