2026-01-27 09:06:40 -05:00
|
|
|
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-12-09 07:17:27 -05:00
|
|
|
|
2015-06-22 05:11:21 -04:00
|
|
|
#include "remote/jsonrpcconnection.hpp"
|
2014-12-09 07:17:27 -05:00
|
|
|
#include "remote/messageorigin.hpp"
|
|
|
|
|
#include "remote/apifunction.hpp"
|
|
|
|
|
#include "base/initialize.hpp"
|
2015-08-15 14:28:05 -04:00
|
|
|
#include "base/configtype.hpp"
|
2014-12-10 03:56:32 -05:00
|
|
|
#include "base/logger.hpp"
|
2015-03-28 06:04:42 -04:00
|
|
|
#include "base/utility.hpp"
|
2019-02-20 06:28:49 -05:00
|
|
|
#include <boost/asio/spawn.hpp>
|
|
|
|
|
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
2019-06-05 04:32:20 -04:00
|
|
|
#include <boost/system/system_error.hpp>
|
2014-12-09 07:17:27 -05:00
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
2015-06-22 05:11:21 -04:00
|
|
|
REGISTER_APIFUNCTION(Heartbeat, event, &JsonRpcConnection::HeartbeatAPIHandler);
|
2014-12-09 07:17:27 -05:00
|
|
|
|
2020-07-08 08:14:07 -04:00
|
|
|
/**
|
|
|
|
|
* We still send a heartbeat without timeout here
|
|
|
|
|
* to keep the m_Seen variable up to date. This is to keep the
|
|
|
|
|
* cluster connection alive when there isn't much going on.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-20 06:28:49 -05:00
|
|
|
void JsonRpcConnection::HandleAndWriteHeartbeats(boost::asio::yield_context yc)
|
|
|
|
|
{
|
2019-06-05 04:32:20 -04:00
|
|
|
boost::system::error_code ec;
|
2019-02-20 06:28:49 -05:00
|
|
|
|
|
|
|
|
for (;;) {
|
2020-07-09 07:16:48 -04:00
|
|
|
m_HeartbeatTimer.expires_from_now(boost::posix_time::seconds(20));
|
2019-06-05 04:32:20 -04:00
|
|
|
m_HeartbeatTimer.async_wait(yc[ec]);
|
2019-02-20 06:28:49 -05:00
|
|
|
|
|
|
|
|
if (m_ShuttingDown) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-08 08:14:07 -04:00
|
|
|
|
|
|
|
|
SendMessageInternal(new Dictionary({
|
|
|
|
|
{ "jsonrpc", "2.0" },
|
|
|
|
|
{ "method", "event::Heartbeat" },
|
|
|
|
|
{ "params", new Dictionary() }
|
|
|
|
|
}));
|
2019-02-20 06:28:49 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 07:31:01 -05:00
|
|
|
Value JsonRpcConnection::HeartbeatAPIHandler(const MessageOrigin::Ptr&, [[maybe_unused]] const Dictionary::Ptr& params)
|
2014-12-09 07:17:27 -05:00
|
|
|
{
|
2014-12-09 09:07:49 -05:00
|
|
|
return Empty;
|
2014-12-09 07:17:27 -05:00
|
|
|
}
|