From 27f9d9373c8b0fea9d96639e7b699810eec1c483 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 14 Jun 2012 13:21:40 +0200 Subject: [PATCH] Added delegation component. --- components/Makefile.am | 1 + components/checker/Makefile.am | 1 + components/checker/checkercomponent.cpp | 17 +-- components/checker/checkercomponent.h | 1 - components/delegation/Makefile.am | 27 +++++ components/delegation/delegation.vcxproj | 92 ++++++++++++++++ components/delegation/delegationcomponent.cpp | 102 ++++++++++++++++++ components/delegation/delegationcomponent.h | 54 ++++++++++ components/delegation/i2-delegation.h | 34 ++++++ configure.ac | 1 + icinga-app/icinga-standalone.conf | 4 + icinga.sln | 12 +++ 12 files changed, 332 insertions(+), 14 deletions(-) create mode 100644 components/delegation/Makefile.am create mode 100644 components/delegation/delegation.vcxproj create mode 100644 components/delegation/delegationcomponent.cpp create mode 100644 components/delegation/delegationcomponent.h create mode 100644 components/delegation/i2-delegation.h diff --git a/components/Makefile.am b/components/Makefile.am index 4a6cb77a7..d2dc2039c 100644 --- a/components/Makefile.am +++ b/components/Makefile.am @@ -5,5 +5,6 @@ SUBDIRS = \ checker \ configfile \ configrpc \ + delegation \ demo \ discovery diff --git a/components/checker/Makefile.am b/components/checker/Makefile.am index 544845031..63f35d0af 100644 --- a/components/checker/Makefile.am +++ b/components/checker/Makefile.am @@ -23,4 +23,5 @@ checker_la_LDFLAGS = \ checker_la_LIBADD = \ ${top_builddir}/base/libbase.la \ + ${top_builddir}/jsonrpc/libjsonrpc.la \ ${top_builddir}/icinga/libicinga.la diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 56d194aa3..bc7626a36 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -23,7 +23,7 @@ using namespace icinga; string CheckerComponent::GetName(void) const { - return "configcomponent"; + return "checker"; } void CheckerComponent::Start(void) @@ -36,13 +36,6 @@ void CheckerComponent::Start(void) m_CheckerEndpoint->RegisterPublication("checker::CheckResult"); GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint); - RequestMessage rm; - rm.SetMethod("checker::AssignService"); - GetEndpointManager()->SendAPIMessage(m_CheckerEndpoint, rm, bind(&CheckerComponent::TestResponseHandler, this, _1)); - - // TODO: get rid of this - ConfigObject::GetAllObjects()->OnObjectAdded += bind_weak(&CheckerComponent::NewServiceHandler, shared_from_this()); - m_CheckTimer = make_shared(); m_CheckTimer->SetInterval(10); m_CheckTimer->OnTimerExpired += bind_weak(&CheckerComponent::CheckTimerHandler, shared_from_this()); @@ -59,14 +52,12 @@ void CheckerComponent::Start(void) } } -int CheckerComponent::TestResponseHandler(const NewResponseEventArgs& ea) -{ - return 0; -} - void CheckerComponent::Stop(void) { + EndpointManager::Ptr mgr = GetEndpointManager(); + if (mgr) + mgr->UnregisterEndpoint(m_CheckerEndpoint); } int CheckerComponent::NewServiceHandler(const ObjectSetEventArgs& ea) diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index b655496d6..320de7d3c 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -50,7 +50,6 @@ private: int NewServiceHandler(const ObjectSetEventArgs& ea); int CheckTimerHandler(const TimerEventArgs& ea); - int TestResponseHandler(const NewResponseEventArgs& ea); int AssignServiceRequestHandler(const NewRequestEventArgs& nrea); int RevokeServiceRequestHandler(const NewRequestEventArgs& nrea); diff --git a/components/delegation/Makefile.am b/components/delegation/Makefile.am new file mode 100644 index 000000000..133f4d2c2 --- /dev/null +++ b/components/delegation/Makefile.am @@ -0,0 +1,27 @@ +## Process this file with automake to produce Makefile.in + +pkglib_LTLIBRARIES = \ + delegation.la + +delegation_la_SOURCES = \ + delegationcomponent.cpp \ + delegationcomponent.h \ + i2-delegation.h + +delegation_la_CPPFLAGS = \ + $(BOOST_CPPFLAGS) \ + -I${top_srcdir}/base \ + -I${top_srcdir}/jsonrpc \ + -I${top_srcdir}/icinga + +delegation_la_LDFLAGS = \ + $(BOOST_LDFLAGS) \ + -module \ + -no-undefined \ + @RELEASE_INFO@ \ + @VERSION_INFO@ + +delegation_la_LIBADD = \ + ${top_builddir}/base/libbase.la \ + ${top_builddir}/jsonrpc/libjsonrpc.la \ + ${top_builddir}/icinga/libicinga.la diff --git a/components/delegation/delegation.vcxproj b/components/delegation/delegation.vcxproj new file mode 100644 index 000000000..cfe75bea3 --- /dev/null +++ b/components/delegation/delegation.vcxproj @@ -0,0 +1,92 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {17C93245-8C20-4316-9573-1AE41D918C10} + Win32Proj + delegation + + + + DynamicLibrary + true + MultiByte + + + DynamicLibrary + false + true + MultiByte + + + + + + + + + + + + + true + $(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath) + $(OutDir);$(LibraryPath) + + + false + $(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath) + $(OutDir);$(LibraryPath) + + + + + + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;DELEGATION_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + base.lib;dyn.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;DELEGATION_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + true + true + base.lib;dyn.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies) + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/delegation/delegationcomponent.cpp b/components/delegation/delegationcomponent.cpp new file mode 100644 index 000000000..8c6c50f26 --- /dev/null +++ b/components/delegation/delegationcomponent.cpp @@ -0,0 +1,102 @@ +/****************************************************************************** + * 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-delegation.h" + +using namespace icinga; + +string DelegationComponent::GetName(void) const +{ + return "delegation"; +} + +void DelegationComponent::Start(void) +{ + m_AllServices = make_shared(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service")); + m_AllServices->OnObjectAdded += bind_weak(&DelegationComponent::NewServiceHandler, shared_from_this()); + m_AllServices->OnObjectCommitted += bind_weak(&DelegationComponent::NewServiceHandler, shared_from_this()); + m_AllServices->OnObjectRemoved += bind_weak(&DelegationComponent::RemovedServiceHandler, shared_from_this()); + m_AllServices->Start(); + + m_DelegationEndpoint = make_shared(); + m_DelegationEndpoint->RegisterPublication("checker::AssignService"); + m_DelegationEndpoint->RegisterPublication("checker::RevokeService"); + GetEndpointManager()->RegisterEndpoint(m_DelegationEndpoint); + + RequestMessage rm; + rm.SetMethod("checker::AssignService"); + GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, rm, bind(&DelegationComponent::TestResponseHandler, this, _1)); +} + +void DelegationComponent::Stop(void) +{ + EndpointManager::Ptr mgr = GetEndpointManager(); + + if (mgr) + mgr->UnregisterEndpoint(m_DelegationEndpoint); +} + +int DelegationComponent::NewServiceHandler(const ObjectSetEventArgs& ea) +{ + AssignService(ea.Target); + return 0; +} + +int DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs& ea) +{ + RevokeService(ea.Target); + return 0; +} + +void DelegationComponent::AssignService(const ConfigObject::Ptr& service) +{ + RequestMessage request; + request.SetMethod("checker::AssignService"); + + MessagePart params; + params.SetProperty("service", service->GetProperties()); + request.SetParams(params); + + GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request, + bind_weak(&DelegationComponent::AssignServiceResponseHandler, shared_from_this())); +} + +int DelegationComponent::AssignServiceResponseHandler(const NewResponseEventArgs& nrea) +{ + return 0; +} + +void DelegationComponent::RevokeService(const ConfigObject::Ptr& service) +{ + +} + +int DelegationComponent::RevokeServiceResponseHandler(const NewResponseEventArgs& nrea) +{ + return 0; +} + +int DelegationComponent::TestResponseHandler(const NewResponseEventArgs& ea) +{ + Application::Log("Response handler called."); + + return 0; +} + +EXPORT_COMPONENT(delegation, DelegationComponent); diff --git a/components/delegation/delegationcomponent.h b/components/delegation/delegationcomponent.h new file mode 100644 index 000000000..7712ef9f3 --- /dev/null +++ b/components/delegation/delegationcomponent.h @@ -0,0 +1,54 @@ +/****************************************************************************** + * 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 DELEGATIONCOMPONENT_H +#define DELEGATIONCOMPONENT_H + +namespace icinga +{ + +/** + * @ingroup delegation + */ +class DelegationComponent : public IcingaComponent +{ +public: + virtual string GetName(void) const; + virtual void Start(void); + virtual void Stop(void); + +private: + VirtualEndpoint::Ptr m_DelegationEndpoint; + ConfigObject::Set::Ptr m_AllServices; + + int NewServiceHandler(const ObjectSetEventArgs& ea); + int RemovedServiceHandler(const ObjectSetEventArgs& ea); + + int AssignServiceResponseHandler(const NewResponseEventArgs& nrea); + int RevokeServiceResponseHandler(const NewResponseEventArgs& nrea); + + void AssignService(const ConfigObject::Ptr& service); + void RevokeService(const ConfigObject::Ptr& service); + + int TestResponseHandler(const NewResponseEventArgs& ea); +}; + +} + +#endif /* DELEGATIONCOMPONENT_H */ diff --git a/components/delegation/i2-delegation.h b/components/delegation/i2-delegation.h new file mode 100644 index 000000000..91e633ee5 --- /dev/null +++ b/components/delegation/i2-delegation.h @@ -0,0 +1,34 @@ +/****************************************************************************** + * 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 I2DELEGATION_H +#define I2DELEGATION_H + +/** + * @defgroup delegation Delegation component + * + * The Delegation component delegates service checks to the checker component. + */ + +#include +#include + +#include "delegationcomponent.h" + +#endif /* I2DELEGATION_H */ diff --git a/configure.ac b/configure.ac index 11ad8707f..e10a91d1f 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,7 @@ components/Makefile components/checker/Makefile components/configfile/Makefile components/configrpc/Makefile +components/delegation/Makefile components/demo/Makefile components/discovery/Makefile dyn/Makefile diff --git a/icinga-app/icinga-standalone.conf b/icinga-app/icinga-standalone.conf index c4d42e4dd..dd2799e64 100644 --- a/icinga-app/icinga-standalone.conf +++ b/icinga-app/icinga-standalone.conf @@ -6,6 +6,10 @@ local object component "checker" { } +local object component "delegation" { + +} + object host "localhost" { } diff --git a/icinga.sln b/icinga.sln index 8d3824492..372c25499 100644 --- a/icinga.sln +++ b/icinga.sln @@ -22,6 +22,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icinga-app", "icinga-app\ic ProjectSection(ProjectDependencies) = postProject {EAD41628-BB96-4F99-9070-8A9676801295} = {EAD41628-BB96-4F99-9070-8A9676801295} {2E6C1133-730F-4875-A72C-B455B1DD4C5C} = {2E6C1133-730F-4875-A72C-B455B1DD4C5C} + {17C93245-8C20-4316-9573-1AE41D918C10} = {17C93245-8C20-4316-9573-1AE41D918C10} {697C6D7E-3109-484C-A7AF-384D28711610} = {697C6D7E-3109-484C-A7AF-384D28711610} {E58F1DA7-B723-412B-B2B7-7FF58E2A944E} = {E58F1DA7-B723-412B-B2B7-7FF58E2A944E} {38CE81CC-2660-4EF0-A936-4A337591DA3E} = {38CE81CC-2660-4EF0-A936-4A337591DA3E} @@ -65,6 +66,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dyntest", "dyntest\dyntest. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checker", "components\checker\checker.vcxproj", "{38CE81CC-2660-4EF0-A936-4A337591DA3E}" ProjectSection(ProjectDependencies) = postProject + {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} = {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} + {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "delegation", "components\delegation\delegation.vcxproj", "{17C93245-8C20-4316-9573-1AE41D918C10}" + ProjectSection(ProjectDependencies) = postProject + {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} = {8DD52FAC-ECEE-48C2-B266-E7C47ED485F8} {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} EndProjectSection EndProject @@ -126,6 +134,10 @@ Global {38CE81CC-2660-4EF0-A936-4A337591DA3E}.Debug|Win32.Build.0 = Debug|Win32 {38CE81CC-2660-4EF0-A936-4A337591DA3E}.Release|Win32.ActiveCfg = Release|Win32 {38CE81CC-2660-4EF0-A936-4A337591DA3E}.Release|Win32.Build.0 = Release|Win32 + {17C93245-8C20-4316-9573-1AE41D918C10}.Debug|Win32.ActiveCfg = Debug|Win32 + {17C93245-8C20-4316-9573-1AE41D918C10}.Debug|Win32.Build.0 = Debug|Win32 + {17C93245-8C20-4316-9573-1AE41D918C10}.Release|Win32.ActiveCfg = Release|Win32 + {17C93245-8C20-4316-9573-1AE41D918C10}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- 2.40.0