Merge branch 'ent-6464-Discovery-id_recon_server-no-cambia-si-no-existe' into 'develop'

Ent 6464 discovery id recon server no cambia si no existe

Closes pandora_enterprise#6464

See merge request artica/pandorafms!3788
This commit is contained in:
Daniel Rodriguez 2021-03-10 15:53:28 +00:00
commit 96d5555ed2
2 changed files with 39 additions and 1 deletions

View File

@ -606,7 +606,7 @@ class DiscoveryTaskList extends HTML
if (check_acl($config['id_user'], 0, 'AW')) {
$data[0] = '<span class="link" onclick="force_task(\'';
$data[0] .= ui_get_full_url(
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&server_id='.$id_server.'&force='.$task['id_rt']
'index.php?sec=gservers&sec2=godmode/servers/discovery&wiz=tasklist&server_id='.$task['id_recon_server'].'&force='.$task['id_rt']
);
$data[0] .= '\'';
if ($task['type'] == DISCOVERY_HOSTDEVICES) {

View File

@ -1055,6 +1055,9 @@ sub pandoradb_main ($$$) {
# Move SNMP modules back to the Enterprise server
enterprise_hook("claim_back_snmp_modules", [$dbh, $conf]);
# Check if there are discovery tasks with wrong id_recon_server
pandora_check_forgotten_discovery_tasks ($conf, $dbh);
# Recalculating dynamic intervals.
enterprise_hook("update_min_max", [$dbh, $conf]);
@ -1064,6 +1067,41 @@ sub pandoradb_main ($$$) {
log_message ('', "Ending at ". strftime ("%Y-%m-%d %H:%M:%S", localtime()) . "\n");
}
###############################################################################
# Check for discovery tasks configured with servers down
###############################################################################
sub pandora_check_forgotten_discovery_tasks {
my ($conf, $dbh) = @_;
log_message ('FORGOTTEN DISCOVERY TASKS', "Check for discovery tasks bound to inactive servers.");
my @discovery_tasks = get_db_rows ($dbh, 'SELECT id_rt, id_recon_server, name FROM trecon_task');
my $discovery_tasks_count = @discovery_tasks;
# End of the check (this server has not discovery tasks!).
if ($discovery_tasks_count eq 0) {
log_message('FORGOTTEN DISCOVERY TASKS', 'There are not defined discovery tasks. Skipping.');
return;
}
my $master_server = get_db_value ($dbh, 'SELECT id_server FROM tserver WHERE server_type = ? AND status != -1', DISCOVERYSERVER);
# Goes through all the tasks to check if any have the server down.
foreach my $task (@discovery_tasks) {
if ($task->{'id_recon_server'} ne $master_server) {
my $this_server_status = get_db_value ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $task->{'id_recon_server'});
if (!defined($this_server_status) || $this_server_status eq -1) {
my $updated_task = db_process_update ($dbh, 'trecon_task', { 'id_recon_server' => $master_server }, { 'id_rt' => $task->{'id_rt'} });
log_message('FORGOTTEN DISCOVERY TASKS', 'Updated discovery task '.$task->{'name'});
}
}
}
log_message('FORGOTTEN DISCOVERY TASKS', 'Step ended');
}
# Init
pandora_init_pdb(\%conf);