mirror of https://github.com/Icinga/icinga2.git
Added checker component.
This commit is contained in:
parent
739d0c1c29
commit
8346c031fb
|
@ -0,0 +1,26 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
pkglib_LTLIBRARIES = \
|
||||
checker.la
|
||||
|
||||
checker_la_SOURCES = \
|
||||
checkercomponent.cpp \
|
||||
checkercomponent.h \
|
||||
i2-checker.h
|
||||
|
||||
checker_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga
|
||||
|
||||
checker_la_LDFLAGS = \
|
||||
$(BOOST_LDFLAGS) \
|
||||
-module \
|
||||
-no-undefined \
|
||||
@RELEASE_INFO@ \
|
||||
@VERSION_INFO@
|
||||
|
||||
checker_la_LIBADD = \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/icinga/libicinga.la
|
|
@ -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>{38CE81CC-2660-4EF0-A936-4A337591DA3E}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>checker</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>
|
||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)\base;$(SolutionDir)\jsonrpc;$(SolutionDir)\icinga;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;CHECKER_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;CHECKER_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>
|
||||
<ClInclude Include="checkercomponent.h" />
|
||||
<ClInclude Include="i2-checker.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="checkercomponent.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,131 @@
|
|||
/******************************************************************************
|
||||
* 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-checker.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
string CheckerComponent::GetName(void) const
|
||||
{
|
||||
return "configcomponent";
|
||||
}
|
||||
|
||||
void CheckerComponent::Start(void)
|
||||
{
|
||||
m_CheckerEndpoint = make_shared<VirtualEndpoint>();
|
||||
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
|
||||
bind_weak(&CheckerComponent::AssignServiceRequestHandler, shared_from_this()));
|
||||
m_CheckerEndpoint->RegisterTopicHandler("checker::RevokeService",
|
||||
bind_weak(&CheckerComponent::AssignServiceRequestHandler, shared_from_this()));
|
||||
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());
|
||||
m_CheckTimer->Start();
|
||||
|
||||
CheckTask::RegisterType("nagios", NagiosCheckTask::CreateTask);
|
||||
|
||||
ConfigObject::TMap::Range range = ConfigObject::GetObjects("service");
|
||||
|
||||
for (ConfigObject::TMap::Iterator it = range.first; it != range.second; it++) {
|
||||
Service svc(it->second);
|
||||
CheckTask::Ptr ct = CheckTask::CreateTask(svc);
|
||||
CheckResult cr = ct->Execute();
|
||||
}
|
||||
}
|
||||
|
||||
int CheckerComponent::TestResponseHandler(const NewResponseEventArgs& ea)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CheckerComponent::Stop(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int CheckerComponent::NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||
{
|
||||
if (ea.Target->GetType() == "service")
|
||||
m_Services.push(ea.Target);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CheckerComponent::CheckTimerHandler(const TimerEventArgs& ea)
|
||||
{
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
if (m_Services.size() == 0)
|
||||
return 0;
|
||||
|
||||
for (;;) {
|
||||
|
||||
Service service = m_Services.top();
|
||||
|
||||
if (service.GetNextCheck() > now)
|
||||
break;
|
||||
|
||||
CheckTask::Ptr ct = CheckTask::CreateTask(service);
|
||||
CheckResult cr = ct->Execute();
|
||||
|
||||
m_Services.pop();
|
||||
service.SetNextCheck(now + service.GetCheckInterval());
|
||||
m_Services.push(service);
|
||||
}
|
||||
|
||||
/* adjust next call time for the check timer */
|
||||
Service service = m_Services.top();
|
||||
static_pointer_cast<Timer>(ea.Source)->SetInterval(service.GetNextCheck() - now);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
|
||||
{
|
||||
string id;
|
||||
if (!nrea.Request.GetID(&id))
|
||||
return 0;
|
||||
|
||||
ResponseMessage rm;
|
||||
rm.SetID(id);
|
||||
|
||||
MessagePart result;
|
||||
rm.SetResult(result);
|
||||
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nrea)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_COMPONENT(checker, CheckerComponent);
|
|
@ -0,0 +1,61 @@
|
|||
/******************************************************************************
|
||||
* 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 CHECKERCOMPONENT_H
|
||||
#define CHECKERCOMPONENT_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
struct ServiceNextCheckLessComparer
|
||||
{
|
||||
public:
|
||||
bool operator()(const Service& a, const Service& b)
|
||||
{
|
||||
return a.GetNextCheck() < b.GetNextCheck();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @ingroup checker
|
||||
*/
|
||||
class CheckerComponent : public IcingaComponent
|
||||
{
|
||||
public:
|
||||
virtual string GetName(void) const;
|
||||
virtual void Start(void);
|
||||
virtual void Stop(void);
|
||||
|
||||
private:
|
||||
priority_queue<Service, vector<Service>, ServiceNextCheckLessComparer> m_Services;
|
||||
Timer::Ptr m_CheckTimer;
|
||||
VirtualEndpoint::Ptr m_CheckerEndpoint;
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CHECKERCOMPONENT_H */
|
|
@ -0,0 +1,36 @@
|
|||
/******************************************************************************
|
||||
* 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 I2CHECKER_H
|
||||
#define I2CHECKER_H
|
||||
|
||||
/**
|
||||
* @defgroup checker Checker component
|
||||
*
|
||||
* The Checker component executes service checks.
|
||||
*/
|
||||
|
||||
#include <i2-base.h>
|
||||
#include <i2-icinga.h>
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "checkercomponent.h"
|
||||
|
||||
#endif /* I2CHECKER_H */
|
Loading…
Reference in New Issue