-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the "cluster-zone" check task.
Fixes #6204
- Loading branch information
1 parent
f85eacb
commit b959124
Showing
8 changed files
with
177 additions
and
6 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-2014 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/clusterzonechecktask.hpp" | ||
#include "icinga/checkcommand.hpp" | ||
#include "icinga/macroprocessor.hpp" | ||
#include "remote/apilistener.hpp" | ||
#include "remote/endpoint.hpp" | ||
#include "remote/zone.hpp" | ||
#include "base/scriptfunction.hpp" | ||
#include <boost/foreach.hpp> | ||
|
||
using namespace icinga; | ||
|
||
REGISTER_SCRIPTFUNCTION(ClusterZoneCheck, &ClusterZoneCheckTask::ScriptFunc); | ||
|
||
void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr) | ||
{ | ||
ApiListener::Ptr listener = ApiListener::GetInstance(); | ||
|
||
if (!listener) { | ||
cr->SetOutput("No API listener is configured for this instance."); | ||
cr->SetState(ServiceUnknown); | ||
checkable->ProcessCheckResult(cr); | ||
return; | ||
} | ||
|
||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand(); | ||
Value raw_command = commandObj->GetCommandLine(); | ||
|
||
Host::Ptr host; | ||
Service::Ptr service; | ||
tie(host, service) = GetHostService(checkable); | ||
|
||
MacroProcessor::ResolverList resolvers; | ||
if (service) | ||
resolvers.push_back(std::make_pair("service", service)); | ||
resolvers.push_back(std::make_pair("host", host)); | ||
resolvers.push_back(std::make_pair("command", commandObj)); | ||
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance())); | ||
|
||
String zoneName = MacroProcessor::ResolveMacros("cluster_zone", resolvers, checkable->GetLastCheckResult()); | ||
|
||
if (zoneName.IsEmpty()) { | ||
cr->SetOutput("Zone '" + zoneName + "' does not exist."); | ||
cr->SetState(ServiceUnknown); | ||
checkable->ProcessCheckResult(cr); | ||
return; | ||
} | ||
|
||
Zone::Ptr zone = Zone::GetByName(zoneName); | ||
|
||
bool connected = false; | ||
|
||
BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) { | ||
if (endpoint->IsConnected()) { | ||
connected = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!connected) { | ||
cr->SetState(ServiceCritical); | ||
cr->SetOutput("Zone '" + zoneName + "' is not connected."); | ||
} else { | ||
cr->SetState(ServiceOK); | ||
cr->SetOutput("Zone '" + zoneName + "' is connected."); | ||
} | ||
|
||
checkable->ProcessCheckResult(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,44 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-2014 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 CLUSTERZONECHECKTASK_H | ||
#define CLUSTERZONECHECKTASK_H | ||
|
||
#include "icinga/service.hpp" | ||
|
||
namespace icinga | ||
{ | ||
|
||
/** | ||
* Cluster zone check type. | ||
* | ||
* @ingroup methods | ||
*/ | ||
class ClusterZoneCheckTask | ||
{ | ||
public: | ||
static void ScriptFunc(const Checkable::Ptr& service, const CheckResult::Ptr& cr); | ||
|
||
private: | ||
ClusterZoneCheckTask(void); | ||
}; | ||
|
||
} | ||
|
||
#endif /* CLUSTERZONECHECKTASK_H */ |