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 941e4c038..e9281a246 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) @@ -59,14 +59,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<ConfigObject::Ptr>& 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<ConfigObject::Ptr>& 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{17C93245-8C20-4316-9573-1AE41D918C10}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>delegation</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <LinkIncremental>true</LinkIncremental> + <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath> + <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath> + <LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <PrecompiledHeader> + </PrecompiledHeader> + <WarningLevel>Level3</WarningLevel> + <Optimization>Disabled</Optimization> + <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DELEGATION_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <AdditionalDependencies>base.lib;dyn.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DELEGATION_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>base.lib;dyn.lib;jsonrpc.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="delegationcomponent.cpp" /> + </ItemGroup> + <ItemGroup> + <ClInclude Include="delegationcomponent.h" /> + <ClInclude Include="i2-delegation.h" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ 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::Set>(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<VirtualEndpoint>(); + 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<ConfigObject::Ptr>& ea) +{ + AssignService(ea.Target); + return 0; +} + +int DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& 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<ConfigObject::Ptr>& ea); + int RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& 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 <i2-base.h> +#include <i2-icinga.h> + +#include "delegationcomponent.h" + +#endif /* I2DELEGATION_H */ diff --git a/configure.ac b/configure.ac index c71c5ea92..11f7b0db1 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