mirror of https://github.com/Icinga/icinga2.git
Introduce Endpoint#icinga_version
... and set it to e.g. 21200 via icinga::Hello.
This commit is contained in:
parent
bbe0f2d8c4
commit
645dcbdc9e
|
@ -29,6 +29,8 @@
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
#include <boost/asio/ssl/context.hpp>
|
#include <boost/asio/ssl/context.hpp>
|
||||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||||
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
#include <boost/system/error_code.hpp>
|
#include <boost/system/error_code.hpp>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
@ -506,6 +508,20 @@ void ApiListener::NewClientHandler(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const auto l_AppVersionInt (([]() -> unsigned long {
|
||||||
|
auto appVersion (Application::GetAppVersion());
|
||||||
|
boost::regex rgx (R"EOF(^v?(\d+)\.(\d+)\.(\d+))EOF");
|
||||||
|
boost::smatch match;
|
||||||
|
|
||||||
|
if (!boost::regex_search(appVersion.GetData(), match, rgx)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 100u * 100u * boost::lexical_cast<unsigned long>(match[1].str())
|
||||||
|
+ 100u * boost::lexical_cast<unsigned long>(match[2].str())
|
||||||
|
+ boost::lexical_cast<unsigned long>(match[3].str());
|
||||||
|
})());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes a new client connection.
|
* Processes a new client connection.
|
||||||
*
|
*
|
||||||
|
@ -650,7 +666,9 @@ void ApiListener::NewClientHandlerInternal(
|
||||||
JsonRpc::SendMessage(client, new Dictionary({
|
JsonRpc::SendMessage(client, new Dictionary({
|
||||||
{ "jsonrpc", "2.0" },
|
{ "jsonrpc", "2.0" },
|
||||||
{ "method", "icinga::Hello" },
|
{ "method", "icinga::Hello" },
|
||||||
{ "params", new Dictionary() }
|
{ "params", new Dictionary({
|
||||||
|
{ "version", (double)l_AppVersionInt }
|
||||||
|
}) }
|
||||||
}), yc);
|
}), yc);
|
||||||
|
|
||||||
client->async_flush(yc);
|
client->async_flush(yc);
|
||||||
|
@ -683,6 +701,16 @@ void ApiListener::NewClientHandlerInternal(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstByte >= '0' && firstByte <= '9') {
|
if (firstByte >= '0' && firstByte <= '9') {
|
||||||
|
JsonRpc::SendMessage(client, new Dictionary({
|
||||||
|
{ "jsonrpc", "2.0" },
|
||||||
|
{ "method", "icinga::Hello" },
|
||||||
|
{ "params", new Dictionary({
|
||||||
|
{ "version", (double)l_AppVersionInt }
|
||||||
|
}) }
|
||||||
|
}), yc);
|
||||||
|
|
||||||
|
client->async_flush(yc);
|
||||||
|
|
||||||
ctype = ClientJsonRpc;
|
ctype = ClientJsonRpc;
|
||||||
} else {
|
} else {
|
||||||
ctype = ClientHttp;
|
ctype = ClientHttp;
|
||||||
|
@ -1607,6 +1635,18 @@ std::set<HttpServerConnection::Ptr> ApiListener::GetHttpClients() const
|
||||||
|
|
||||||
Value ApiListener::HelloAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
|
Value ApiListener::HelloAPIHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params)
|
||||||
{
|
{
|
||||||
|
if (origin) {
|
||||||
|
auto client (origin->FromClient);
|
||||||
|
|
||||||
|
if (client) {
|
||||||
|
auto endpoint (client->GetEndpoint());
|
||||||
|
|
||||||
|
if (endpoint) {
|
||||||
|
endpoint->SetIcingaVersion((double)params->Get("version"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Empty;
|
return Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ class Endpoint : ConfigObject
|
||||||
|
|
||||||
[state] Timestamp local_log_position;
|
[state] Timestamp local_log_position;
|
||||||
[state] Timestamp remote_log_position;
|
[state] Timestamp remote_log_position;
|
||||||
|
[state] "unsigned long" icinga_version {
|
||||||
|
default {{{ return 0; }}}
|
||||||
|
};
|
||||||
|
|
||||||
[no_user_modify] bool connecting;
|
[no_user_modify] bool connecting;
|
||||||
[no_user_modify] bool syncing;
|
[no_user_modify] bool syncing;
|
||||||
|
|
Loading…
Reference in New Issue