mirror of https://github.com/Icinga/icinga2.git
Implemented host acknowledgements.
This commit is contained in:
parent
8d8d1d8cd8
commit
ae17878596
|
@ -5,6 +5,7 @@ pkglib_LTLIBRARIES = \
|
|||
libicinga.la
|
||||
|
||||
libicinga_la_SOURCES = \
|
||||
acknowledgement.h \
|
||||
cib.cpp \
|
||||
cib.h \
|
||||
externalcommand.cpp \
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 ACKNOWLEDGEMENT_H
|
||||
#define ACKNOWLEDGEMENT_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* The acknowledgement type of a host/service.
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
enum AcknowledgementType
|
||||
{
|
||||
AcknowledgementNone = 0,
|
||||
AcknowledgementNormal = 1,
|
||||
AcknowledgementSticky = 2
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ACKNOWLEDGEMENT_H */
|
|
@ -70,7 +70,10 @@ void ExternalCommand::Execute(double time, const String& command, const vector<S
|
|||
RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommand::DisableHostSvcChecks);
|
||||
RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommand::AcknowledgeSvcProblem);
|
||||
RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommand::AcknowledgeSvcProblemExpire);
|
||||
RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommand::RemoveSvcAcknowledgement);
|
||||
RegisterCommand("REMOVE_SVC_ACKNOWLEDGEMENT", &ExternalCommand::RemoveHostAcknowledgement);
|
||||
RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM", &ExternalCommand::AcknowledgeHostProblem);
|
||||
RegisterCommand("ACKNOWLEDGE_HOST_PROBLEM_EXPIRE", &ExternalCommand::AcknowledgeHostProblemExpire);
|
||||
RegisterCommand("REMOVE_HOST_ACKNOWLEDGEMENT", &ExternalCommand::RemoveHostAcknowledgement);
|
||||
RegisterCommand("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::EnableHostgroupSvcChecks);
|
||||
RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::DisableHostgroupSvcChecks);
|
||||
RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommand::EnableServicegroupSvcChecks);
|
||||
|
@ -358,6 +361,62 @@ void ExternalCommand::RemoveSvcAcknowledgement(double time, const vector<String>
|
|||
service->SetAcknowledgementExpiry(0);
|
||||
}
|
||||
|
||||
void ExternalCommand::AcknowledgeHostProblem(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 7)
|
||||
throw_exception(invalid_argument("Expected 7 arguments."));
|
||||
|
||||
if (!Host::Exists(arguments[1]))
|
||||
throw_exception(invalid_argument("The host '" + arguments[1] + "' does not exist."));
|
||||
|
||||
int sticky = arguments[2].ToDouble();
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[1]);
|
||||
|
||||
if (host->IsUp())
|
||||
throw_exception(invalid_argument("The host '" + arguments[1] + "' is OK."));
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Setting acknowledgement for host '" + host->GetName() + "'");
|
||||
host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
|
||||
host->SetAcknowledgementExpiry(0);
|
||||
}
|
||||
|
||||
void ExternalCommand::AcknowledgeHostProblemExpire(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 8)
|
||||
throw_exception(invalid_argument("Expected 8 arguments."));
|
||||
|
||||
if (!Host::Exists(arguments[1]))
|
||||
throw_exception(invalid_argument("The host '" + arguments[1] + "' does not exist."));
|
||||
|
||||
int sticky = arguments[2].ToDouble();
|
||||
double timestamp = arguments[5].ToDouble();
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[1]);
|
||||
|
||||
if (host->IsUp())
|
||||
throw_exception(invalid_argument("The host '" + arguments[1] + "' is OK."));
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Setting timed acknowledgement for host '" + host->GetName() + "'");
|
||||
host->SetAcknowledgement(sticky ? AcknowledgementSticky : AcknowledgementNormal);
|
||||
host->SetAcknowledgementExpiry(timestamp);
|
||||
}
|
||||
|
||||
void ExternalCommand::RemoveHostAcknowledgement(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 2)
|
||||
throw_exception(invalid_argument("Expected 2 arguments."));
|
||||
|
||||
if (!Host::Exists(arguments[1]))
|
||||
throw_exception(invalid_argument("The host '" + arguments[1] + "' does not exist."));
|
||||
|
||||
Host::Ptr host = Host::GetByName(arguments[1]);
|
||||
|
||||
Logger::Write(LogInformation, "icinga", "Removing acknowledgement for host '" + host->GetName() + "'");
|
||||
host->SetAcknowledgement(AcknowledgementNone);
|
||||
host->SetAcknowledgementExpiry(0);
|
||||
}
|
||||
|
||||
void ExternalCommand::EnableHostgroupSvcChecks(double time, const vector<String>& arguments)
|
||||
{
|
||||
if (arguments.size() < 1)
|
||||
|
|
|
@ -42,6 +42,9 @@ public:
|
|||
static void AcknowledgeSvcProblem(double time, const vector<String>& arguments);
|
||||
static void AcknowledgeSvcProblemExpire(double time, const vector<String>& arguments);
|
||||
static void RemoveSvcAcknowledgement(double time, const vector<String>& arguments);
|
||||
static void AcknowledgeHostProblem(double time, const vector<String>& arguments);
|
||||
static void AcknowledgeHostProblemExpire(double time, const vector<String>& arguments);
|
||||
static void RemoveHostAcknowledgement(double time, const vector<String>& arguments);
|
||||
static void EnableHostgroupSvcChecks(double time, const vector<String>& arguments);
|
||||
static void DisableHostgroupSvcChecks(double time, const vector<String>& arguments);
|
||||
static void EnableServicegroupSvcChecks(double time, const vector<String>& arguments);
|
||||
|
|
|
@ -26,7 +26,9 @@ bool Host::m_ServicesCacheValid = true;
|
|||
|
||||
static AttributeDescription hostAttributes[] = {
|
||||
{ "alias", Attribute_Config },
|
||||
{ "hostgroups", Attribute_Config }
|
||||
{ "hostgroups", Attribute_Config },
|
||||
{ "acknowledgement", Attribute_Replicated },
|
||||
{ "acknowledgement_expiry", Attribute_Replicated }
|
||||
};
|
||||
|
||||
REGISTER_TYPE(Host, hostAttributes);
|
||||
|
@ -307,6 +309,49 @@ set<Service::Ptr> Host::GetServices(void) const
|
|||
return services;
|
||||
}
|
||||
|
||||
AcknowledgementType Host::GetAcknowledgement(void)
|
||||
{
|
||||
Value value = Get("acknowledgement");
|
||||
|
||||
if (value.IsEmpty())
|
||||
return AcknowledgementNone;
|
||||
|
||||
int ivalue = static_cast<int>(value);
|
||||
AcknowledgementType avalue = static_cast<AcknowledgementType>(ivalue);
|
||||
|
||||
if (avalue != AcknowledgementNone) {
|
||||
double expiry = GetAcknowledgementExpiry();
|
||||
|
||||
if (expiry != 0 && expiry < Utility::GetTime()) {
|
||||
avalue = AcknowledgementNone;
|
||||
SetAcknowledgement(avalue);
|
||||
SetAcknowledgementExpiry(0);
|
||||
}
|
||||
}
|
||||
|
||||
return avalue;
|
||||
}
|
||||
|
||||
void Host::SetAcknowledgement(AcknowledgementType acknowledgement)
|
||||
{
|
||||
Set("acknowledgement", static_cast<long>(acknowledgement));
|
||||
}
|
||||
|
||||
double Host::GetAcknowledgementExpiry(void) const
|
||||
{
|
||||
Value value = Get("acknowledgement_expiry");
|
||||
|
||||
if (value.IsEmpty())
|
||||
return 0;
|
||||
|
||||
return static_cast<double>(value);
|
||||
}
|
||||
|
||||
void Host::SetAcknowledgementExpiry(double timestamp)
|
||||
{
|
||||
Set("acknowledgement_expiry", timestamp);
|
||||
}
|
||||
|
||||
void Host::InvalidateServicesCache(void)
|
||||
{
|
||||
m_ServicesCacheValid = false;
|
||||
|
|
|
@ -44,9 +44,16 @@ public:
|
|||
|
||||
String GetAlias(void) const;
|
||||
Dictionary::Ptr GetGroups(void) const;
|
||||
|
||||
set<Host::Ptr> GetParents(void);
|
||||
Dictionary::Ptr GetMacros(void) const;
|
||||
|
||||
AcknowledgementType GetAcknowledgement(void);
|
||||
void SetAcknowledgement(AcknowledgementType acknowledgement);
|
||||
|
||||
double GetAcknowledgementExpiry(void) const;
|
||||
void SetAcknowledgementExpiry(double timestamp);
|
||||
|
||||
bool IsReachable(void);
|
||||
bool IsUp(void);
|
||||
|
||||
|
|
|
@ -48,6 +48,8 @@ using boost::algorithm::is_any_of;
|
|||
|
||||
#include "timeperiod.h"
|
||||
|
||||
#include "acknowledgement.h"
|
||||
|
||||
#include "host.h"
|
||||
#include "hostgroup.h"
|
||||
#include "service.h"
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
<ClCompile Include="timeperiod.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="acknowledgement.h" />
|
||||
<ClInclude Include="cib.h" />
|
||||
<ClInclude Include="externalcommand.h" />
|
||||
<ClInclude Include="host.h" />
|
||||
|
|
|
@ -81,6 +81,9 @@
|
|||
<ClInclude Include="externalcommand.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="acknowledgement.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Headerdateien">
|
||||
|
|
|
@ -48,18 +48,6 @@ enum ServiceStateType
|
|||
StateTypeHard
|
||||
};
|
||||
|
||||
/**
|
||||
* The acknowledgement type of a service.
|
||||
*
|
||||
* @ingroup icinga
|
||||
*/
|
||||
enum AcknowledgementType
|
||||
{
|
||||
AcknowledgementNone = 0,
|
||||
AcknowledgementNormal = 1,
|
||||
AcknowledgementSticky = 2
|
||||
};
|
||||
|
||||
class CheckResultMessage;
|
||||
class ServiceStatusMessage;
|
||||
|
||||
|
|
Loading…
Reference in New Issue