diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 8a5f087f9..6af6267b4 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -1565,16 +1565,50 @@ void ApiListener::ReplayLog(const JsonRpcConnection::Ptr& client) } if (last_sync) { - { - ObjectLock olock2(endpoint); - endpoint->SetSyncing(false); - } - OpenLogFile(); break; } } + + Log(LogNotice, "ApiListener") + << "Replaying log."; + + count = 0; + + for (auto& message : endpoint->GetReplayLog()) { + try { + client->SendRawMessage(message.second); + } catch (const std::exception& ex) { + Log(LogWarning, "ApiListener") + << "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex, false); + + Log(LogDebug, "ApiListener") + << "Error while replaying log for endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex); + + break; + } + + ++count; + + if (message.first > logpos_ts + 10) { + logpos_ts = message.first; + + client->SendMessage(new Dictionary({ + { "jsonrpc", "2.0" }, + { "method", "log::SetLogPosition" }, + { "params", new Dictionary({ + { "log_position", logpos_ts } + }) } + })); + } + } + + Log(count > 0u ? LogInformation : LogNotice, "ApiListener") + << "Replayed " << count << " messages."; + + ObjectLock olock2(endpoint); + endpoint->SetSyncing(false); } void ApiListener::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)