-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #5438
- Loading branch information
Michael Friedrich
committed
Feb 7, 2014
1 parent
7d9dc1a
commit e534f9b
Showing
8 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* This program is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU General Public License * | ||
* as published by the Free Software Foundation; either version 2 * | ||
* of the License, or (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the Free Software Foundation * | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
******************************************************************************/ | ||
|
||
#include "methods/clusterchecktask.h" | ||
#include "cluster/endpoint.h" | ||
#include "cluster/clusterlistener.h" | ||
#include "icinga/cib.h" | ||
#include "icinga/service.h" | ||
#include "icinga/icingaapplication.h" | ||
#include "base/application.h" | ||
#include "base/objectlock.h" | ||
#include "base/convert.h" | ||
#include "base/utility.h" | ||
#include "base/scriptfunction.h" | ||
#include "base/dynamictype.h" | ||
#include <boost/algorithm/string/join.hpp> | ||
|
||
using namespace icinga; | ||
|
||
REGISTER_SCRIPTFUNCTION(ClusterCheck, &ClusterCheckTask::ScriptFunc); | ||
|
||
CheckResult::Ptr ClusterCheckTask::ScriptFunc(const Service::Ptr&) | ||
{ | ||
double interval = Utility::GetTime() - Application::GetStartTime(); | ||
|
||
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>()) { | ||
String identity = cluster_listener->GetIdentity(); | ||
|
||
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()); | ||
std::sort(connected_endpoints.begin(), connected_endpoints.end()); | ||
|
||
ServiceState state = StateOK; | ||
String output = "Icinga 2 Cluster is running: Connected Endpoints: "+ Convert::ToString(connected_endpoints.size()) + " (" + | ||
boost::algorithm::join(connected_endpoints, ",") + ")."; | ||
|
||
if (not_connected_endpoints.size() > 0) { | ||
state = StateCritical; | ||
output = "Icinga 2 Cluster Problem: " + Convert::ToString(not_connected_endpoints.size()) + | ||
" Endpoints (" + boost::algorithm::join(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>(); | ||
cr->SetOutput(output); | ||
cr->SetPerformanceData(perfdata); | ||
cr->SetState(state); | ||
cr->SetCheckSource(IcingaApplication::GetInstance()->GetNodeName()); | ||
|
||
return cr; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* This program is free software; you can redistribute it and/or * | ||
* modify it under the terms of the GNU General Public License * | ||
* as published by the Free Software Foundation; either version 2 * | ||
* of the License, or (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program; if not, write to the Free Software Foundation * | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * | ||
******************************************************************************/ | ||
|
||
#ifndef CLUSTERCHECKTASK_H | ||
#define CLUSTERCHECKTASK_H | ||
|
||
#include "methods/i2-methods.h" | ||
#include "icinga/service.h" | ||
|
||
namespace icinga | ||
{ | ||
|
||
/** | ||
* Cluster check type. | ||
* | ||
* @ingroup methods | ||
*/ | ||
class I2_METHODS_API ClusterCheckTask | ||
{ | ||
public: | ||
static CheckResult::Ptr ScriptFunc(const Service::Ptr& service); | ||
|
||
private: | ||
ClusterCheckTask(void); | ||
}; | ||
|
||
} | ||
|
||
#endif /* CLUSTERCHECKTASK_H */ |