mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
parent
f5d40bab2d
commit
66aa874f7d
@ -37,52 +37,55 @@ REGISTER_SCRIPTFUNCTION(ClusterCheck, &ClusterCheckTask::ScriptFunc);
|
|||||||
|
|
||||||
CheckResult::Ptr ClusterCheckTask::ScriptFunc(const Service::Ptr&)
|
CheckResult::Ptr ClusterCheckTask::ScriptFunc(const Service::Ptr&)
|
||||||
{
|
{
|
||||||
double interval = Utility::GetTime() - Application::GetStartTime();
|
Dictionary::Ptr status;
|
||||||
|
|
||||||
if (interval > 60)
|
|
||||||
interval = 60;
|
|
||||||
|
|
||||||
double count_endpoints = 0;
|
|
||||||
std::vector<String> not_connected_endpoints;
|
|
||||||
std::vector<String> connected_endpoints;
|
|
||||||
|
|
||||||
BOOST_FOREACH(const ClusterListener::Ptr& cluster_listener, DynamicType::GetObjects<ClusterListener>()) {
|
BOOST_FOREACH(const ClusterListener::Ptr& cluster_listener, DynamicType::GetObjects<ClusterListener>()) {
|
||||||
String identity = cluster_listener->GetIdentity();
|
/* XXX there's only one cluster listener */
|
||||||
|
status = cluster_listener->GetClusterStatus();
|
||||||
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
|
|
||||||
count_endpoints++;
|
|
||||||
|
|
||||||
if(!endpoint->IsConnected() && endpoint->GetName() != identity)
|
|
||||||
not_connected_endpoints.push_back(endpoint->GetName());
|
|
||||||
else if(endpoint->IsConnected() && endpoint->GetName() != identity)
|
|
||||||
connected_endpoints.push_back(endpoint->GetName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(not_connected_endpoints.begin(), not_connected_endpoints.end());
|
String connected_endpoints = FormatArray(status->Get("conn_endpoints"));
|
||||||
std::sort(connected_endpoints.begin(), connected_endpoints.end());
|
String not_connected_endpoints = FormatArray(status->Get("not_conn_endpoints"));
|
||||||
|
|
||||||
|
/* remove unneeded perfdata */
|
||||||
|
status->Set("conn_endpoints", Empty);
|
||||||
|
status->Set("not_conn_endpoints", Empty);
|
||||||
|
|
||||||
ServiceState state = StateOK;
|
ServiceState state = StateOK;
|
||||||
String output = "Icinga 2 Cluster is running: Connected Endpoints: "+ Convert::ToString(connected_endpoints.size()) + " (" +
|
String output = "Icinga 2 Cluster is running: Connected Endpoints: "+ Convert::ToString(status->Get("num_conn_endpoints")) + " (" +
|
||||||
boost::algorithm::join(connected_endpoints, ",") + ").";
|
connected_endpoints + ").";
|
||||||
|
|
||||||
if (not_connected_endpoints.size() > 0) {
|
if (status->Get("num_not_conn_endpoints") > 0) {
|
||||||
state = StateCritical;
|
state = StateCritical;
|
||||||
output = "Icinga 2 Cluster Problem: " + Convert::ToString(not_connected_endpoints.size()) +
|
output = "Icinga 2 Cluster Problem: " + Convert::ToString(status->Get("num_not_conn_endpoints")) +
|
||||||
" Endpoints (" + boost::algorithm::join(not_connected_endpoints, ",") + ") not connected.";
|
" Endpoints (" + not_connected_endpoints + ") not connected.";
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr perfdata = make_shared<Dictionary>();
|
|
||||||
perfdata->Set("num_endpoints", count_endpoints);
|
|
||||||
perfdata->Set("num_conn_endpoints", connected_endpoints.size());
|
|
||||||
perfdata->Set("num_not_conn_endpoints", not_connected_endpoints.size());
|
|
||||||
|
|
||||||
CheckResult::Ptr cr = make_shared<CheckResult>();
|
CheckResult::Ptr cr = make_shared<CheckResult>();
|
||||||
cr->SetOutput(output);
|
cr->SetOutput(output);
|
||||||
cr->SetPerformanceData(perfdata);
|
cr->SetPerformanceData(status);
|
||||||
cr->SetState(state);
|
cr->SetState(state);
|
||||||
cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
|
cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName());
|
||||||
|
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String ClusterCheckTask::FormatArray(const Array::Ptr& arr)
|
||||||
|
{
|
||||||
|
bool first = true;
|
||||||
|
String str;
|
||||||
|
|
||||||
|
if (arr) {
|
||||||
|
ObjectLock olock(arr);
|
||||||
|
BOOST_FOREACH(const Value& value, arr) {
|
||||||
|
if (first)
|
||||||
|
first = false;
|
||||||
|
else
|
||||||
|
str += ",";
|
||||||
|
|
||||||
|
str += Convert::ToString(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ClusterCheckTask(void);
|
ClusterCheckTask(void);
|
||||||
|
static String FormatArray(const Array::Ptr& arr);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ public:
|
|||||||
shared_ptr<SSL_CTX> GetSSLContext(void) const;
|
shared_ptr<SSL_CTX> GetSSLContext(void) const;
|
||||||
String GetClusterDir(void) const;
|
String GetClusterDir(void) const;
|
||||||
|
|
||||||
|
Dictionary::Ptr GetClusterStatus(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
shared_ptr<SSL_CTX> m_SSLContext;
|
shared_ptr<SSL_CTX> m_SSLContext;
|
||||||
|
|
||||||
@ -117,8 +119,6 @@ private:
|
|||||||
void PersistMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message);
|
void PersistMessage(const Endpoint::Ptr& source, const Dictionary::Ptr& message);
|
||||||
|
|
||||||
static void MessageExceptionHandler(boost::exception_ptr exp);
|
static void MessageExceptionHandler(boost::exception_ptr exp);
|
||||||
|
|
||||||
Dictionary::Ptr GetClusterStatus(void);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user