mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
parent
bd610a74b1
commit
87bcb168d7
@ -102,6 +102,10 @@ void ApiClient::Disconnect(void)
|
|||||||
|
|
||||||
if (m_Endpoint)
|
if (m_Endpoint)
|
||||||
m_Endpoint->RemoveClient(GetSelf());
|
m_Endpoint->RemoveClient(GetSelf());
|
||||||
|
else {
|
||||||
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
||||||
|
listener->RemoveAnonymousClient(GetSelf());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ApiClient::ProcessMessage(void)
|
bool ApiClient::ProcessMessage(void)
|
||||||
@ -194,6 +198,21 @@ void ApiClient::KeepAliveTimerHandler(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
||||||
|
|
||||||
|
if (listener) {
|
||||||
|
double timeout = now - 60;
|
||||||
|
|
||||||
|
BOOST_FOREACH(const ApiClient::Ptr& client, listener->GetAnonymousClients()) {
|
||||||
|
if (client->m_Seen < timeout) {
|
||||||
|
Log(LogInformation, "remote", "Closing connection with inactive anonymous endpoint '" + client->GetIdentity() + "'");
|
||||||
|
client->Disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Value SetLogPositionHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
Value SetLogPositionHandler(const MessageOrigin& origin, const Dictionary::Ptr& params)
|
||||||
|
@ -205,12 +205,15 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, ConnectionRole rol
|
|||||||
|
|
||||||
Endpoint::Ptr endpoint = Endpoint::GetByName(identity);
|
Endpoint::Ptr endpoint = Endpoint::GetByName(identity);
|
||||||
|
|
||||||
|
bool need_sync;
|
||||||
|
|
||||||
|
if (endpoint)
|
||||||
|
need_sync = !endpoint->IsConnected();
|
||||||
|
|
||||||
|
ApiClient::Ptr aclient = make_shared<ApiClient>(identity, tlsStream, role);
|
||||||
|
aclient->Start();
|
||||||
|
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
bool need_sync = !endpoint->IsConnected();
|
|
||||||
|
|
||||||
ApiClient::Ptr aclient = make_shared<ApiClient>(identity, tlsStream, role);
|
|
||||||
aclient->Start();
|
|
||||||
|
|
||||||
if (need_sync) {
|
if (need_sync) {
|
||||||
{
|
{
|
||||||
ObjectLock olock(endpoint);
|
ObjectLock olock(endpoint);
|
||||||
@ -222,7 +225,8 @@ void ApiListener::NewClientHandler(const Socket::Ptr& client, ConnectionRole rol
|
|||||||
}
|
}
|
||||||
|
|
||||||
endpoint->AddClient(aclient);
|
endpoint->AddClient(aclient);
|
||||||
}
|
} else
|
||||||
|
AddAnonymousClient(aclient);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApiListener::ApiTimerHandler(void)
|
void ApiListener::ApiTimerHandler(void)
|
||||||
@ -645,3 +649,21 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus(void)
|
|||||||
|
|
||||||
return std::make_pair(status, perfdata);
|
return std::make_pair(status, perfdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApiListener::AddAnonymousClient(const ApiClient::Ptr& aclient)
|
||||||
|
{
|
||||||
|
ObjectLock olock(this);
|
||||||
|
m_AnonymousClients.insert(aclient);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApiListener::RemoveAnonymousClient(const ApiClient::Ptr& aclient)
|
||||||
|
{
|
||||||
|
ObjectLock olock(this);
|
||||||
|
m_AnonymousClients.erase(aclient);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<ApiClient::Ptr> ApiListener::GetAnonymousClients(void) const
|
||||||
|
{
|
||||||
|
ObjectLock olock(this);
|
||||||
|
return m_AnonymousClients;
|
||||||
|
}
|
@ -64,6 +64,10 @@ public:
|
|||||||
static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
|
static Value StatsFunc(Dictionary::Ptr& status, Dictionary::Ptr& perfdata);
|
||||||
std::pair<Dictionary::Ptr, Dictionary::Ptr> GetStatus(void);
|
std::pair<Dictionary::Ptr, Dictionary::Ptr> GetStatus(void);
|
||||||
|
|
||||||
|
void AddAnonymousClient(const ApiClient::Ptr& aclient);
|
||||||
|
void RemoveAnonymousClient(const ApiClient::Ptr& aclient);
|
||||||
|
std::set<ApiClient::Ptr> GetAnonymousClients(void) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnConfigLoaded(void);
|
virtual void OnConfigLoaded(void);
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
@ -71,6 +75,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
shared_ptr<SSL_CTX> m_SSLContext;
|
shared_ptr<SSL_CTX> m_SSLContext;
|
||||||
std::set<TcpSocket::Ptr> m_Servers;
|
std::set<TcpSocket::Ptr> m_Servers;
|
||||||
|
std::set<ApiClient::Ptr> m_AnonymousClients;
|
||||||
Timer::Ptr m_Timer;
|
Timer::Ptr m_Timer;
|
||||||
|
|
||||||
void ApiTimerHandler(void);
|
void ApiTimerHandler(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user