Added delegation component.

This commit is contained in:
Gunnar Beutner 2012-06-14 13:21:40 +02:00
parent b0a372c5f8
commit 27f9d9373c
12 changed files with 332 additions and 14 deletions

View File

@ -5,5 +5,6 @@ SUBDIRS = \
checker \
configfile \
configrpc \
delegation \
demo \
discovery

View 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

View 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)

View 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);

View File

@ -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

View File

@ -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>

View File

@ -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);

View File

@ -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 */

View File

@ -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 */

View 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

View File

@ -6,6 +6,10 @@ local object component "checker" {
}
local object component "delegation" {
}
object host "localhost" {
}

View 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