]> granicus.if.org Git - icinga2/commitdiff
Added delegation component.
authorGunnar Beutner <gunnar@beutner.name>
Thu, 14 Jun 2012 11:21:40 +0000 (13:21 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Thu, 14 Jun 2012 11:21:40 +0000 (13:21 +0200)
12 files changed:
components/Makefile.am
components/checker/Makefile.am
components/checker/checkercomponent.cpp
components/checker/checkercomponent.h
components/delegation/Makefile.am [new file with mode: 0644]
components/delegation/delegation.vcxproj [new file with mode: 0644]
components/delegation/delegationcomponent.cpp [new file with mode: 0644]
components/delegation/delegationcomponent.h [new file with mode: 0644]
components/delegation/i2-delegation.h [new file with mode: 0644]
configure.ac
icinga-app/icinga-standalone.conf
icinga.sln

index 4a6cb77a7caec48244b4e15e6931504ee7c2d3f6..d2dc2039cf570bd72774342a595373090e8cad5a 100644 (file)
@@ -5,5 +5,6 @@ SUBDIRS = \
        checker \
        configfile \
        configrpc \
+       delegation \
        demo \
        discovery
index 5448450314dd620ba285b92af61c31cdef813f0e..63f35d0af128f3fb066598f0c8a4dc5f82e8e568 100644 (file)
@@ -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
index 56d194aa3cc1eb91fa79fcfe5ec08affa7ab0530..bc7626a36963b8aeca0c6e49e86695c561595afc 100644 (file)
@@ -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<Timer>();
        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<ConfigObject::Ptr>& ea)
index b655496d6db87a28ec381b2492d1c0fc1125b4ed..320de7d3c164e1962c0d8d417d9eb35913edaea6 100644 (file)
@@ -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 (file)
index 0000000..133f4d2
--- /dev/null
@@ -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 (file)
index 0000000..cfe75be
--- /dev/null
@@ -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 (file)
index 0000000..8c6c50f
--- /dev/null
@@ -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 (file)
index 0000000..7712ef9
--- /dev/null
@@ -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 (file)
index 0000000..91e633e
--- /dev/null
@@ -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 */
index 11ad8707f3aaf44b5306767da8a6ff489a23adc1..e10a91d1f1bbeda4974ebdf5fdcb78efd7f1636d 100644 (file)
@@ -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
index c4d42e4dd6c8dc583c81f3a810d164a7062a5f18..dd2799e64bc0d45e88b8a6bcbbee3dffb675b67c 100644 (file)
@@ -6,6 +6,10 @@ local object component "checker" {
 
 }
 
+local object component "delegation" {
+
+}
+
 object host "localhost" {
 
 }
index 8d3824492ee9e730ca8a63d39bc6df72028fa2a9..372c254993bfdeb6c1dbff789f59407a1824faa1 100644 (file)
@@ -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