UniFi and RMM sync (forum #3236): Site Manager device counts come from its list of sites instead of a request per site, a console is asked for its sites only when it has new ones, listing gets half a sync's time and finishes over later syncs, at least one linked site syncs each run, linking brings in only that site's devices, linking, Sync Now, Test and saving release the session so other pages don't wait, a 429 with a short wait is retried once and a longer one is reported plainly, and a console asked directly with more than 50 sites isn't asked for each site's count; 26.12.3 changelog

This commit is contained in:
johnnyq
2026-12-01 13:57:25 -05:00
parent abcd1a6fcf
commit 0b770dcdf0
5 changed files with 235 additions and 27 deletions

View File

@@ -73,12 +73,18 @@ if (isset($_POST['check_rmm_provider']) || isset($_POST['add_rmm_provider']) ||
flashAlert('<strong>' . escapeHtml($name) . '</strong> saved - it is off, so nothing is brought in');
redirect($back);
}
$test = rmmTest($provider);
// Asking it can take a while - the agent's other pages don't wait on it (rmmWithoutSession())
$test = rmmWithoutSession(function () use ($provider) {
$test = rmmTest($provider);
if ($test['ok']) {
rmmSync($provider, 0, 60);
}
return $test;
});
if (!$test['ok']) {
flashAlert('<strong>' . escapeHtml($name) . '</strong> saved, but it didn\'t answer: ' . escapeHtml($test['text']), 'warning');
redirect($back);
}
rmmSync($provider, 0, 60);
flashAlert('<strong>' . escapeHtml($name) . '</strong> saved. ' . escapeHtml($test['text']) . ($before ? '' : ' Now link its ' . $words['clients'] . ' to your clients.'));
redirect($back);
@@ -94,7 +100,9 @@ if (isset($_GET['test_rmm_provider'])) {
flashAlert('That provider or platform no longer exists.', 'error');
redirect('rmm_providers.php');
}
$test = rmmTest($provider);
$test = rmmWithoutSession(function () use ($provider) {
return rmmTest($provider);
});
flashAlert('<strong>' . escapeHtml(rmmProviderName($provider)) . '</strong> - ' . escapeHtml($test['text']), $test['ok'] ? 'success' : 'error');
redirect();
@@ -111,7 +119,9 @@ if (isset($_GET['sync_rmm'])) {
redirect();
}
set_time_limit(180);
$sync = rmmSync($provider, 0, 150);
$sync = rmmWithoutSession(function () use ($provider) {
return rmmSync($provider, 0, 150);
});
flashAlert('<strong>' . escapeHtml(rmmProviderName($provider)) . '</strong> ' . ($sync['ok'] ? 'synced - ' : 'didn\'t sync - ') . escapeHtml($sync['note']), $sync['ok'] ? 'success' : 'error');
redirect();
@@ -214,7 +224,10 @@ if (isset($_POST['link_rmm_client'])) {
$linked = $rmm_link_client($rmm_client, $client_id);
set_time_limit(180);
$sync = rmmSync(rmmProviderRow($rmm_client['rmm_client_provider_id']), intval($rmm_client['rmm_client_id']), 150);
// Its devices now - just its own; the agent's other pages don't wait on it
$sync = rmmWithoutSession(function () use ($rmm_client) {
return rmmSync(rmmProviderRow($rmm_client['rmm_client_provider_id']), intval($rmm_client['rmm_client_id']), 150);
});
$left = $linked['left'] ? '. The ' . ($linked['left'] === 1 ? 'asset' : $linked['left'] . ' assets') . ' brought in for <strong>' . escapeHtml($linked['before_name']) . '</strong> ' . ($linked['left'] === 1 ? 'stays there - archive it if it was' : 'stay there - archive them if they were') . ' never theirs.' : '';
flashAlert('<strong>' . escapeHtml($rmm_client['rmm_client_name']) . '</strong> linked to <strong>' . escapeHtml($linked['client_name']) . '</strong> - ' . escapeHtml($sync['note']) . $left, $sync['ok'] ? 'success' : 'warning');
redirect($back);
@@ -247,7 +260,9 @@ if (isset($_GET['link_rmm_suggested'])) {
$rmm_link_client(rmmClientRow($rmm_client_id), $client_id);
}
set_time_limit(180);
$sync = rmmSync($provider, count($suggestions) === 1 ? intval(array_key_first($suggestions)) : 0, 150);
$sync = rmmWithoutSession(function () use ($provider, $suggestions) {
return rmmSync($provider, count($suggestions) === 1 ? intval(array_key_first($suggestions)) : 0, 150);
});
flashAlert(count($suggestions) . ' ' . $words['client'] . (count($suggestions) === 1 ? '' : 's') . ' linked - ' . escapeHtml($sync['note']), $sync['ok'] ? 'success' : 'warning');
redirect($back);
@@ -292,7 +307,9 @@ if (isset($_GET['rmm_bring_back'])) {
$brought_networks = mysqli_affected_rows($mysqli);
}
set_time_limit(180);
$sync = rmmSync(rmmProviderRow($rmm_client['rmm_client_provider_id']), $rmm_client_id, 150);
$sync = rmmWithoutSession(function () use ($rmm_client, $rmm_client_id) {
return rmmSync(rmmProviderRow($rmm_client['rmm_client_provider_id']), $rmm_client_id, 150);
});
$words = rmmFamilyWords(rmmFamily($rmm_client));
$brought_words = implode(' and ', array_filter([$brought || !$brought_networks ? "$brought deleted device" . ($brought === 1 ? '' : 's') : '', $brought_networks ? "$brought_networks deleted network" . ($brought_networks === 1 ? '' : 's') : '']));
logAudit($words['audit'], "Edit", "$session_name brought back $brought_words of " . escapeSql(rmmProviderName($rmm_client) . " {$words['client']} {$rmm_client['rmm_client_name']}"), intval($rmm_client['rmm_client_client_id']), intval($rmm_client['rmm_client_provider_id']));