1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #include "remote/jsonrpcconnection.hpp" 4 #include "remote/messageorigin.hpp" 5 #include "remote/apifunction.hpp" 6 #include "base/initialize.hpp" 7 #include "base/configtype.hpp" 8 #include "base/logger.hpp" 9 #include "base/utility.hpp" 10 #include <boost/asio/spawn.hpp> 11 #include <boost/date_time/posix_time/posix_time_duration.hpp> 12 #include <boost/system/system_error.hpp> 13 14 using namespace icinga; 15 16 REGISTER_APIFUNCTION(Heartbeat, event, &JsonRpcConnection::HeartbeatAPIHandler); 17 18 /** 19 * We still send a heartbeat without timeout here 20 * to keep the m_Seen variable up to date. This is to keep the 21 * cluster connection alive when there isn't much going on. 22 */ 23 HandleAndWriteHeartbeats(boost::asio::yield_context yc)24void JsonRpcConnection::HandleAndWriteHeartbeats(boost::asio::yield_context yc) 25 { 26 boost::system::error_code ec; 27 28 for (;;) { 29 m_HeartbeatTimer.expires_from_now(boost::posix_time::seconds(20)); 30 m_HeartbeatTimer.async_wait(yc[ec]); 31 32 if (m_ShuttingDown) { 33 break; 34 } 35 36 SendMessageInternal(new Dictionary({ 37 { "jsonrpc", "2.0" }, 38 { "method", "event::Heartbeat" }, 39 { "params", new Dictionary() } 40 })); 41 } 42 } 43 HeartbeatAPIHandler(const MessageOrigin::Ptr & origin,const Dictionary::Ptr & params)44Value JsonRpcConnection::HeartbeatAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params) 45 { 46 return Empty; 47 } 48 49