2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
#include "remote/jsonrpcconnection.hpp"
|
2014-12-09 13:17:27 +01:00
|
|
|
#include "remote/messageorigin.hpp"
|
|
|
|
#include "remote/apifunction.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configtype.hpp"
|
2014-12-10 09:56:32 +01:00
|
|
|
#include "base/logger.hpp"
|
2015-03-28 11:04:42 +01:00
|
|
|
#include "base/utility.hpp"
|
2019-02-20 12:28:49 +01:00
|
|
|
#include <boost/asio/spawn.hpp>
|
|
|
|
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
2019-06-05 10:32:20 +02:00
|
|
|
#include <boost/system/system_error.hpp>
|
2014-12-09 13:17:27 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2015-06-22 11:11:21 +02:00
|
|
|
REGISTER_APIFUNCTION(Heartbeat, event, &JsonRpcConnection::HeartbeatAPIHandler);
|
2014-12-09 13:17:27 +01:00
|
|
|
|
2020-07-08 14:14:07 +02: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 12:28:49 +01:00
|
|
|
void JsonRpcConnection::HandleAndWriteHeartbeats(boost::asio::yield_context yc)
|
|
|
|
{
|
2019-06-05 10:32:20 +02:00
|
|
|
boost::system::error_code ec;
|
2019-02-20 12:28:49 +01:00
|
|
|
|
|
|
|
for (;;) {
|
2020-07-09 13:16:48 +02:00
|
|
|
m_HeartbeatTimer.expires_from_now(boost::posix_time::seconds(20));
|
2019-06-05 10:32:20 +02:00
|
|
|
m_HeartbeatTimer.async_wait(yc[ec]);
|
2019-02-20 12:28:49 +01:00
|
|
|
|
|
|
|
if (m_ShuttingDown) {
|
|
|
|
break;
|
|
|
|
}
|
2020-07-08 14:14:07 +02:00
|
|
|
|
|
|
|
SendMessageInternal(new Dictionary({
|
|
|
|
{ "jsonrpc", "2.0" },
|
|
|
|
{ "method", "event::Heartbeat" },
|
|
|
|
{ "params", new Dictionary() }
|
|
|
|
}));
|
2019-02-20 12:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
Value JsonRpcConnection::HeartbeatAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
|
2014-12-09 13:17:27 +01:00
|
|
|
{
|
2014-12-09 15:07:49 +01:00
|
|
|
return Empty;
|
2014-12-09 13:17:27 +01:00
|
|
|
}
|
|
|
|
|