Implemented host acknowledgements.

This commit is contained in:
Gunnar Beutner 2013-01-27 11:35:47 +01:00
parent 8d8d1d8cd8
commit ae17878596
10 changed files with 163 additions and 14 deletions

View File

@ -5,6 +5,7 @@ pkglib_LTLIBRARIES = \
libicinga.la libicinga.la
libicinga_la_SOURCES = \ libicinga_la_SOURCES = \
acknowledgement.h \
cib.cpp \ cib.cpp \
cib.h \ cib.h \
externalcommand.cpp \ externalcommand.cpp \

View File

@ -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 */

View File

@ -70,7 +70,10 @@ void ExternalCommand::Execute(double time, const String& command, const vector<S
RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommand::DisableHostSvcChecks); RegisterCommand("DISABLE_HOST_SVC_CHECKS", &ExternalCommand::DisableHostSvcChecks);
RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommand::AcknowledgeSvcProblem); RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM", &ExternalCommand::AcknowledgeSvcProblem);
RegisterCommand("ACKNOWLEDGE_SVC_PROBLEM_EXPIRE", &ExternalCommand::AcknowledgeSvcProblemExpire); 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("ENABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::EnableHostgroupSvcChecks);
RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::DisableHostgroupSvcChecks); RegisterCommand("DISABLE_HOSTGROUP_SVC_CHECKS", &ExternalCommand::DisableHostgroupSvcChecks);
RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommand::EnableServicegroupSvcChecks); RegisterCommand("ENABLE_SERVICEGROUP_SVC_CHECKS", &ExternalCommand::EnableServicegroupSvcChecks);
@ -358,6 +361,62 @@ void ExternalCommand::RemoveSvcAcknowledgement(double time, const vector<String>
service->SetAcknowledgementExpiry(0); 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) void ExternalCommand::EnableHostgroupSvcChecks(double time, const vector<String>& arguments)
{ {
if (arguments.size() < 1) if (arguments.size() < 1)

View File

@ -42,6 +42,9 @@ public:
static void AcknowledgeSvcProblem(double time, const vector<String>& arguments); static void AcknowledgeSvcProblem(double time, const vector<String>& arguments);
static void AcknowledgeSvcProblemExpire(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 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 EnableHostgroupSvcChecks(double time, const vector<String>& arguments);
static void DisableHostgroupSvcChecks(double time, const vector<String>& arguments); static void DisableHostgroupSvcChecks(double time, const vector<String>& arguments);
static void EnableServicegroupSvcChecks(double time, const vector<String>& arguments); static void EnableServicegroupSvcChecks(double time, const vector<String>& arguments);

View File

@ -26,7 +26,9 @@ bool Host::m_ServicesCacheValid = true;
static AttributeDescription hostAttributes[] = { static AttributeDescription hostAttributes[] = {
{ "alias", Attribute_Config }, { "alias", Attribute_Config },
{ "hostgroups", Attribute_Config } { "hostgroups", Attribute_Config },
{ "acknowledgement", Attribute_Replicated },
{ "acknowledgement_expiry", Attribute_Replicated }
}; };
REGISTER_TYPE(Host, hostAttributes); REGISTER_TYPE(Host, hostAttributes);
@ -307,6 +309,49 @@ set<Service::Ptr> Host::GetServices(void) const
return services; 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) void Host::InvalidateServicesCache(void)
{ {
m_ServicesCacheValid = false; m_ServicesCacheValid = false;

View File

@ -44,9 +44,16 @@ public:
String GetAlias(void) const; String GetAlias(void) const;
Dictionary::Ptr GetGroups(void) const; Dictionary::Ptr GetGroups(void) const;
set<Host::Ptr> GetParents(void); set<Host::Ptr> GetParents(void);
Dictionary::Ptr GetMacros(void) const; Dictionary::Ptr GetMacros(void) const;
AcknowledgementType GetAcknowledgement(void);
void SetAcknowledgement(AcknowledgementType acknowledgement);
double GetAcknowledgementExpiry(void) const;
void SetAcknowledgementExpiry(double timestamp);
bool IsReachable(void); bool IsReachable(void);
bool IsUp(void); bool IsUp(void);

View File

@ -48,6 +48,8 @@ using boost::algorithm::is_any_of;
#include "timeperiod.h" #include "timeperiod.h"
#include "acknowledgement.h"
#include "host.h" #include "host.h"
#include "hostgroup.h" #include "hostgroup.h"
#include "service.h" #include "service.h"

View File

@ -39,6 +39,7 @@
<ClCompile Include="timeperiod.cpp" /> <ClCompile Include="timeperiod.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="acknowledgement.h" />
<ClInclude Include="cib.h" /> <ClInclude Include="cib.h" />
<ClInclude Include="externalcommand.h" /> <ClInclude Include="externalcommand.h" />
<ClInclude Include="host.h" /> <ClInclude Include="host.h" />

View File

@ -81,6 +81,9 @@
<ClInclude Include="externalcommand.h"> <ClInclude Include="externalcommand.h">
<Filter>Headerdateien</Filter> <Filter>Headerdateien</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="acknowledgement.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="Headerdateien"> <Filter Include="Headerdateien">

View File

@ -48,18 +48,6 @@ enum ServiceStateType
StateTypeHard StateTypeHard
}; };
/**
* The acknowledgement type of a service.
*
* @ingroup icinga
*/
enum AcknowledgementType
{
AcknowledgementNone = 0,
AcknowledgementNormal = 1,
AcknowledgementSticky = 2
};
class CheckResultMessage; class CheckResultMessage;
class ServiceStatusMessage; class ServiceStatusMessage;