2012-07-09 20:32:02 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2013-09-25 07:43:57 +02:00
|
|
|
* Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) *
|
2012-07-09 20:32:02 +02:00
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "icinga/service.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/servicegroup.h"
|
2013-06-13 11:33:00 +02:00
|
|
|
#include "icinga/checkcommand.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/icingaapplication.h"
|
|
|
|
#include "icinga/macroprocessor.h"
|
2013-03-22 14:40:55 +01:00
|
|
|
#include "config/configitembuilder.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "base/dynamictype.h"
|
|
|
|
#include "base/objectlock.h"
|
2013-03-22 14:40:55 +01:00
|
|
|
#include "base/convert.h"
|
2013-03-25 18:36:15 +01:00
|
|
|
#include "base/utility.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <boost/smart_ptr/make_shared.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
2013-09-01 06:01:27 +02:00
|
|
|
#include <boost/bind/apply.hpp>
|
2012-06-13 13:42:55 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-03-01 12:07:52 +01:00
|
|
|
REGISTER_TYPE(Service);
|
2012-07-26 12:28:29 +02:00
|
|
|
|
2013-08-29 13:48:18 +02:00
|
|
|
boost::signals2::signal<void (const Service::Ptr&, const String&, const String&, AcknowledgementType, double, const String&)> Service::OnAcknowledgementSet;
|
|
|
|
boost::signals2::signal<void (const Service::Ptr&, const String&)> Service::OnAcknowledgementCleared;
|
|
|
|
|
2013-09-01 06:01:27 +02:00
|
|
|
Service::Service(void)
|
|
|
|
: m_CheckRunning(false)
|
|
|
|
{ }
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
void Service::Start(void)
|
2013-02-26 10:13:54 +01:00
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
DynamicObject::Start();
|
2013-06-21 10:20:29 +02:00
|
|
|
|
2013-09-25 08:51:55 +02:00
|
|
|
VERIFY(GetHost());
|
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
SetSchedulingOffset(rand());
|
2013-08-20 11:06:04 +02:00
|
|
|
UpdateNextCheck();
|
2013-06-28 16:08:43 +02:00
|
|
|
|
2013-08-29 16:53:57 +02:00
|
|
|
AddDowntimesToCache();
|
|
|
|
AddCommentsToCache();
|
2013-09-17 20:11:29 +02:00
|
|
|
|
|
|
|
StartDowntimesExpiredTimer();
|
2013-08-29 16:53:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Service::OnConfigLoaded(void)
|
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
Array::Ptr groups = GetGroups();
|
2013-02-20 19:52:25 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
if (groups) {
|
2013-09-09 13:52:37 +02:00
|
|
|
ObjectLock olock(groups);
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const String& name, groups) {
|
|
|
|
ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
|
2012-08-02 09:38:08 +02:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
if (sg)
|
|
|
|
sg->AddMember(GetSelf());
|
|
|
|
}
|
|
|
|
}
|
2013-03-02 09:07:47 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
Host::Ptr host = GetHost();
|
|
|
|
if (host)
|
|
|
|
host->AddService(GetSelf());
|
2013-08-29 16:53:57 +02:00
|
|
|
|
|
|
|
UpdateSlaveNotifications();
|
2013-01-24 15:01:06 +01:00
|
|
|
}
|
|
|
|
|
2013-02-09 17:50:47 +01:00
|
|
|
String Service::GetDisplayName(void) const
|
2012-08-02 09:38:08 +02:00
|
|
|
{
|
2013-02-26 10:13:54 +01:00
|
|
|
if (m_DisplayName.IsEmpty())
|
2013-02-24 01:10:34 +01:00
|
|
|
return GetShortName();
|
2013-02-26 10:13:54 +01:00
|
|
|
else
|
|
|
|
return m_DisplayName;
|
2012-06-13 13:42:55 +02:00
|
|
|
}
|
|
|
|
|
2013-02-08 15:38:22 +01:00
|
|
|
Service::Ptr Service::GetByNamePair(const String& hostName, const String& serviceName)
|
|
|
|
{
|
|
|
|
if (!hostName.IsEmpty()) {
|
|
|
|
Host::Ptr host = Host::GetByName(hostName);
|
2013-02-27 15:23:25 +01:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
return Service::Ptr();
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
return host->GetServiceByShortName(serviceName);
|
2013-02-08 15:38:22 +01:00
|
|
|
} else {
|
|
|
|
return Service::GetByName(serviceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 16:05:02 +02:00
|
|
|
Host::Ptr Service::GetHost(void) const
|
2012-06-13 13:42:55 +02:00
|
|
|
{
|
2013-02-27 12:44:51 +01:00
|
|
|
return Host::GetByName(m_HostName);
|
2012-06-13 13:42:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary::Ptr Service::GetMacros(void) const
|
|
|
|
{
|
2013-02-26 10:13:54 +01:00
|
|
|
return m_Macros;
|
2012-06-13 13:42:55 +02:00
|
|
|
}
|
|
|
|
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr Service::GetHostDependencies(void) const
|
2012-06-27 18:43:34 +02:00
|
|
|
{
|
2013-02-26 10:13:54 +01:00
|
|
|
return m_HostDependencies;
|
2012-06-13 13:42:55 +02:00
|
|
|
}
|
2012-06-14 11:18:20 +02:00
|
|
|
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr Service::GetServiceDependencies(void) const
|
2013-02-07 20:29:35 +01:00
|
|
|
{
|
2013-02-26 10:13:54 +01:00
|
|
|
return m_ServiceDependencies;
|
2012-07-09 10:09:53 +02:00
|
|
|
}
|
|
|
|
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr Service::GetGroups(void) const
|
2012-06-30 13:39:55 +02:00
|
|
|
{
|
2013-09-25 09:24:34 +02:00
|
|
|
return m_Groups;
|
2012-06-30 13:39:55 +02:00
|
|
|
}
|
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
String Service::GetHostName(void) const
|
2013-02-08 15:38:22 +01:00
|
|
|
{
|
2013-02-26 10:13:54 +01:00
|
|
|
return m_HostName;
|
|
|
|
}
|
2013-02-08 15:38:22 +01:00
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
String Service::GetShortName(void) const
|
|
|
|
{
|
|
|
|
if (m_ShortName.IsEmpty())
|
2013-02-08 15:38:22 +01:00
|
|
|
return GetName();
|
2013-02-26 10:13:54 +01:00
|
|
|
else
|
|
|
|
return m_ShortName;
|
2013-02-08 15:38:22 +01:00
|
|
|
}
|
|
|
|
|
2013-07-09 16:59:31 +02:00
|
|
|
bool Service::IsHostCheck(void) const
|
|
|
|
{
|
|
|
|
ASSERT(!OwnsLock());
|
|
|
|
|
2013-09-25 09:12:15 +02:00
|
|
|
Service::Ptr hc = GetHost()->GetCheckService();
|
2013-07-09 16:59:31 +02:00
|
|
|
|
|
|
|
if (!hc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (hc->GetName() == GetName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
bool Service::IsReachable(void) const
|
2012-07-03 14:18:46 +02:00
|
|
|
{
|
2013-03-07 16:00:10 +01:00
|
|
|
ASSERT(!OwnsLock());
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
BOOST_FOREACH(const Service::Ptr& service, GetParentServices()) {
|
2013-02-27 17:20:22 +01:00
|
|
|
/* ignore ourselves */
|
2013-03-02 09:07:47 +01:00
|
|
|
if (service->GetName() == GetName())
|
2013-02-27 17:20:22 +01:00
|
|
|
continue;
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
ObjectLock olock(service);
|
|
|
|
|
2012-07-09 12:44:31 +02:00
|
|
|
/* ignore pending services */
|
2012-08-02 09:38:08 +02:00
|
|
|
if (!service->GetLastCheckResult())
|
2012-07-09 12:44:31 +02:00
|
|
|
continue;
|
|
|
|
|
2012-07-09 17:03:24 +02:00
|
|
|
/* ignore soft states */
|
2012-07-27 16:05:02 +02:00
|
|
|
if (service->GetStateType() == StateTypeSoft)
|
2012-07-09 17:03:24 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* ignore services states OK and Warning */
|
2012-07-27 16:05:02 +02:00
|
|
|
if (service->GetState() == StateOK ||
|
|
|
|
service->GetState() == StateWarning)
|
2012-07-09 17:03:24 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return false;
|
2012-07-03 14:18:46 +02:00
|
|
|
}
|
2012-07-09 17:03:24 +02:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
BOOST_FOREACH(const Host::Ptr& host, GetParentHosts()) {
|
2013-09-25 09:12:15 +02:00
|
|
|
Service::Ptr hc = host->GetCheckService();
|
2013-02-28 10:26:33 +01:00
|
|
|
|
|
|
|
/* ignore hosts that don't have a hostcheck */
|
|
|
|
if (!hc)
|
|
|
|
continue;
|
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
/* ignore ourselves */
|
|
|
|
if (hc->GetName() == GetName())
|
|
|
|
continue;
|
|
|
|
|
2013-02-27 12:44:51 +01:00
|
|
|
ObjectLock olock(hc);
|
2013-02-19 23:02:08 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
/* ignore soft states */
|
|
|
|
if (hc->GetStateType() == StateTypeSoft)
|
2013-02-27 17:20:22 +01:00
|
|
|
continue;
|
|
|
|
|
2013-02-07 20:29:35 +01:00
|
|
|
/* ignore hosts that are up */
|
2013-03-02 09:07:47 +01:00
|
|
|
if (hc->GetState() == StateOK)
|
2013-02-07 20:29:35 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-03 15:20:44 +02:00
|
|
|
return true;
|
2012-07-03 14:18:46 +02:00
|
|
|
}
|
|
|
|
|
2013-06-13 12:24:20 +02:00
|
|
|
bool Service::IsVolatile(void) const
|
|
|
|
{
|
|
|
|
if (m_Volatile.IsEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_Volatile;
|
|
|
|
}
|
|
|
|
|
2013-01-23 13:21:07 +01:00
|
|
|
AcknowledgementType Service::GetAcknowledgement(void)
|
|
|
|
{
|
2013-03-07 16:00:10 +01:00
|
|
|
ASSERT(OwnsLock());
|
2013-03-06 11:03:50 +01:00
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
if (m_Acknowledgement.IsEmpty())
|
2013-01-23 13:21:07 +01:00
|
|
|
return AcknowledgementNone;
|
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
int ivalue = static_cast<int>(m_Acknowledgement);
|
2013-01-23 13:21:07 +01:00
|
|
|
AcknowledgementType avalue = static_cast<AcknowledgementType>(ivalue);
|
|
|
|
|
|
|
|
if (avalue != AcknowledgementNone) {
|
|
|
|
double expiry = GetAcknowledgementExpiry();
|
|
|
|
|
|
|
|
if (expiry != 0 && expiry < Utility::GetTime()) {
|
|
|
|
avalue = AcknowledgementNone;
|
2013-08-29 13:48:18 +02:00
|
|
|
ClearAcknowledgement();
|
2013-01-23 13:21:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return avalue;
|
|
|
|
}
|
|
|
|
|
2013-02-11 16:38:16 +01:00
|
|
|
bool Service::IsAcknowledged(void)
|
|
|
|
{
|
|
|
|
return GetAcknowledgement() != AcknowledgementNone;
|
|
|
|
}
|
|
|
|
|
2013-01-23 13:21:07 +01:00
|
|
|
double Service::GetAcknowledgementExpiry(void) const
|
|
|
|
{
|
2013-02-26 10:13:54 +01:00
|
|
|
if (m_AcknowledgementExpiry.IsEmpty())
|
2013-01-23 13:21:07 +01:00
|
|
|
return 0;
|
|
|
|
|
2013-02-26 10:13:54 +01:00
|
|
|
return static_cast<double>(m_AcknowledgementExpiry);
|
2013-01-23 13:21:07 +01:00
|
|
|
}
|
|
|
|
|
2013-08-29 13:48:18 +02:00
|
|
|
void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry, const String& authority)
|
2013-02-24 12:47:24 +01:00
|
|
|
{
|
2013-03-08 16:36:26 +01:00
|
|
|
{
|
|
|
|
ObjectLock olock(this);
|
2013-03-02 09:07:47 +01:00
|
|
|
|
2013-08-29 13:48:18 +02:00
|
|
|
m_Acknowledgement = type;
|
|
|
|
m_AcknowledgementExpiry = expiry;
|
2013-03-08 16:36:26 +01:00
|
|
|
}
|
2013-02-24 12:47:24 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
|
2013-08-29 13:48:18 +02:00
|
|
|
|
2013-09-01 06:01:27 +02:00
|
|
|
boost::function<void (void)> f = boost::bind(boost::ref(Service::OnAcknowledgementSet), GetSelf(), author, comment, type, expiry, authority);
|
|
|
|
Utility::QueueAsyncCallback(f);
|
2013-02-24 12:47:24 +01:00
|
|
|
}
|
|
|
|
|
2013-08-29 13:48:18 +02:00
|
|
|
void Service::ClearAcknowledgement(const String& authority)
|
2013-02-24 12:47:24 +01:00
|
|
|
{
|
2013-08-29 13:48:18 +02:00
|
|
|
ASSERT(OwnsLock());
|
|
|
|
|
|
|
|
m_Acknowledgement = AcknowledgementNone;
|
|
|
|
m_AcknowledgementExpiry = 0;
|
2013-03-04 15:52:42 +01:00
|
|
|
|
2013-09-01 06:01:27 +02:00
|
|
|
Utility::QueueAsyncCallback(boost::bind(boost::ref(OnAcknowledgementCleared), GetSelf(), authority));
|
2013-02-24 12:47:24 +01:00
|
|
|
}
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Host::Ptr> Service::GetParentHosts(void) const
|
2013-02-07 20:29:35 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Host::Ptr> parents;
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
Host::Ptr host = GetHost();
|
2013-02-27 12:44:51 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
/* The service's host is implicitly a parent. */
|
|
|
|
if (host)
|
|
|
|
parents.insert(host);
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr dependencies = GetHostDependencies();
|
2013-02-07 20:29:35 +01:00
|
|
|
|
|
|
|
if (dependencies) {
|
2013-03-02 09:07:47 +01:00
|
|
|
ObjectLock olock(dependencies);
|
|
|
|
|
2013-03-14 12:17:46 +01:00
|
|
|
BOOST_FOREACH(const Value& dependency, dependencies) {
|
|
|
|
Host::Ptr host = Host::GetByName(dependency);
|
2013-02-27 15:23:25 +01:00
|
|
|
|
|
|
|
if (!host)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
parents.insert(host);
|
2013-02-07 20:29:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parents;
|
|
|
|
}
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Service::Ptr> Service::GetParentServices(void) const
|
2013-02-07 20:29:35 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<Service::Ptr> parents;
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
Host::Ptr host = GetHost();
|
2013-03-14 12:17:46 +01:00
|
|
|
Array::Ptr dependencies = GetServiceDependencies();
|
2013-02-27 12:44:51 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
if (host && dependencies) {
|
2013-06-21 08:30:26 +02:00
|
|
|
ObjectLock olock(dependencies);
|
|
|
|
|
2013-03-14 12:17:46 +01:00
|
|
|
BOOST_FOREACH(const Value& dependency, dependencies) {
|
|
|
|
Service::Ptr service = host->GetServiceByShortName(dependency);
|
2013-02-07 20:29:35 +01:00
|
|
|
|
2013-03-02 09:07:47 +01:00
|
|
|
if (!service)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (service->GetName() == GetName())
|
2013-02-07 20:29:35 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
parents.insert(service);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parents;
|
|
|
|
}
|
2013-02-09 18:39:43 +01:00
|
|
|
|
2013-03-22 14:40:55 +01:00
|
|
|
bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
|
2013-02-09 18:39:43 +01:00
|
|
|
{
|
2013-03-22 14:40:55 +01:00
|
|
|
if (macro == "SERVICEDESC") {
|
|
|
|
*result = GetShortName();
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICEDISPLAYNAME") {
|
|
|
|
*result = GetDisplayName();
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICECHECKCOMMAND") {
|
2013-06-13 11:33:00 +02:00
|
|
|
CheckCommand::Ptr commandObj = GetCheckCommand();
|
|
|
|
|
|
|
|
if (commandObj)
|
|
|
|
*result = commandObj->GetName();
|
|
|
|
else
|
|
|
|
*result = "";
|
|
|
|
|
2013-03-22 14:40:55 +01:00
|
|
|
return true;
|
2013-02-24 01:10:34 +01:00
|
|
|
}
|
2013-02-11 16:29:23 +01:00
|
|
|
|
2013-03-22 14:40:55 +01:00
|
|
|
if (macro == "SERVICESTATE") {
|
|
|
|
*result = StateToString(GetState());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICESTATEID") {
|
|
|
|
*result = Convert::ToString(GetState());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICESTATETYPE") {
|
|
|
|
*result = StateTypeToString(GetStateType());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICEATTEMPT") {
|
|
|
|
*result = Convert::ToString(GetCurrentCheckAttempt());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "MAXSERVICEATTEMPT") {
|
|
|
|
*result = Convert::ToString(GetMaxCheckAttempts());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "LASTSERVICESTATE") {
|
|
|
|
*result = StateToString(GetLastState());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "LASTSERVICESTATEID") {
|
|
|
|
*result = Convert::ToString(GetLastState());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "LASTSERVICESTATETYPE") {
|
|
|
|
*result = StateTypeToString(GetLastStateType());
|
|
|
|
return true;
|
|
|
|
} else if (macro == "LASTSERVICESTATECHANGE") {
|
|
|
|
*result = Convert::ToString((long)GetLastStateChange());
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-15 13:29:41 +01:00
|
|
|
|
2013-02-11 16:29:23 +01:00
|
|
|
if (cr) {
|
2013-03-22 14:40:55 +01:00
|
|
|
if (macro == "SERVICELATENCY") {
|
|
|
|
*result = Convert::ToString(Service::CalculateLatency(cr));
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICEEXECUTIONTIME") {
|
|
|
|
*result = Convert::ToString(Service::CalculateExecutionTime(cr));
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICEOUTPUT") {
|
|
|
|
*result = cr->Get("output");
|
|
|
|
return true;
|
|
|
|
} else if (macro == "SERVICEPERFDATA") {
|
|
|
|
*result = cr->Get("performance_data_raw");
|
|
|
|
return true;
|
|
|
|
} else if (macro == "LASTSERVICECHECK") {
|
|
|
|
*result = Convert::ToString((long)cr->Get("execution_end"));
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-11 16:29:23 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 14:40:55 +01:00
|
|
|
Dictionary::Ptr macros = GetMacros();
|
2013-03-07 12:04:20 +01:00
|
|
|
|
2013-03-22 14:40:55 +01:00
|
|
|
if (macros && macros->Contains(macro)) {
|
|
|
|
*result = macros->Get(macro);
|
|
|
|
return true;
|
2013-03-07 12:04:20 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 14:40:55 +01:00
|
|
|
return false;
|
2013-03-07 12:04:20 +01:00
|
|
|
}
|
2013-08-20 11:06:04 +02:00
|
|
|
|
|
|
|
void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
|
|
|
|
{
|
|
|
|
DynamicObject::InternalSerialize(bag, attributeTypes);
|
|
|
|
|
|
|
|
if (attributeTypes & Attribute_Config) {
|
|
|
|
bag->Set("display_name", m_DisplayName);
|
|
|
|
bag->Set("macros", m_Macros);
|
2013-09-25 09:16:53 +02:00
|
|
|
bag->Set("host_dependencies", m_HostDependencies);
|
|
|
|
bag->Set("service_dependencies", m_ServiceDependencies);
|
2013-09-25 09:24:34 +02:00
|
|
|
bag->Set("groups", m_Groups);
|
2013-08-20 11:06:04 +02:00
|
|
|
bag->Set("check_command", m_CheckCommand);
|
|
|
|
bag->Set("max_check_attempts", m_MaxCheckAttempts);
|
|
|
|
bag->Set("check_period", m_CheckPeriod);
|
|
|
|
bag->Set("check_interval", m_CheckInterval);
|
|
|
|
bag->Set("retry_interval", m_RetryInterval);
|
|
|
|
bag->Set("event_command", m_EventCommand);
|
|
|
|
bag->Set("volatile", m_Volatile);
|
|
|
|
bag->Set("short_name", m_ShortName);
|
2013-09-25 09:19:25 +02:00
|
|
|
bag->Set("host", m_HostName);
|
2013-08-20 11:06:04 +02:00
|
|
|
bag->Set("flapping_threshold", m_FlappingThreshold);
|
|
|
|
bag->Set("notifications", m_NotificationDescriptions);
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:40:43 +02:00
|
|
|
if (attributeTypes & Attribute_State) {
|
|
|
|
bag->Set("next_check", m_NextCheck);
|
|
|
|
bag->Set("current_checker", m_CurrentChecker);
|
|
|
|
bag->Set("check_attempt", m_CheckAttempt);
|
|
|
|
bag->Set("state", m_State);
|
|
|
|
bag->Set("state_type", m_StateType);
|
|
|
|
bag->Set("last_state", m_LastState);
|
|
|
|
bag->Set("last_hard_state", m_LastHardState);
|
|
|
|
bag->Set("last_state_type", m_LastStateType);
|
|
|
|
bag->Set("last_reachable", m_LastReachable);
|
|
|
|
bag->Set("last_result", m_LastResult);
|
|
|
|
bag->Set("last_state_change", m_LastStateChange);
|
|
|
|
bag->Set("last_hard_state_change", m_LastHardStateChange);
|
|
|
|
bag->Set("last_state_ok", m_LastStateOK);
|
|
|
|
bag->Set("last_state_warning", m_LastStateWarning);
|
|
|
|
bag->Set("last_state_critical", m_LastStateCritical);
|
|
|
|
bag->Set("last_state_unknown", m_LastStateUnknown);
|
|
|
|
bag->Set("last_state_unreachable", m_LastStateUnreachable);
|
|
|
|
bag->Set("last_in_downtime", m_LastInDowntime);
|
|
|
|
bag->Set("enable_active_checks", m_EnableActiveChecks);
|
|
|
|
bag->Set("enable_passive_checks", m_EnablePassiveChecks);
|
|
|
|
bag->Set("force_next_check", m_ForceNextCheck);
|
|
|
|
bag->Set("acknowledgement", m_Acknowledgement);
|
|
|
|
bag->Set("acknowledgement_expiry", m_AcknowledgementExpiry);
|
|
|
|
bag->Set("comments", m_Comments);
|
|
|
|
bag->Set("downtimes", m_Downtimes);
|
|
|
|
bag->Set("enable_notifications", m_EnableNotifications);
|
|
|
|
bag->Set("force_next_notification", m_ForceNextNotification);
|
|
|
|
bag->Set("flapping_positive", m_FlappingPositive);
|
|
|
|
bag->Set("flapping_negative", m_FlappingNegative);
|
|
|
|
bag->Set("flapping_lastchange", m_FlappingLastChange);
|
|
|
|
bag->Set("enable_flapping", m_EnableFlapping);
|
|
|
|
}
|
2013-08-20 11:06:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
|
|
|
|
{
|
|
|
|
DynamicObject::InternalDeserialize(bag, attributeTypes);
|
|
|
|
|
|
|
|
if (attributeTypes & Attribute_Config) {
|
|
|
|
m_DisplayName = bag->Get("display_name");
|
|
|
|
m_Macros = bag->Get("macros");
|
2013-09-25 09:16:53 +02:00
|
|
|
m_HostDependencies = bag->Get("host_dependencies");
|
|
|
|
m_ServiceDependencies = bag->Get("service_dependencies");
|
2013-09-25 09:24:34 +02:00
|
|
|
m_Groups = bag->Get("groups");
|
2013-08-20 11:06:04 +02:00
|
|
|
m_CheckCommand = bag->Get("check_command");
|
|
|
|
m_MaxCheckAttempts = bag->Get("max_check_attempts");
|
|
|
|
m_CheckPeriod = bag->Get("check_period");
|
|
|
|
m_CheckInterval = bag->Get("check_interval");
|
|
|
|
m_RetryInterval = bag->Get("retry_interval");
|
|
|
|
m_EventCommand = bag->Get("event_command");
|
|
|
|
m_Volatile = bag->Get("volatile");
|
|
|
|
m_ShortName = bag->Get("short_name");
|
2013-09-25 09:19:25 +02:00
|
|
|
m_HostName = bag->Get("host");
|
2013-08-20 11:06:04 +02:00
|
|
|
m_FlappingThreshold = bag->Get("flapping_threshold");
|
|
|
|
m_NotificationDescriptions = bag->Get("notifications");
|
|
|
|
}
|
|
|
|
|
2013-08-29 10:40:43 +02:00
|
|
|
if (attributeTypes & Attribute_State) {
|
|
|
|
m_NextCheck = bag->Get("next_check");
|
|
|
|
m_CurrentChecker = bag->Get("current_checker");
|
|
|
|
m_CheckAttempt = bag->Get("check_attempt");
|
|
|
|
m_State = bag->Get("state");
|
|
|
|
m_StateType = bag->Get("state_type");
|
|
|
|
m_LastState = bag->Get("last_state");
|
|
|
|
m_LastHardState = bag->Get("last_hard_state");
|
|
|
|
m_LastStateType = bag->Get("last_state_type");
|
|
|
|
m_LastReachable = bag->Get("last_reachable");
|
|
|
|
m_LastResult = bag->Get("last_result");
|
|
|
|
m_LastStateChange = bag->Get("last_state_change");
|
|
|
|
m_LastHardStateChange = bag->Get("last_hard_state_change");
|
|
|
|
m_LastStateOK = bag->Get("last_state_ok");
|
|
|
|
m_LastStateWarning = bag->Get("last_state_warning");
|
|
|
|
m_LastStateCritical = bag->Get("last_state_critical");
|
|
|
|
m_LastStateUnknown = bag->Get("last_state_unknown");
|
|
|
|
m_LastStateUnreachable = bag->Get("last_state_unreachable");
|
|
|
|
m_LastInDowntime = bag->Get("last_in_downtime");
|
|
|
|
m_EnableActiveChecks = bag->Get("enable_active_checks");
|
|
|
|
m_EnablePassiveChecks = bag->Get("enable_passive_checks");
|
|
|
|
m_ForceNextCheck = bag->Get("force_next_check");
|
|
|
|
m_Acknowledgement = bag->Get("acknowledgement");
|
|
|
|
m_AcknowledgementExpiry = bag->Get("acknowledgement_expiry");
|
|
|
|
m_Comments = bag->Get("comments");
|
|
|
|
m_Downtimes = bag->Get("downtimes");
|
|
|
|
m_EnableNotifications = bag->Get("enable_notifications");
|
|
|
|
m_ForceNextNotification = bag->Get("force_next_notification");
|
|
|
|
m_FlappingPositive = bag->Get("flapping_positive");
|
|
|
|
m_FlappingNegative = bag->Get("flapping_negative");
|
|
|
|
m_FlappingLastChange = bag->Get("flapping_lastchange");
|
|
|
|
m_EnableFlapping = bag->Get("enable_flapping");
|
|
|
|
}
|
2013-08-20 11:06:04 +02:00
|
|
|
}
|