mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 15:14:07 +02:00
Merged convenience component into libicinga.
This commit is contained in:
parent
97829fbfcd
commit
5921337b46
@ -4,7 +4,6 @@
|
|||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
checker \
|
checker \
|
||||||
compat \
|
compat \
|
||||||
convenience \
|
|
||||||
delegation \
|
delegation \
|
||||||
demo \
|
demo \
|
||||||
replication
|
replication
|
||||||
|
@ -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
|
|
@ -1,90 +0,0 @@
|
|||||||
<?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>{D02A349B-BAF7-41FB-86FF-B05BA05FE578}</ProjectGuid>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<RootNamespace>convenience</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)\lib\base;$(SolutionDir)\lib\remoting;$(SolutionDir)\lib\icinga;$(SolutionDir)\lib\config;$(IncludePath)</IncludePath>
|
|
||||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<LinkIncremental>false</LinkIncremental>
|
|
||||||
<IncludePath>$(SolutionDir)\lib\base;$(SolutionDir)\lib\remoting;$(SolutionDir)\lib\icinga;$(SolutionDir)\lib\config;$(IncludePath)</IncludePath>
|
|
||||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CONVENIENCE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Windows</SubSystem>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CONVENIENCE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Windows</SubSystem>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
|
||||||
<AdditionalDependencies>base.lib;config.lib;remoting.lib;icinga.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="conveniencecomponent.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="conveniencecomponent.h" />
|
|
||||||
<ClInclude Include="i2-convenience.h" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
@ -1,30 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup>
|
|
||||||
<Filter Include="Quelldateien">
|
|
||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
|
||||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Headerdateien">
|
|
||||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
|
||||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="Ressourcendateien">
|
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="conveniencecomponent.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="conveniencecomponent.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="i2-convenience.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
@ -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<typename TDict>
|
|
||||||
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>();
|
|
||||||
|
|
||||||
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<ConfigItemBuilder>(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>()) {
|
|
||||||
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);
|
|
||||||
|
|
@ -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 */
|
|
@ -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 <i2-base.h>
|
|
||||||
#include <i2-config.h>
|
|
||||||
#include <i2-remoting.h>
|
|
||||||
#include <i2-icinga.h>
|
|
||||||
|
|
||||||
#include "conveniencecomponent.h"
|
|
||||||
|
|
||||||
#endif /* I2CONVENIENCE_H */
|
|
@ -70,7 +70,6 @@ Makefile
|
|||||||
components/Makefile
|
components/Makefile
|
||||||
components/checker/Makefile
|
components/checker/Makefile
|
||||||
components/compat/Makefile
|
components/compat/Makefile
|
||||||
components/convenience/Makefile
|
|
||||||
components/delegation/Makefile
|
components/delegation/Makefile
|
||||||
components/demo/Makefile
|
components/demo/Makefile
|
||||||
components/replication/Makefile
|
components/replication/Makefile
|
||||||
|
@ -34,10 +34,8 @@ icinga2_LDADD = \
|
|||||||
-dlopen ${top_builddir}/components/checker/checker.la \
|
-dlopen ${top_builddir}/components/checker/checker.la \
|
||||||
-dlopen ${top_builddir}/components/replication/replication.la \
|
-dlopen ${top_builddir}/components/replication/replication.la \
|
||||||
-dlopen ${top_builddir}/components/compat/compat.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/delegation/delegation.la \
|
||||||
-dlopen ${top_builddir}/components/demo/demo.la
|
-dlopen ${top_builddir}/components/demo/demo.la
|
||||||
|
|
||||||
icinga2_DEPENDENCIES = \
|
icinga2_DEPENDENCIES = \
|
||||||
${top_builddir}/components/replication/replication.la \
|
${top_builddir}/components/replication/replication.la
|
||||||
${top_builddir}/components/convenience/convenience.la
|
|
||||||
|
11
icinga2.sln
11
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}
|
{2E6C1133-730F-4875-A72C-B455B1DD4C5C} = {2E6C1133-730F-4875-A72C-B455B1DD4C5C}
|
||||||
{17C93245-8C20-4316-9573-1AE41D918C10} = {17C93245-8C20-4316-9573-1AE41D918C10}
|
{17C93245-8C20-4316-9573-1AE41D918C10} = {17C93245-8C20-4316-9573-1AE41D918C10}
|
||||||
{704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C} = {704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C}
|
{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}
|
{38CE81CC-2660-4EF0-A936-4A337591DA3E} = {38CE81CC-2660-4EF0-A936-4A337591DA3E}
|
||||||
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
|
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
@ -41,11 +40,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "compat", "components\compat
|
|||||||
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
|
{C1FC77E1-04A4-481B-A78B-2F7AF489C2F8} = {C1FC77E1-04A4-481B-A78B-2F7AF489C2F8}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
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}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "components", "components", "{4A1773FD-DDED-4952-8700-C898E890554A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "libraries", "libraries", "{BC82DE9C-42E2-4880-92DA-C2269D2F6416}"
|
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}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}.Release|Win32.ActiveCfg = Release|Win32
|
{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}.Release|Win32.ActiveCfg = Release|Win32
|
||||||
{2BD1C70C-43DB-4F44-B66B-67CF5C7044AA}.Release|Win32.Build.0 = 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.ActiveCfg = Debug|Win32
|
||||||
{9C92DA90-FD53-43A9-A244-90F2E8AF9677}.Debug|Win32.Build.0 = Debug|Win32
|
{9C92DA90-FD53-43A9-A244-90F2E8AF9677}.Debug|Win32.Build.0 = Debug|Win32
|
||||||
{9C92DA90-FD53-43A9-A244-90F2E8AF9677}.Release|Win32.ActiveCfg = Release|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}
|
{17C93245-8C20-4316-9573-1AE41D918C10} = {4A1773FD-DDED-4952-8700-C898E890554A}
|
||||||
{704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C} = {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}
|
{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}
|
{2E6C1133-730F-4875-A72C-B455B1DD4C5C} = {4A1773FD-DDED-4952-8700-C898E890554A}
|
||||||
{19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {3BE47C55-D74A-46E6-8F8B-470B3FD29FB7}
|
{19CBCE06-3F5C-479A-BD75-E2AB6215D345} = {3BE47C55-D74A-46E6-8F8B-470B3FD29FB7}
|
||||||
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {3BE47C55-D74A-46E6-8F8B-470B3FD29FB7}
|
{66BED474-C33F-48F9-90BA-BBCFEDC006B8} = {3BE47C55-D74A-46E6-8F8B-470B3FD29FB7}
|
||||||
|
@ -58,7 +58,7 @@ void StreamLogger::ProcessLogEntry(std::ostream& stream, const LogEntry& entry)
|
|||||||
time_t ts = entry.Timestamp;
|
time_t ts = entry.Timestamp;
|
||||||
tm tmnow = *localtime(&ts);
|
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 << "] "
|
stream << "[" << timestamp << "] "
|
||||||
<< Logger::SeverityToString(entry.Severity) << "/" << entry.Facility << ": "
|
<< Logger::SeverityToString(entry.Severity) << "/" << entry.Facility << ": "
|
||||||
|
@ -23,9 +23,18 @@ using namespace icinga;
|
|||||||
|
|
||||||
REGISTER_CLASS(Host);
|
REGISTER_CLASS(Host);
|
||||||
|
|
||||||
|
bool Host::m_InitializerDone = false;
|
||||||
|
|
||||||
Host::Host(const Dictionary::Ptr& properties)
|
Host::Host(const Dictionary::Ptr& properties)
|
||||||
: DynamicObject(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("alias", Attribute_Config);
|
||||||
RegisterAttribute("hostgroups", Attribute_Config);
|
RegisterAttribute("hostgroups", Attribute_Config);
|
||||||
}
|
}
|
||||||
@ -127,3 +136,134 @@ bool Host::IsUp(void)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename TDict>
|
||||||
|
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>();
|
||||||
|
|
||||||
|
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<ConfigItemBuilder>(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>()) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,12 @@ public:
|
|||||||
|
|
||||||
bool IsReachable(void);
|
bool IsReachable(void);
|
||||||
bool IsUp(void);
|
bool IsUp(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool m_InitializerDone;
|
||||||
|
|
||||||
|
void ObjectCommittedHandler(const ConfigItem::Ptr& item);
|
||||||
|
void ObjectRemovedHandler(const ConfigItem::Ptr& item);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -41,14 +41,6 @@ IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate)
|
|||||||
replicationComponentConfig->SetLocal(true);
|
replicationComponentConfig->SetLocal(true);
|
||||||
replicationComponentConfig->Compile()->Commit();
|
replicationComponentConfig->Compile()->Commit();
|
||||||
replicationComponentConfig.reset();
|
replicationComponentConfig.reset();
|
||||||
|
|
||||||
/* load convenience config component */
|
|
||||||
ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
|
||||||
convenienceComponentConfig->SetType("Component");
|
|
||||||
convenienceComponentConfig->SetName("convenience");
|
|
||||||
convenienceComponentConfig->SetLocal(true);
|
|
||||||
convenienceComponentConfig->Compile()->Commit();
|
|
||||||
convenienceComponentConfig.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user