From 5921337b464574e97396a5e9f7063249a1f95e02 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 21 Sep 2012 13:49:14 +0200 Subject: [PATCH] Merged convenience component into libicinga. --- components/Makefile.am | 1 - components/convenience/Makefile.am | 31 ---- components/convenience/convenience.vcxproj | 90 ---------- .../convenience/convenience.vcxproj.filters | 30 ---- .../convenience/conveniencecomponent.cpp | 164 ------------------ components/convenience/conveniencecomponent.h | 41 ----- components/convenience/i2-convenience.h | 38 ---- configure.ac | 1 - icinga-app/Makefile.am | 4 +- icinga2.sln | 11 -- lib/base/streamlogger.cpp | 2 +- lib/icinga/host.cpp | 140 +++++++++++++++ lib/icinga/host.h | 6 + lib/icinga/icingaapplication.cpp | 8 - 14 files changed, 148 insertions(+), 419 deletions(-) delete mode 100644 components/convenience/Makefile.am delete mode 100644 components/convenience/convenience.vcxproj delete mode 100644 components/convenience/convenience.vcxproj.filters delete mode 100644 components/convenience/conveniencecomponent.cpp delete mode 100644 components/convenience/conveniencecomponent.h delete mode 100644 components/convenience/i2-convenience.h diff --git a/components/Makefile.am b/components/Makefile.am index 16f0cc366..837b8f59e 100644 --- a/components/Makefile.am +++ b/components/Makefile.am @@ -4,7 +4,6 @@ SUBDIRS = \ checker \ compat \ - convenience \ delegation \ demo \ replication diff --git a/components/convenience/Makefile.am b/components/convenience/Makefile.am deleted file mode 100644 index 6d2f1260b..000000000 --- a/components/convenience/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -## Process this file with automake to produce Makefile.in - -pkglib_LTLIBRARIES = \ - convenience.la - -convenience_la_SOURCES = \ - conveniencecomponent.cpp \ - conveniencecomponent.h \ - i2-convenience.h - -convenience_la_CPPFLAGS = \ - $(BOOST_CPPFLAGS) \ - -I${top_srcdir}/lib/base \ - -I${top_srcdir}/lib/config \ - -I${top_srcdir}/lib/remoting \ - -I${top_srcdir}/lib/icinga - -convenience_la_LDFLAGS = \ - $(BOOST_LDFLAGS) \ - -module \ - -no-undefined \ - @RELEASE_INFO@ \ - @VERSION_INFO@ - -convenience_la_LIBADD = \ - $(BOOST_SIGNALS_LIB) \ - $(BOOST_THREAD_LIB) \ - ${top_builddir}/lib/base/libbase.la \ - ${top_builddir}/lib/config/libconfig.la \ - ${top_builddir}/lib/remoting/libremoting.la \ - ${top_builddir}/lib/icinga/libicinga.la diff --git a/components/convenience/convenience.vcxproj b/components/convenience/convenience.vcxproj deleted file mode 100644 index 39cd65bc6..000000000 --- a/components/convenience/convenience.vcxproj +++ /dev/null @@ -1,90 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {D02A349B-BAF7-41FB-86FF-B05BA05FE578} - Win32Proj - convenience - - - - DynamicLibrary - true - MultiByte - - - DynamicLibrary - false - true - MultiByte - - - - - - - - - - - - - true - $(SolutionDir)\lib\base;$(SolutionDir)\lib\remoting;$(SolutionDir)\lib\icinga;$(SolutionDir)\lib\config;$(IncludePath) - $(OutDir);$(LibraryPath) - - - false - $(SolutionDir)\lib\base;$(SolutionDir)\lib\remoting;$(SolutionDir)\lib\icinga;$(SolutionDir)\lib\config;$(IncludePath) - $(OutDir);$(LibraryPath) - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;CONVENIENCE_EXPORTS;%(PreprocessorDefinitions) - true - - - Windows - true - base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;CONVENIENCE_EXPORTS;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies) - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/convenience/convenience.vcxproj.filters b/components/convenience/convenience.vcxproj.filters deleted file mode 100644 index 9a47a8313..000000000 --- a/components/convenience/convenience.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Quelldateien - - - - - Headerdateien - - - Headerdateien - - - \ No newline at end of file diff --git a/components/convenience/conveniencecomponent.cpp b/components/convenience/conveniencecomponent.cpp deleted file mode 100644 index e4caea210..000000000 --- a/components/convenience/conveniencecomponent.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/****************************************************************************** - * 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. * - ******************************************************************************/ - -#include "i2-convenience.h" - -using namespace icinga; - -/** - * Starts the component. - */ -void ConvenienceComponent::Start(void) -{ - ConfigItem::OnCommitted.connect(boost::bind(&ConvenienceComponent::ObjectCommittedHandler, this, _1)); - ConfigItem::OnRemoved.connect(boost::bind(&ConvenienceComponent::ObjectRemovedHandler, this, _1)); -} - -template -static void CopyServiceAttributes(const Host::Ptr& host, TDict serviceDesc, - const ConfigItemBuilder::Ptr& builder) -{ - /* TODO: we only need to copy macros if this is an inline definition, - * i.e. host->GetProperties() != service, however for now we just - * copy them anyway. */ - Value macros = serviceDesc->Get("macros"); - if (!macros.IsEmpty()) - builder->AddExpression("macros", OperatorPlus, macros); - - Value checkInterval = serviceDesc->Get("check_interval"); - if (!checkInterval.IsEmpty()) - builder->AddExpression("check_interval", OperatorSet, checkInterval); - - Value retryInterval = serviceDesc->Get("retry_interval"); - if (!retryInterval.IsEmpty()) - builder->AddExpression("retry_interval", OperatorSet, retryInterval); - - Value sgroups = serviceDesc->Get("servicegroups"); - if (!sgroups.IsEmpty()) - builder->AddExpression("servicegroups", OperatorPlus, sgroups); - - Value checkers = serviceDesc->Get("checkers"); - if (!checkers.IsEmpty()) - builder->AddExpression("checkers", OperatorSet, checkers); - - Value dependencies = serviceDesc->Get("dependencies"); - if (!dependencies.IsEmpty()) - builder->AddExpression("dependencies", OperatorPlus, - Service::ResolveDependencies(host, dependencies)); - - Value hostchecks = serviceDesc->Get("hostchecks"); - if (!hostchecks.IsEmpty()) - builder->AddExpression("dependencies", OperatorPlus, - Service::ResolveDependencies(host, hostchecks)); -} - -void ConvenienceComponent::ObjectCommittedHandler(const ConfigItem::Ptr& item) -{ - if (item->GetType() != "Host") - return; - - /* ignore abstract host objects */ - if (!Host::Exists(item->GetName())) - return; - - Host::Ptr host = Host::GetByName(item->GetName()); - - Dictionary::Ptr oldServices = host->Get("convenience_services"); - - Dictionary::Ptr newServices; - newServices = boost::make_shared(); - - Dictionary::Ptr serviceDescs = host->Get("services"); - - if (serviceDescs) { - String svcname; - Value svcdesc; - BOOST_FOREACH(tie(svcname, svcdesc), serviceDescs) { - stringstream namebuf; - namebuf << item->GetName() << "-" << svcname; - String name = namebuf.str(); - - ConfigItemBuilder::Ptr builder = boost::make_shared(item->GetDebugInfo()); - builder->SetType("Service"); - builder->SetName(name); - builder->AddExpression("host_name", OperatorSet, item->GetName()); - builder->AddExpression("alias", OperatorSet, svcname); - - CopyServiceAttributes(host, host, builder); - - if (svcdesc.IsScalar()) { - builder->AddParent(svcdesc); - } else if (svcdesc.IsObjectType()) { - Dictionary::Ptr service = svcdesc; - - String parent = service->Get("service"); - if (parent.IsEmpty()) - parent = svcname; - - builder->AddParent(parent); - - CopyServiceAttributes(host, service, builder); - } else { - throw_exception(invalid_argument("Service description must be either a string or a dictionary.")); - } - - ConfigItem::Ptr serviceItem = builder->Compile(); - serviceItem->Commit(); - - newServices->Set(name, serviceItem); - } - } - - if (oldServices) { - ConfigItem::Ptr service; - BOOST_FOREACH(tie(tuples::ignore, service), oldServices) { - if (!service) - continue; - - if (!newServices->Contains(service->GetName())) - service->Unregister(); - } - } - - host->Set("convenience_services", newServices); -} - -void ConvenienceComponent::ObjectRemovedHandler(const ConfigItem::Ptr& item) -{ - if (item->GetType() != "Host") - return; - - DynamicObject::Ptr host = item->GetDynamicObject(); - - if (!host) - return; - - Dictionary::Ptr services = host->Get("convenience_services"); - - if (!services) - return; - - ConfigItem::Ptr service; - BOOST_FOREACH(tie(tuples::ignore, service), services) { - service->Unregister(); - } -} - -EXPORT_COMPONENT(convenience, ConvenienceComponent); - diff --git a/components/convenience/conveniencecomponent.h b/components/convenience/conveniencecomponent.h deleted file mode 100644 index e1d7db788..000000000 --- a/components/convenience/conveniencecomponent.h +++ /dev/null @@ -1,41 +0,0 @@ -/****************************************************************************** - * 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 CONVENIENCECOMPONENT_H -#define CONVENIENCECOMPONENT_H - -namespace icinga -{ - -/** - * @ingroup convenience - */ -class ConvenienceComponent : public IComponent -{ -public: - virtual void Start(void); - -private: - void ObjectCommittedHandler(const ConfigItem::Ptr& item); - void ObjectRemovedHandler(const ConfigItem::Ptr& item); -}; - -} - -#endif /* CONVENIENCECOMPONENT_H */ diff --git a/components/convenience/i2-convenience.h b/components/convenience/i2-convenience.h deleted file mode 100644 index a2a9ef47e..000000000 --- a/components/convenience/i2-convenience.h +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * 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 I2CONVENIENCE_H -#define I2CONVENIENCE_H - -/** - * @defgroup convenience Convenience component - * - * The convenience component takes service definitions from host objects - * and creates service objects. Technically this isn't strictly necessary but - * makes defining services a lot easier for users. - */ - -#include -#include -#include -#include - -#include "conveniencecomponent.h" - -#endif /* I2CONVENIENCE_H */ diff --git a/configure.ac b/configure.ac index 707c2fe90..d91d07e77 100644 --- a/configure.ac +++ b/configure.ac @@ -70,7 +70,6 @@ Makefile components/Makefile components/checker/Makefile components/compat/Makefile -components/convenience/Makefile components/delegation/Makefile components/demo/Makefile components/replication/Makefile diff --git a/icinga-app/Makefile.am b/icinga-app/Makefile.am index 3f7e5a68c..9495c6d35 100644 --- a/icinga-app/Makefile.am +++ b/icinga-app/Makefile.am @@ -34,10 +34,8 @@ icinga2_LDADD = \ -dlopen ${top_builddir}/components/checker/checker.la \ -dlopen ${top_builddir}/components/replication/replication.la \ -dlopen ${top_builddir}/components/compat/compat.la \ - -dlopen ${top_builddir}/components/convenience/convenience.la \ -dlopen ${top_builddir}/components/delegation/delegation.la \ -dlopen ${top_builddir}/components/demo/demo.la icinga2_DEPENDENCIES = \ - ${top_builddir}/components/replication/replication.la \ - ${top_builddir}/components/convenience/convenience.la + ${top_builddir}/components/replication/replication.la diff --git a/icinga2.sln b/icinga2.sln index 8f476609e..8c39f2253 100644 --- a/icinga2.sln +++ b/icinga2.sln @@ -7,7 +7,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga-app", "icinga-app\ic {2E6C1133-730F-4875-A72C-B455B1DD4C5C} = {2E6C1133-730F-4875-A72C-B455B1DD4C5C} {17C93245-8C20-4316-9573-1AE41D918C10} = {17C93245-8C20-4316-9573-1AE41D918C10} {704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C} = {704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C} - {D02A349B-BAF7-41FB-86FF-B05BA05FE578} = {D02A349B-BAF7-41FB-86FF-B05BA05FE578} {38CE81CC-2660-4EF0-A936-4A337591DA3E} = {38CE81CC-2660-4EF0-A936-4A337591DA3E} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} EndProjectSection @@ -41,11 +40,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compat", "components\compat {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "convenience", "components\convenience\convenience.vcxproj", "{D02A349B-BAF7-41FB-86FF-B05BA05FE578}" - ProjectSection(ProjectDependencies) = postProject - {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "components", "components", "{4A1773FD-DDED-4952-8700-C898E890554A}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libraries", "libraries", "{BC82DE9C-42E2-4880-92DA-C2269D2F6416}" @@ -114,10 +108,6 @@ Global {2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}.Debug|Win32.Build.0 = Debug|Win32 {2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}.Release|Win32.ActiveCfg = Release|Win32 {2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}.Release|Win32.Build.0 = Release|Win32 - {D02A349B-BAF7-41FB-86FF-B05BA05FE578}.Debug|Win32.ActiveCfg = Debug|Win32 - {D02A349B-BAF7-41FB-86FF-B05BA05FE578}.Debug|Win32.Build.0 = Debug|Win32 - {D02A349B-BAF7-41FB-86FF-B05BA05FE578}.Release|Win32.ActiveCfg = Release|Win32 - {D02A349B-BAF7-41FB-86FF-B05BA05FE578}.Release|Win32.Build.0 = Release|Win32 {9C92DA90-FD53-43A9-A244-90F2E8AF9677}.Debug|Win32.ActiveCfg = Debug|Win32 {9C92DA90-FD53-43A9-A244-90F2E8AF9677}.Debug|Win32.Build.0 = Debug|Win32 {9C92DA90-FD53-43A9-A244-90F2E8AF9677}.Release|Win32.ActiveCfg = Release|Win32 @@ -143,7 +133,6 @@ Global {17C93245-8C20-4316-9573-1AE41D918C10} = {4A1773FD-DDED-4952-8700-C898E890554A} {704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C} = {4A1773FD-DDED-4952-8700-C898E890554A} {2BD1C70C-43DB-4F44-B66B-67CF5C7044AA} = {4A1773FD-DDED-4952-8700-C898E890554A} - {D02A349B-BAF7-41FB-86FF-B05BA05FE578} = {4A1773FD-DDED-4952-8700-C898E890554A} {2E6C1133-730F-4875-A72C-B455B1DD4C5C} = {4A1773FD-DDED-4952-8700-C898E890554A} {19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {3BE47C55-D74A-46E6-8F8B-470B3FD29FB7} {66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {3BE47C55-D74A-46E6-8F8B-470B3FD29FB7} diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index 758484a14..bd292878b 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -58,7 +58,7 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, const LogEntry& entry) time_t ts = entry.Timestamp; tm tmnow = *localtime(&ts); - strftime(timestamp, sizeof(timestamp), "%Y/%m/%d %H:%M:%S", &tmnow); + strftime(timestamp, sizeof(timestamp), "%a, %d %b %Y %T %z", &tmnow); stream << "[" << timestamp << "] " << Logger::SeverityToString(entry.Severity) << "/" << entry.Facility << ": " diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index f4aff61f1..95fe7e0a3 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -23,9 +23,18 @@ using namespace icinga; REGISTER_CLASS(Host); +bool Host::m_InitializerDone = false; + Host::Host(const Dictionary::Ptr& properties) : DynamicObject(properties) { + if (!m_InitializerDone) { + ConfigItem::OnCommitted.connect(boost::bind(&Host::ObjectCommittedHandler, this, _1)); + ConfigItem::OnRemoved.connect(boost::bind(&Host::ObjectRemovedHandler, this, _1)); + + m_InitializerDone = true; + } + RegisterAttribute("alias", Attribute_Config); RegisterAttribute("hostgroups", Attribute_Config); } @@ -127,3 +136,134 @@ bool Host::IsUp(void) return true; } + +template +static void CopyServiceAttributes(const Host::Ptr& host, TDict serviceDesc, + const ConfigItemBuilder::Ptr& builder) +{ + /* TODO: we only need to copy macros if this is an inline definition, + * i.e. host->GetProperties() != service, however for now we just + * copy them anyway. */ + Value macros = serviceDesc->Get("macros"); + if (!macros.IsEmpty()) + builder->AddExpression("macros", OperatorPlus, macros); + + Value checkInterval = serviceDesc->Get("check_interval"); + if (!checkInterval.IsEmpty()) + builder->AddExpression("check_interval", OperatorSet, checkInterval); + + Value retryInterval = serviceDesc->Get("retry_interval"); + if (!retryInterval.IsEmpty()) + builder->AddExpression("retry_interval", OperatorSet, retryInterval); + + Value sgroups = serviceDesc->Get("servicegroups"); + if (!sgroups.IsEmpty()) + builder->AddExpression("servicegroups", OperatorPlus, sgroups); + + Value checkers = serviceDesc->Get("checkers"); + if (!checkers.IsEmpty()) + builder->AddExpression("checkers", OperatorSet, checkers); + + Value dependencies = serviceDesc->Get("dependencies"); + if (!dependencies.IsEmpty()) + builder->AddExpression("dependencies", OperatorPlus, + Service::ResolveDependencies(host, dependencies)); + + Value hostchecks = serviceDesc->Get("hostchecks"); + if (!hostchecks.IsEmpty()) + builder->AddExpression("dependencies", OperatorPlus, + Service::ResolveDependencies(host, hostchecks)); +} + +void Host::ObjectCommittedHandler(const ConfigItem::Ptr& item) +{ + if (item->GetType() != "Host") + return; + + /* ignore abstract host objects */ + if (!Host::Exists(item->GetName())) + return; + + Host::Ptr host = Host::GetByName(item->GetName()); + + Dictionary::Ptr oldServices = host->Get("convenience_services"); + + Dictionary::Ptr newServices; + newServices = boost::make_shared(); + + Dictionary::Ptr serviceDescs = host->Get("services"); + + if (serviceDescs) { + String svcname; + Value svcdesc; + BOOST_FOREACH(tie(svcname, svcdesc), serviceDescs) { + stringstream namebuf; + namebuf << item->GetName() << "-" << svcname; + String name = namebuf.str(); + + ConfigItemBuilder::Ptr builder = boost::make_shared(item->GetDebugInfo()); + builder->SetType("Service"); + builder->SetName(name); + builder->AddExpression("host_name", OperatorSet, item->GetName()); + builder->AddExpression("alias", OperatorSet, svcname); + + CopyServiceAttributes(host, host, builder); + + if (svcdesc.IsScalar()) { + builder->AddParent(svcdesc); + } else if (svcdesc.IsObjectType()) { + Dictionary::Ptr service = svcdesc; + + String parent = service->Get("service"); + if (parent.IsEmpty()) + parent = svcname; + + builder->AddParent(parent); + + CopyServiceAttributes(host, service, builder); + } else { + throw_exception(invalid_argument("Service description must be either a string or a dictionary.")); + } + + ConfigItem::Ptr serviceItem = builder->Compile(); + serviceItem->Commit(); + + newServices->Set(name, serviceItem); + } + } + + if (oldServices) { + ConfigItem::Ptr service; + BOOST_FOREACH(tie(tuples::ignore, service), oldServices) { + if (!service) + continue; + + if (!newServices->Contains(service->GetName())) + service->Unregister(); + } + } + + host->Set("convenience_services", newServices); +} + +void Host::ObjectRemovedHandler(const ConfigItem::Ptr& item) +{ + if (item->GetType() != "Host") + return; + + DynamicObject::Ptr host = item->GetDynamicObject(); + + if (!host) + return; + + Dictionary::Ptr services = host->Get("convenience_services"); + + if (!services) + return; + + ConfigItem::Ptr service; + BOOST_FOREACH(tie(tuples::ignore, service), services) { + service->Unregister(); + } +} + diff --git a/lib/icinga/host.h b/lib/icinga/host.h index 26d06bac0..48ef812b6 100644 --- a/lib/icinga/host.h +++ b/lib/icinga/host.h @@ -46,6 +46,12 @@ public: bool IsReachable(void); bool IsUp(void); + +private: + static bool m_InitializerDone; + + void ObjectCommittedHandler(const ConfigItem::Ptr& item); + void ObjectRemovedHandler(const ConfigItem::Ptr& item); }; } diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index a2764db65..4b83891c0 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -41,14 +41,6 @@ IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate) replicationComponentConfig->SetLocal(true); replicationComponentConfig->Compile()->Commit(); replicationComponentConfig.reset(); - - /* load convenience config component */ - ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared(); - convenienceComponentConfig->SetType("Component"); - convenienceComponentConfig->SetName("convenience"); - convenienceComponentConfig->SetLocal(true); - convenienceComponentConfig->Compile()->Commit(); - convenienceComponentConfig.reset(); } /**