SUBDIRS = \
checker \
compat \
- delegation \
demo \
ido_mysql \
livestatus \
- notification \
- replication
+ notification
******************************************************************************/
#include "checker/checkercomponent.h"
-#include "remoting/endpointmanager.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
+#include "base/utility.h"
#include "base/logger_fwd.h"
#include <boost/exception/diagnostic_information.hpp>
+#include <boost/foreach.hpp>
using namespace icinga;
REGISTER_TYPE(CheckerComponent);
-CheckerComponent::CheckerComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{ }
-
void CheckerComponent::Start(void)
{
- m_Endpoint = Endpoint::MakeEndpoint("checker", false);
+ DynamicObject::Start();
- /* dummy registration so the delegation module knows this is a checker
- TODO: figure out a better way for this */
- m_Endpoint->RegisterSubscription("checker");
+ DynamicObject::OnStarted.connect(bind(&CheckerComponent::ObjectStartedHandler, this, _1));
+ DynamicObject::OnStopped.connect(bind(&CheckerComponent::ObjectStoppedHandler, this, _1));
- Service::OnCheckerChanged.connect(bind(&CheckerComponent::CheckerChangedHandler, this, _1));
Service::OnNextCheckChanged.connect(bind(&CheckerComponent::NextCheckChangedHandler, this, _1));
m_Stopped = false;
m_ResultTimer->SetInterval(5);
m_ResultTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::ResultTimerHandler, this));
m_ResultTimer->Start();
+
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
+ if (service->IsActive())
+ ObjectStartedHandler(service);
+ }
}
void CheckerComponent::Stop(void)
{
- m_Endpoint->Unregister();
-
{
boost::mutex::scoped_lock lock(m_Mutex);
m_Stopped = true;
CheckTimeView::iterator it = idx.begin();
Service::Ptr service = *it;
- if (!service->IsRegistered()) {
+ if (!service->IsActive()) {
idx.erase(it);
continue;
}
Log(LogInformation, "checker", msgbuf.str());
}
-void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
+void CheckerComponent::ObjectStartedHandler(const DynamicObject::Ptr& object)
{
- boost::mutex::scoped_lock lock(m_Mutex);
+ if (object->GetType() != DynamicType::GetByName("Service"))
+ return;
- String checker = service->GetCurrentChecker();
+ Service::Ptr service = static_pointer_cast<Service>(object);
+
+ {
+ boost::mutex::scoped_lock lock(m_Mutex);
- if (checker == EndpointManager::GetInstance()->GetIdentity() || Endpoint::GetByName(checker) == m_Endpoint) {
if (m_PendingServices.find(service) != m_PendingServices.end())
return;
m_IdleServices.insert(service);
m_CV.notify_all();
- } else {
+ }
+}
+
+void CheckerComponent::ObjectStoppedHandler(const DynamicObject::Ptr& object)
+{
+ if (object->GetType() != DynamicType::GetByName("Service"))
+ return;
+
+ Service::Ptr service = static_pointer_cast<Service>(object);
+
+ {
+ boost::mutex::scoped_lock lock(m_Mutex);
+
m_IdleServices.erase(service);
m_PendingServices.erase(service);
m_CV.notify_all();
>
> ServiceSet;
- CheckerComponent(const Dictionary::Ptr& serializedUpdate);
-
virtual void Start(void);
virtual void Stop(void);
private:
- Endpoint::Ptr m_Endpoint;
-
boost::mutex m_Mutex;
boost::condition_variable m_CV;
bool m_Stopped;
void AdjustCheckTimer(void);
- void CheckerChangedHandler(const Service::Ptr& service);
+ void ObjectStartedHandler(const DynamicObject::Ptr& object);
+ void ObjectStoppedHandler(const DynamicObject::Ptr& object);
void NextCheckChangedHandler(const Service::Ptr& service);
void RescheduleCheckTimer(void);
REGISTER_TYPE(CheckResultReader);
-CheckResultReader::CheckResultReader(const Dictionary::Ptr& properties)
- : DynamicObject(properties)
-{
- RegisterAttribute("spool_dir", Attribute_Config, &m_SpoolDir);
-}
-
/**
* @threadsafety Always.
*/
m_ReadTimer->Start();
}
-/**
- * @threadsafety Always.
- */
-CheckResultReader::Ptr CheckResultReader::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("CheckResultReader", name);
-
- return dynamic_pointer_cast<CheckResultReader>(configObject);
-}
-
/**
* @threadsafety Always.
*/
if (line.empty() || line[0] == '#')
continue; /* Ignore comments and empty lines. */
- int pos = line.find_first_of('=');
+ size_t pos = line.find_first_of('=');
if (pos == std::string::npos)
continue; /* Ignore invalid lines. */
service->SetNextCheck(Utility::GetTime() + service->GetCheckInterval());
}
}
+
+void CheckResultReader::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config)
+ bag->Set("spool_dir", m_SpoolDir);
+}
+
+void CheckResultReader::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config)
+ m_SpoolDir = bag->Get("spool_dir");
+}
{
public:
DECLARE_PTR_TYPEDEFS(CheckResultReader);
-
- CheckResultReader(const Dictionary::Ptr& properties);
-
- static CheckResultReader::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(CheckResultReader);
String GetSpoolDir(void) const;
protected:
virtual void Start(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_SpoolDir;
+ String m_SpoolDir;
Timer::Ptr m_ReadTimer;
void ReadTimerHandler(void) const;
*/
void CompatComponent::Start(void)
{
+ DynamicObject::Start();
+
m_StatusTimer = boost::make_shared<Timer>();
m_StatusTimer->SetInterval(15);
m_StatusTimer->OnTimerExpired.connect(boost::bind(&CompatComponent::StatusTimerHandler, this));
*/
String CompatComponent::GetStatusPath(void) const
{
- Value statusPath = m_StatusPath;
- if (statusPath.IsEmpty())
+ if (m_StatusPath.IsEmpty())
return Application::GetLocalStateDir() + "/cache/icinga2/status.dat";
else
- return statusPath;
+ return m_StatusPath;
}
/**
*/
String CompatComponent::GetObjectsPath(void) const
{
- Value objectsPath = m_ObjectsPath;
- if (objectsPath.IsEmpty())
+ if (m_ObjectsPath.IsEmpty())
return Application::GetLocalStateDir() + "/cache/icinga2/objects.cache";
else
- return objectsPath;
+ return m_ObjectsPath;
}
/**
*/
String CompatComponent::GetCommandPath(void) const
{
- Value commandPath = m_CommandPath;
- if (commandPath.IsEmpty())
+ if (m_CommandPath.IsEmpty())
return Application::GetLocalStateDir() + "/run/icinga2/icinga2.cmd";
else
- return commandPath;
+ return m_CommandPath;
}
-CompatComponent::CompatComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("status_path", Attribute_Config, &m_StatusPath);
- RegisterAttribute("objects_path", Attribute_Config, &m_ObjectsPath);
- RegisterAttribute("command_path", Attribute_Config, &m_CommandPath);
-}
#ifndef _WIN32
void CompatComponent::CommandPipeThread(const String& commandPath)
<< "\t" << "timeperiod_name" << "\t" << tp->GetName() << "\n"
<< "\t" << "alias" << "\t" << tp->GetName() << "\n";
- Dictionary::Ptr ranges = tp->Get("ranges");
+ Dictionary::Ptr ranges = tp->GetRanges();
if (ranges) {
ObjectLock olock(ranges);
fp << "\t" << "check_command=" << attrs->Get("check_command") << "\n"
<< "\t" << "event_handler=" << attrs->Get("event_handler") << "\n"
<< "\t" << "check_period=" << attrs->Get("check_period") << "\n"
- << "\t" << "check_interval=" << attrs->Get("check_interval") << "\n"
- << "\t" << "retry_interval=" << attrs->Get("retry_interval") << "\n"
+ << "\t" << "check_interval=" << static_cast<double>(attrs->Get("check_interval")) << "\n"
+ << "\t" << "retry_interval=" << static_cast<double>(attrs->Get("retry_interval")) << "\n"
<< "\t" << "has_been_checked=" << attrs->Get("has_been_checked") << "\n"
<< "\t" << "should_be_scheduled=" << attrs->Get("should_be_scheduled") << "\n"
- << "\t" << "check_execution_time=" << attrs->Get("check_execution_time") << "\n"
- << "\t" << "check_latency=" << attrs->Get("check_latency") << "\n"
+ << "\t" << "check_execution_time=" << static_cast<double>(attrs->Get("check_execution_time")) << "\n"
+ << "\t" << "check_latency=" << static_cast<double>(attrs->Get("check_latency")) << "\n"
<< "\t" << "current_state=" << attrs->Get("current_state") << "\n"
<< "\t" << "state_type=" << attrs->Get("state_type") << "\n"
<< "\t" << "plugin_output=" << attrs->Get("plugin_output") << "\n"
<< "# This file is auto-generated. Do not modify this file." << "\n"
<< "\n";
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
- Host::Ptr host = static_pointer_cast<Host>(object);
-
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
std::ostringstream tempstatusfp;
tempstatusfp << std::fixed;
DumpHostStatus(tempstatusfp, host);
objectfp << tempobjectfp.str();
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
- HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
-
+ BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
objectfp << tempobjectfp.str();
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
std::ostringstream tempstatusfp;
tempstatusfp << std::fixed;
DumpServiceStatus(tempstatusfp, service);
objectfp << tempobjectfp.str();
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
- ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
-
+ BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjects<ServiceGroup>()) {
std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
objectfp << tempobjectfp.str();
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
- User::Ptr user = static_pointer_cast<User>(object);
-
+ BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
objectfp << tempobjectfp.str();
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
- UserGroup::Ptr ug = static_pointer_cast<UserGroup>(object);
-
+ BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjects<UserGroup>()) {
std::ostringstream tempobjectfp;
tempobjectfp << std::fixed;
objectfp << tempobjectfp.str();
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("CheckCommand")) {
- Command::Ptr command = static_pointer_cast<Command>(object);
-
+ BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<CheckCommand>()) {
DumpCommand(objectfp, command);
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("NotificationCommand")) {
- Command::Ptr command = static_pointer_cast<Command>(object);
-
+ BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<NotificationCommand>()) {
DumpCommand(objectfp, command);
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("EventCommand")) {
- Command::Ptr command = static_pointer_cast<Command>(object);
-
+ BOOST_FOREACH(const Command::Ptr& command, DynamicType::GetObjects<EventCommand>()) {
DumpCommand(objectfp, command);
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
- TimePeriod::Ptr tp = static_pointer_cast<TimePeriod>(object);
-
+ BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
DumpTimePeriod(objectfp, tp);
}
<< boost::errinfo_file_name(objectspathtmp));
}
}
+
+void CompatComponent::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("status_path", m_StatusPath);
+ bag->Set("objects_path", m_ObjectsPath);
+ bag->Set("command_path", m_CommandPath);
+ }
+}
+
+void CompatComponent::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_StatusPath = bag->Get("status_path");
+ m_ObjectsPath = bag->Get("objects_path");
+ m_CommandPath = bag->Get("command_path");
+ }
+}
public:
DECLARE_PTR_TYPEDEFS(CompatComponent);
- CompatComponent(const Dictionary::Ptr& serializedUpdate);
-
+protected:
virtual void Start(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_StatusPath;
- Attribute<String> m_ObjectsPath;
- Attribute<String> m_CommandPath;
+ String m_StatusPath;
+ String m_ObjectsPath;
+ String m_CommandPath;
#ifndef _WIN32
boost::thread m_CommandThread;
******************************************************************************/
#include "compat/compatlog.h"
-#include "icinga/checkresultmessage.h"
-#include "icinga/downtimemessage.h"
#include "icinga/service.h"
#include "icinga/checkcommand.h"
#include "icinga/notification.h"
-#include "icinga/notificationmessage.h"
#include "icinga/macroprocessor.h"
#include "config/configcompilercontext.h"
#include "base/dynamictype.h"
REGISTER_TYPE(CompatLog);
REGISTER_SCRIPTFUNCTION(ValidateRotationMethod, &CompatLog::ValidateRotationMethod);
-CompatLog::CompatLog(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate), m_LastRotation(0)
-{
- RegisterAttribute("log_dir", Attribute_Config, &m_LogDir);
- RegisterAttribute("rotation_method", Attribute_Config, &m_RotationMethod);
-}
-
-/**
- * @threadsafety Always.
- */
-void CompatLog::OnAttributeChanged(const String& name)
-{
- ASSERT(!OwnsLock());
-
- if (name == "rotation_method")
- ScheduleNextRotation();
-}
+CompatLog::CompatLog(void)
+ : m_LastRotation(0)
+{ }
/**
* @threadsafety Always.
*/
void CompatLog::Start(void)
{
- m_Endpoint = Endpoint::MakeEndpoint("compatlog_" + GetName(), false);
- m_Endpoint->RegisterTopicHandler("checker::CheckResult",
- boost::bind(&CompatLog::CheckResultRequestHandler, this, _3));
-
+ Service::OnNewCheckResult.connect(bind(&CompatLog::CheckResultHandler, this, _1, _2));
Service::OnDowntimeChanged.connect(bind(&CompatLog::DowntimeHandler, this, _1, _2));
Service::OnNotificationSentChanged.connect(bind(&CompatLog::NotificationSentHandler, this, _1, _2, _3, _4, _5, _6));
Service::OnFlappingChanged.connect(bind(&CompatLog::FlappingHandler, this, _1, _2));
ScheduleNextRotation();
}
-/**
- * @threadsafety Always.
- */
-CompatLog::Ptr CompatLog::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("CompatLog", name);
-
- return dynamic_pointer_cast<CompatLog>(configObject);
-}
-
/**
* @threadsafety Always.
*/
/**
* @threadsafety Always.
*/
-void CompatLog::CheckResultRequestHandler(const RequestMessage& request)
+void CompatLog::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr &cr)
{
- CheckResultMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
-
Host::Ptr host = service->GetHost();
if (!host)
return;
- Dictionary::Ptr cr = params.GetCheckResult();
- if (!cr)
- return;
-
Dictionary::Ptr vars_after = cr->Get("vars_after");
long state_after = vars_after->Get("state");
/**
* @threadsafety Always.
*/
-void CompatLog::NotificationSentHandler(const Service::Ptr& service, const String& username,
+void CompatLog::NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user,
NotificationType const& notification_type, Dictionary::Ptr const& cr,
const String& author, const String& comment_text)
{
std::ostringstream msgbuf;
msgbuf << "SERVICE NOTIFICATION: "
- << username << ";"
+ << user->GetName() << ";"
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< notification_type_str << " "
if (service == host->GetHostCheckService()) {
std::ostringstream msgbuf;
msgbuf << "HOST NOTIFICATION: "
- << username << ";"
+ << user->GetName() << ";"
<< host->GetName() << ";"
<< notification_type_str << " "
<< "(" << Service::StateToString(service->GetState()) << ");"
WriteLine("LOG ROTATION: " + GetRotationMethod());
WriteLine("LOG VERSION: 2.0");
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
- Host::Ptr host = static_pointer_cast<Host>(object);
-
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
Service::Ptr hc = host->GetHostCheckService();
if (!hc)
WriteLine(msgbuf.str());
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Host::Ptr host = service->GetHost();
if (!host)
if (!rotation_method.IsEmpty() && rotation_method != "HOURLY" && rotation_method != "DAILY" &&
rotation_method != "WEEKLY" && rotation_method != "MONTHLY" && rotation_method != "NONE") {
- ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
+ ConfigCompilerContext::GetInstance()->AddError(false, "Validation failed for " +
location + ": Rotation method '" + rotation_method + "' is invalid.");
}
}
+
+void CompatLog::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("log_dir", m_LogDir);
+ bag->Set("rotation_method", m_RotationMethod);
+ }
+}
+
+void CompatLog::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_LogDir = bag->Get("log_dir");
+ m_RotationMethod = bag->Get("rotation_method");
+ }
+}
{
public:
DECLARE_PTR_TYPEDEFS(CompatLog);
+ DECLARE_TYPENAME(CompatLog);
- CompatLog(const Dictionary::Ptr& serializedUpdate);
-
- static CompatLog::Ptr GetByName(const String& name);
+ CompatLog(void);
String GetLogDir(void) const;
String GetRotationMethod(void) const;
static void ValidateRotationMethod(const String& location, const Dictionary::Ptr& attrs);
protected:
- virtual void OnAttributeChanged(const String& name);
virtual void Start(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_LogDir;
- Attribute<String> m_RotationMethod;
+ String m_LogDir;
+ String m_RotationMethod;
double m_LastRotation;
void WriteLine(const String& line);
void Flush(void);
- Endpoint::Ptr m_Endpoint;
- void CheckResultRequestHandler(const RequestMessage& request);
+ void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr);
void DowntimeHandler(const Service::Ptr& service, DowntimeState downtime_state);
- void NotificationSentHandler(const Service::Ptr& service, const String& username, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
+ void NotificationSentHandler(const Service::Ptr& service, const User::Ptr& user, NotificationType const& notification_type, Dictionary::Ptr const& cr, const String& author, const String& comment_text);
void FlappingHandler(const Service::Ptr& service, FlappingState flapping_state);
Timer::Ptr m_RotationTimer;
+++ /dev/null
-delegation-type.cpp
+++ /dev/null
-## Process this file with automake to produce Makefile.in
-
-pkglib_LTLIBRARIES = \
- libdelegation.la
-
-EXTRA_DIST = \
- delegation-type.conf
-
-.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig.c
- $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
-
-libdelegation_la_SOURCES = \
- delegationcomponent.cpp \
- delegationcomponent.h \
- delegation-type.cpp
-
-libdelegation_la_CPPFLAGS = \
- $(LTDLINCL) \
- $(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib \
- -I${top_srcdir}/components
-
-libdelegation_la_LDFLAGS = \
- $(BOOST_LDFLAGS) \
- -module \
- -no-undefined \
- @RELEASE_INFO@ \
- @VERSION_INFO@
-
-libdelegation_la_LIBADD = \
- $(BOOST_SIGNALS_LIB) \
- $(BOOST_THREAD_LIB) \
- $(BOOST_SYSTEM_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
+++ /dev/null
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-
-type DelegationComponent {
-}
+++ /dev/null
-<?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="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</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)'=='Debug|x64'" 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>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" 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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
- <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>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
- <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;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <LinkIncremental>true</LinkIncremental>
- <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <LinkIncremental>false</LinkIncremental>
- <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MinimalRebuild>false</MinimalRebuild>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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)'=='Debug|x64'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MinimalRebuild>false</MinimalRebuild>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MinimalRebuild>false</MinimalRebuild>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>MaxSpeed</Optimization>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MinimalRebuild>false</MinimalRebuild>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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="delegation-type.cpp" />
- <ClCompile Include="delegationcomponent.cpp" />
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="delegationcomponent.h" />
- <ClInclude Include="i2-delegation.h" />
- </ItemGroup>
- <ItemGroup>
- <CustomBuild Include="delegation-type.conf">
- <FileType>Document</FileType>
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Preparing config fragment for embedding</Message>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Preparing config fragment for embedding</Message>
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Preparing config fragment for embedding</Message>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Preparing config fragment for embedding</Message>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp;%(Outputs)</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp;%(Outputs)</Outputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- </CustomBuild>
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project>
\ No newline at end of file
+++ /dev/null
-<?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>
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="delegationcomponent.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
- <ClCompile Include="delegation-type.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="delegationcomponent.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- <ClInclude Include="i2-delegation.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- <CustomBuild Include="delegation-type.conf">
- <Filter>Quelldateien</Filter>
- </CustomBuild>
- </ItemGroup>
-</Project>
\ No newline at end of file
+++ /dev/null
-/******************************************************************************
- * 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 "delegation/delegationcomponent.h"
-#include "remoting/endpointmanager.h"
-#include "base/objectlock.h"
-#include "base/logger_fwd.h"
-#include <algorithm>
-#include "base/dynamictype.h"
-#include <boost/foreach.hpp>
-#include <boost/tuple/tuple.hpp>
-
-using namespace icinga;
-
-REGISTER_TYPE(DelegationComponent);
-
-DelegationComponent::DelegationComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{ }
-
-void DelegationComponent::Start(void)
-{
- m_DelegationTimer = boost::make_shared<Timer>();
-
- m_DelegationTimer->SetInterval(30);
- m_DelegationTimer->OnTimerExpired.connect(boost::bind(&DelegationComponent::DelegationTimerHandler, this));
- m_DelegationTimer->Start();
- m_DelegationTimer->Reschedule(Utility::GetTime() + 10);
-}
-
-bool DelegationComponent::IsEndpointChecker(const Endpoint::Ptr& endpoint)
-{
- return (endpoint->HasSubscription("checker"));
-}
-
-std::set<Endpoint::Ptr> DelegationComponent::GetCheckerCandidates(const Service::Ptr& service) const
-{
- std::set<Endpoint::Ptr> candidates;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
- Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
- String myIdentity = EndpointManager::GetInstance()->GetIdentity();
-
- /* ignore local-only endpoints (unless this is a local-only instance) */
- if (endpoint->IsLocal() && !myIdentity.IsEmpty())
- continue;
-
- /* ignore disconnected endpoints */
- if (!endpoint->IsConnected() && endpoint->GetName() != myIdentity)
- continue;
-
- /* ignore endpoints that aren't running the checker component */
- if (!IsEndpointChecker(endpoint))
- continue;
-
- /* ignore endpoints that aren't allowed to check this service */
- if (!service->IsAllowedChecker(endpoint->GetName()))
- continue;
-
- candidates.insert(endpoint);
- }
-
- return candidates;
-}
-
-void DelegationComponent::DelegationTimerHandler(void)
-{
- std::map<Endpoint::Ptr, int> histogram;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
- Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-
- histogram[endpoint] = 0;
- }
-
- std::vector<Service::Ptr> services;
-
- /* build "checker -> service count" histogram */
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = dynamic_pointer_cast<Service>(object);
-
- if (!service)
- continue;
-
- services.push_back(service);
-
- String checker = service->GetCurrentChecker();
-
- if (checker.IsEmpty())
- continue;
-
- Endpoint::Ptr endpoint = Endpoint::GetByName(checker);
-
- if (!endpoint)
- continue;
-
- histogram[endpoint]++;
- }
-
- int delegated = 0;
-
- /* re-assign services */
- BOOST_FOREACH(const Service::Ptr& service, services) {
- String checker = service->GetCurrentChecker();
-
- Endpoint::Ptr oldEndpoint = Endpoint::GetByName(checker);
-
- std::set<Endpoint::Ptr> candidates = GetCheckerCandidates(service);
-
- int avg_services = 0, overflow_tolerance = 0;
- std::vector<Endpoint::Ptr>::iterator cit;
-
- if (!candidates.empty()) {
-#ifdef _DEBUG
- std::ostringstream msgbuf;
- msgbuf << "Service: " << service->GetName() << ", candidates: " << candidates.size();
- Log(LogDebug, "delegation", msgbuf.str());
-#endif /* _DEBUG */
-
- BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
- avg_services += histogram[candidate];
- }
-
- avg_services /= candidates.size();
- overflow_tolerance = candidates.size() * 2;
- }
-
- /* don't re-assign service if the checker is still valid
- * and doesn't have too many services */
-
- if (oldEndpoint && oldEndpoint->IsConnected() &&
- candidates.find(oldEndpoint) != candidates.end() &&
- histogram[oldEndpoint] <= avg_services + overflow_tolerance)
- continue;
-
- /* clear the service's current checker */
- if (!checker.IsEmpty()) {
- {
- ObjectLock olock(service);
- service->SetCurrentChecker("");
- }
-
- if (oldEndpoint)
- histogram[oldEndpoint]--;
- }
-
- /* find a new checker for the service */
- BOOST_FOREACH(const Endpoint::Ptr& candidate, candidates) {
- /* does this checker already have too many services */
- if (histogram[candidate] > avg_services)
- continue;
-
- {
- ObjectLock olock(service);
- service->SetCurrentChecker(candidate->GetName());
- }
-
- histogram[candidate]++;
-
- /* reschedule the service; this avoids "check floods"
- * when a lot of services are re-assigned that haven't
- * been checked recently. */
- service->UpdateNextCheck();
-
- delegated++;
-
- break;
- }
-
- if (candidates.empty()) {
- if (service->GetState() != StateUncheckable && service->GetEnableActiveChecks()) {
- Dictionary::Ptr cr = boost::make_shared<Dictionary>();
-
- double now = Utility::GetTime();
- cr->Set("schedule_start", now);
- cr->Set("schedule_end", now);
- cr->Set("execution_start", now);
- cr->Set("execution_end", now);
-
- cr->Set("state", StateUncheckable);
- cr->Set("output", "No checker is available for this service.");
-
- service->ProcessCheckResult(cr);
-
- Log(LogWarning, "delegation", "Can't delegate service: " + service->GetName());
- }
-
- continue;
- }
-
- ASSERT(!service->GetCurrentChecker().IsEmpty());
- }
-
- Endpoint::Ptr endpoint;
- int count;
- BOOST_FOREACH(boost::tie(endpoint, count), histogram) {
- std::ostringstream msgbuf;
- msgbuf << "histogram: " << endpoint->GetName() << " - " << count;
- Log(LogInformation, "delegation", msgbuf.str());
- }
-
- std::ostringstream msgbuf;
- msgbuf << "Updated delegations for " << delegated << " services";
- Log(LogInformation, "delegation", msgbuf.str());
-}
+++ /dev/null
-/******************************************************************************
- * 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
-
-#include "icinga/service.h"
-#include "remoting/endpoint.h"
-#include "base/dynamicobject.h"
-#include "base/timer.h"
-
-namespace icinga
-{
-
-/**
- * @ingroup delegation
- */
-class DelegationComponent : public DynamicObject
-{
-public:
- DECLARE_PTR_TYPEDEFS(DelegationComponent);
-
- DelegationComponent(const Dictionary::Ptr& serializedUpdate);
-
- virtual void Start(void);
-
-private:
- Timer::Ptr m_DelegationTimer;
-
- void DelegationTimerHandler(void);
-
- std::set<Endpoint::Ptr> GetCheckerCandidates(const Service::Ptr& service) const;
-
- static bool IsEndpointChecker(const Endpoint::Ptr& endpoint);
-};
-
-}
-
-#endif /* DELEGATIONCOMPONENT_H */
REGISTER_TYPE(DemoComponent);
-DemoComponent::DemoComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{ }
-
/**
* Starts the component.
*/
void DemoComponent::Start(void)
{
- m_Endpoint = Endpoint::MakeEndpoint("demo", false);
- m_Endpoint->RegisterTopicHandler("demo::HelloWorld",
- boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2,
- _3));
+ DynamicObject::Start();
m_DemoTimer = boost::make_shared<Timer>();
m_DemoTimer->SetInterval(5);
*/
void DemoComponent::Stop(void)
{
- m_Endpoint->Unregister();
+ /* Nothing to do here. */
}
/**
*/
void DemoComponent::DemoTimerHandler(void)
{
- Log(LogInformation, "demo", "Sending multicast 'hello world' message.");
-
- RequestMessage request;
- request.SetMethod("demo::HelloWorld");
-
- EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
-}
-
-/**
- * Processes demo::HelloWorld messages.
- */
-void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender,
- const RequestMessage&)
-{
- Log(LogInformation, "demo", "Got 'hello world' from identity=" +
- (sender ? sender->GetName() : "(anonymous)"));
+ Log(LogInformation, "demo", "Hello World!");
}
public:
DECLARE_PTR_TYPEDEFS(DemoComponent);
- DemoComponent(const Dictionary::Ptr& serializedUpdate);
-
virtual void Start(void);
virtual void Stop(void);
private:
Timer::Ptr m_DemoTimer;
- Endpoint::Ptr m_Endpoint;
void DemoTimerHandler(void);
- void HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
};
}
REGISTER_TYPE(IdoMysqlDbConnection);
-IdoMysqlDbConnection::IdoMysqlDbConnection(const Dictionary::Ptr& serializedUpdate)
- : DbConnection(serializedUpdate), m_Connected(false)
+void IdoMysqlDbConnection::Start(void)
{
- RegisterAttribute("host", Attribute_Config, &m_Host);
- RegisterAttribute("port", Attribute_Config, &m_Port);
- RegisterAttribute("user", Attribute_Config, &m_User);
- RegisterAttribute("password", Attribute_Config, &m_Password);
- RegisterAttribute("database", Attribute_Config, &m_Database);
+ DbConnection::Start();
- RegisterAttribute("instance_name", Attribute_Config, &m_InstanceName);
- RegisterAttribute("instance_description", Attribute_Config, &m_InstanceDescription);
+ m_Connected = false;
m_TxTimer = boost::make_shared<Timer>();
m_TxTimer->SetInterval(5);
return;
if (!first)
- qbuf << " AND ";
+ where << " AND ";
where << key << " = " << value;
SetInsertID(query.Object, GetLastInsertID());
}
}
+
+void IdoMysqlDbConnection::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DbConnection::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("host", m_Host);
+ bag->Set("port", m_Port);
+ bag->Set("user", m_User);
+ bag->Set("password", m_Password);
+ bag->Set("database", m_Database);
+ bag->Set("instance_name", m_InstanceName);
+ bag->Set("instance_description", m_InstanceDescription);
+ }
+}
+
+void IdoMysqlDbConnection::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DbConnection::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_Host = bag->Get("host");
+ m_Port = bag->Get("port");
+ m_User = bag->Get("user");
+ m_Password = bag->Get("password");
+ m_Database = bag->Get("database");
+ m_InstanceName = bag->Get("instance_name");
+ m_InstanceDescription = bag->Get("instance_description");
+ }
+}
class IdoMysqlDbConnection : public DbConnection
{
public:
- typedef shared_ptr<IdoMysqlDbConnection> Ptr;
- typedef weak_ptr<IdoMysqlDbConnection> WeakPtr;
-
- IdoMysqlDbConnection(const Dictionary::Ptr& serializedUpdate);
- virtual void Stop(void);
+ DECLARE_PTR_TYPEDEFS(IdoMysqlDbConnection);
//virtual void UpdateObject(const DbObject::Ptr& dbobj, DbUpdateType kind);
protected:
+ virtual void Start(void);
+ virtual void Stop(void);
+
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
virtual void ActivateObject(const DbObject::Ptr& dbobj);
virtual void DeactivateObject(const DbObject::Ptr& dbobj);
virtual void ExecuteQuery(const DbQuery& query);
private:
- Attribute<String> m_Host;
- Attribute<long> m_Port;
- Attribute<String> m_User;
- Attribute<String> m_Password;
- Attribute<String> m_Database;
- Attribute<String> m_InstanceName;
- Attribute<String> m_InstanceDescription;
+ String m_Host;
+ Value m_Port;
+ String m_User;
+ String m_Password;
+ String m_Database;
+ String m_InstanceName;
+ String m_InstanceDescription;
DbReference m_InstanceID;
void CommandsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("CheckCommand")) {
+ BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects<CheckCommand>()) {
addRowFn(object);
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("EventCommand")) {
+ BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects<EventCommand>()) {
addRowFn(object);
}
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("NotificationCommand")) {
+ BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects<NotificationCommand>()) {
addRowFn(object);
}
}
void CommentsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = static_pointer_cast<Service>(object);
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr comments = service->GetComments();
if (!comments)
static int l_Connections = 0;
static boost::mutex l_ComponentMutex;
-LivestatusComponent::LivestatusComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("socket_type", Attribute_Config, &m_SocketType);
- RegisterAttribute("socket_path", Attribute_Config, &m_SocketPath);
- RegisterAttribute("host", Attribute_Config, &m_Host);
- RegisterAttribute("port", Attribute_Config, &m_Port);
-}
-
/**
* Starts the component.
*/
void LivestatusComponent::Start(void)
{
+ DynamicObject::Start();
+
if (GetSocketType() == "tcp") {
TcpSocket::Ptr socket = boost::make_shared<TcpSocket>();
socket->Bind(GetHost(), GetPort(), AF_INET);
l_ClientsConnected--;
}
}
+
+void LivestatusComponent::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("socket_type", m_SocketType);
+ bag->Set("socket_path", m_SocketPath);
+ bag->Set("host", m_Host);
+ bag->Set("port", m_Port);
+ }
+}
+
+void LivestatusComponent::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_SocketType = bag->Get("socket_type");
+ m_SocketPath = bag->Get("socket_path");
+ m_Host = bag->Get("host");
+ m_Port = bag->Get("port");
+ }
+}
class LivestatusComponent : public DynamicObject
{
public:
- LivestatusComponent(const Dictionary::Ptr& serializedUpdate);
-
- virtual void Start(void);
-
String GetSocketType(void) const;
String GetSocketPath(void) const;
String GetHost(void) const;
static int GetClientsConnected(void);
static int GetConnections(void);
+protected:
+ virtual void Start(void);
+
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_SocketType;
- Attribute<String> m_SocketPath;
- Attribute<String> m_Host;
- Attribute<String> m_Port;
+ String m_SocketType;
+ String m_SocketPath;
+ String m_Host;
+ String m_Port;
void ServerThreadProc(const Socket::Ptr& server);
void ClientThreadProc(const Socket::Ptr& client);
void ContactGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
- addRowFn(object);
+ BOOST_FOREACH(const UserGroup::Ptr& ug, DynamicType::GetObjects<UserGroup>()) {
+ addRowFn(ug);
}
}
void ContactsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
- addRowFn(object);
+ BOOST_FOREACH(const User::Ptr& user, DynamicType::GetObjects<User>()) {
+ addRowFn(user);
}
}
void DowntimesTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = static_pointer_cast<Service>(object);
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
Dictionary::Ptr downtimes = service->GetDowntimes();
if (!downtimes)
void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
- addRowFn(object);
+ BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
+ addRowFn(hg);
}
}
void HostsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
- addRowFn(object);
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
+ addRowFn(host);
}
}
void ServiceGroupsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
- addRowFn(object);
+ BOOST_FOREACH(const ServiceGroup::Ptr& sg, DynamicType::GetObjects<ServiceGroup>()) {
+ addRowFn(sg);
}
}
void ServicesTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- addRowFn(object);
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
+ addRowFn(service);
}
}
#include "livestatus/component.h"
#include "icinga/icingaapplication.h"
#include "icinga/cib.h"
+#include "icinga/host.h"
+#include "icinga/service.h"
#include "base/dynamictype.h"
#include "base/utility.h"
#include <boost/smart_ptr/make_shared.hpp>
Value StatusTable::NumHostsAccessor(const Value& row)
{
- return static_cast<long>(DynamicType::GetObjects("Host").size());
+ return DynamicType::GetObjects<Host>().size();
}
Value StatusTable::NumServicesAccessor(const Value& row)
{
- return static_cast<long>(DynamicType::GetObjects("Service").size());
+ return DynamicType::GetObjects<Service>().size();
}
Value StatusTable::ProgramVersionAccessor(const Value& row)
void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
- addRowFn(object);
+ BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
+ addRowFn(tp);
}
}
REGISTER_TYPE(NotificationComponent);
-NotificationComponent::NotificationComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{ }
-
/**
* Starts the component.
*/
void NotificationComponent::Start(void)
{
- m_Endpoint = Endpoint::MakeEndpoint("notification", false);
- m_Endpoint->RegisterTopicHandler("icinga::SendNotifications",
- boost::bind(&NotificationComponent::SendNotificationsRequestHandler, this, _2,
- _3));
+ DynamicObject::Start();
+
+ Service::OnNotificationsRequested.connect(bind(&NotificationComponent::SendNotificationsHandler, this, _1,
+ _2, _3, _4, _5));
m_NotificationTimer = boost::make_shared<Timer>();
m_NotificationTimer->SetInterval(5);
m_NotificationTimer->Start();
}
-/**
- * Stops the component.
- */
-void NotificationComponent::Stop(void)
-{
- m_Endpoint->Unregister();
-}
-
/**
* Periodically sends notifications.
*
{
double now = Utility::GetTime();
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) {
- Notification::Ptr notification = dynamic_pointer_cast<Notification>(object);
-
+ BOOST_FOREACH(const Notification::Ptr& notification, DynamicType::GetObjects<Notification>()) {
if (notification->GetNotificationInterval() <= 0)
continue;
notification->SetNextNotification(Utility::GetTime() + notification->GetNotificationInterval());
}
- bool send_notification;
-
{
ObjectLock olock(service);
/**
* Processes icinga::SendNotifications messages.
*/
-void NotificationComponent::SendNotificationsRequestHandler(const Endpoint::Ptr& sender,
- const RequestMessage& request)
+void NotificationComponent::SendNotificationsHandler(const Service::Ptr& service, NotificationType type,
+ const Dictionary::Ptr& cr, const String& author, const String& text)
{
- MessagePart params;
- if (!request.GetParams(¶ms))
- return;
-
- String svc;
- if (!params.Get("service", &svc))
- return;
-
- int type;
- if (!params.Get("type", &type))
- return;
-
- Dictionary::Ptr cr;
- if (!params.Get("check_result", &cr))
- return;
-
- Service::Ptr service = Service::GetByName(svc);
-
- if (!service)
- return;
-
- String author;
- params.Get("author", &author);
- String text;
- params.Get("text", &text);
-
service->SendNotifications(static_cast<NotificationType>(type), cr, author, text);
}
#ifndef NOTIFICATIONCOMPONENT_H
#define NOTIFICATIONCOMPONENT_H
-#include "remoting/endpoint.h"
+#include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
public:
DECLARE_PTR_TYPEDEFS(NotificationComponent);
- NotificationComponent(const Dictionary::Ptr& serializedUpdate);
-
virtual void Start(void);
- virtual void Stop(void);
private:
Timer::Ptr m_NotificationTimer;
- Endpoint::Ptr m_Endpoint;
void NotificationTimerHandler(void);
- void SendNotificationsRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
+ void SendNotificationsHandler(const Service::Ptr& service, NotificationType type,
+ const Dictionary::Ptr& cr, const String& author, const String& text);
};
}
+++ /dev/null
-replication-type.cpp
+++ /dev/null
-## Process this file with automake to produce Makefile.in
-
-pkglib_LTLIBRARIES = \
- libreplication.la
-
-EXTRA_DIST = \
- replication-type.conf
-
-.conf.cpp: $(top_builddir)/tools/mkembedconfig/mkembedconfig.c
- $(top_builddir)/tools/mkembedconfig/mkembedconfig $< $@
-
-libreplication_la_SOURCES = \
- replicationcomponent.cpp \
- replicationcomponent.h \
- replication-type.cpp
-
-libreplication_la_CPPFLAGS = \
- $(LTDLINCL) \
- $(BOOST_CPPFLAGS) \
- -I${top_srcdir}/lib \
- -I${top_srcdir}/components
-
-libreplication_la_LDFLAGS = \
- $(BOOST_LDFLAGS) \
- -module \
- -no-undefined \
- @RELEASE_INFO@ \
- @VERSION_INFO@
-
-libreplication_la_LIBADD = \
- $(BOOST_SIGNALS_LIB) \
- $(BOOST_THREAD_LIB) \
- $(BOOST_SYSTEM_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
+++ /dev/null
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-
-type ReplicationComponent {
-}
+++ /dev/null
-<?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>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="replicationcomponent.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- <ClInclude Include="i2-replication.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="replicationcomponent.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
- </ItemGroup>
-</Project>
+++ /dev/null
-<?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="Debug|x64">
- <Configuration>Debug</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|x64">
- <Configuration>Release</Configuration>
- <Platform>x64</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectGuid>{704DDD8E-9E6D-4C22-80BD-6DE10F3A5E1C}</ProjectGuid>
- <Keyword>Win32Proj</Keyword>
- <RootNamespace>replication</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)'=='Debug|x64'" 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>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" 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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
- <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>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
- <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;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <LinkIncremental>true</LinkIncremental>
- <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <LinkIncremental>false</LinkIncremental>
- <IncludePath>$(SolutionDir)\lib;$(SolutionDir)\components;$(IncludePath)</IncludePath>
- <LibraryPath>$(SolutionDir)$(Platform)\$(Configuration)\;$(LibraryPath)</LibraryPath>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <MinimalRebuild>false</MinimalRebuild>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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)'=='Debug|x64'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <MinimalRebuild>false</MinimalRebuild>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>MaxSpeed</Optimization>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>NDEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <MultiProcessorCompilation>true</MultiProcessorCompilation>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </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>
- <ClInclude Include="replicationcomponent.h" />
- <ClInclude Include="i2-replication.h" />
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="replication-type.cpp" />
- <ClCompile Include="replicationcomponent.cpp" />
- </ItemGroup>
- <ItemGroup>
- <CustomBuild Include="replication-type.conf">
- <FileType>Document</FileType>
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Preparing config fragment for embedding</Message>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Preparing config fragment for embedding</Message>
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Preparing config fragment for embedding</Message>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(SolutionDir)$(Platform)\$(Configuration)\mkembedconfig.exe" "%(Identity)" "%(Filename).cpp"</Command>
- <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Preparing config fragment for embedding</Message>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(Filename).cpp;%(Outputs)</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">%(Filename).cpp;%(Outputs)</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(Filename).cpp;%(Outputs)</Outputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- <AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)\tools\mkembedconfig\mkembedconfig.c</AdditionalInputs>
- </CustomBuild>
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup>
- <ClInclude Include="i2-replication.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- <ClInclude Include="replicationcomponent.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- <Filter Include="Headerdateien">
- <UniqueIdentifier>{85c17050-f3b5-4dbe-9d86-2c4838ddd7e0}</UniqueIdentifier>
- </Filter>
- <Filter Include="Quelldateien">
- <UniqueIdentifier>{0caf70c2-14a5-4d97-a2d0-0afbe6028b49}</UniqueIdentifier>
- </Filter>
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="replicationcomponent.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
- <ClCompile Include="replication-type.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
- </ItemGroup>
- <ItemGroup>
- <CustomBuild Include="replication-type.conf">
- <Filter>Quelldateien</Filter>
- </CustomBuild>
- </ItemGroup>
-</Project>
\ No newline at end of file
+++ /dev/null
-/******************************************************************************
- * 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 "replication/replicationcomponent.h"
-#include "icinga/service.h"
-#include "icinga/checkresultmessage.h"
-#include "remoting/endpointmanager.h"
-#include "base/dynamictype.h"
-#include "base/objectlock.h"
-#include "base/logger_fwd.h"
-#include <boost/foreach.hpp>
-
-using namespace icinga;
-
-REGISTER_TYPE(ReplicationComponent);
-
-ReplicationComponent::ReplicationComponent(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{ }
-
-/**
- * Starts the component.
- */
-void ReplicationComponent::Start(void)
-{
- m_Endpoint = Endpoint::MakeEndpoint("replication", false);
-
- DynamicObject::OnRegistered.connect(boost::bind(&ReplicationComponent::LocalObjectRegisteredHandler, this, _1));
- DynamicObject::OnUnregistered.connect(boost::bind(&ReplicationComponent::LocalObjectUnregisteredHandler, this, _1));
- DynamicObject::OnTransactionClosing.connect(boost::bind(&ReplicationComponent::TransactionClosingHandler, this, _1, _2));
- DynamicObject::OnFlushObject.connect(boost::bind(&ReplicationComponent::FlushObjectHandler, this, _1, _2));
-
- Endpoint::OnConnected.connect(boost::bind(&ReplicationComponent::EndpointConnectedHandler, this, _1));
-
- m_Endpoint->RegisterTopicHandler("config::ObjectUpdate",
- boost::bind(&ReplicationComponent::RemoteObjectUpdateHandler, this, _3));
- m_Endpoint->RegisterTopicHandler("config::ObjectRemoved",
- boost::bind(&ReplicationComponent::RemoteObjectRemovedHandler, this, _3));
-
- /* service status */
- m_Endpoint->RegisterTopicHandler("checker::CheckResult",
- boost::bind(&ReplicationComponent::CheckResultRequestHandler, _3));
-}
-
-/**
- * Stops the component.
- */
-void ReplicationComponent::Stop(void)
-{
- m_Endpoint->Unregister();
-}
-
-void ReplicationComponent::CheckResultRequestHandler(const RequestMessage& request)
-{
- CheckResultMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
-
- Dictionary::Ptr cr = params.GetCheckResult();
- if (!cr)
- return;
-
- if (cr->Contains("current_checker") && cr->Get("current_checker") == EndpointManager::GetInstance()->GetIdentity())
- return;
-
- Service::UpdateStatistics(cr);
-}
-
-void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)
-{
- /* no need to sync the config with local endpoints */
- if (endpoint->IsLocalEndpoint())
- return;
-
- /* we just assume the other endpoint wants object updates */
- endpoint->RegisterSubscription("config::ObjectUpdate");
- endpoint->RegisterSubscription("config::ObjectRemoved");
-
- DynamicType::Ptr type;
- BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
- std::set<DynamicObject::Ptr> objects;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) {
- if (!ShouldReplicateObject(object))
- continue;
-
- RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", 0, true);
- EndpointManager::GetInstance()->SendUnicastMessage(m_Endpoint, endpoint, request);
-
- }
- }
-}
-
-RequestMessage ReplicationComponent::MakeObjectMessage(const DynamicObject::Ptr& object, const String& method, double sinceTx, bool includeProperties)
-{
- RequestMessage msg;
- msg.SetMethod(method);
-
- MessagePart params;
- msg.SetParams(params);
-
- params.Set("name", object->GetName());
- params.Set("type", object->GetType()->GetName());
-
- String source = object->GetSource();
-
- if (source.IsEmpty())
- source = EndpointManager::GetInstance()->GetIdentity();
-
- params.Set("source", source);
-
- if (includeProperties)
- params.Set("update", object->BuildUpdate(sinceTx, Attribute_Replicated | Attribute_Config));
-
- return msg;
-}
-
-bool ReplicationComponent::ShouldReplicateObject(const DynamicObject::Ptr& object)
-{
- return (!object->IsLocal());
-}
-
-void ReplicationComponent::LocalObjectRegisteredHandler(const DynamicObject::Ptr& object)
-{
- if (!ShouldReplicateObject(object))
- return;
-
- EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
- MakeObjectMessage(object, "config::ObjectUpdate", 0, true));
-}
-
-void ReplicationComponent::LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object)
-{
- if (!ShouldReplicateObject(object))
- return;
-
- EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
- MakeObjectMessage(object, "config::ObjectRemoved", 0, false));
-}
-
-void ReplicationComponent::TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects)
-{
- if (modifiedObjects.empty())
- return;
-
- std::ostringstream msgbuf;
- msgbuf << "Sending " << modifiedObjects.size() << " replication updates.";
- Log(LogInformation, "replication", msgbuf.str());
-
- BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, modifiedObjects) {
- DynamicObject::Ptr object = wobject.lock();
-
- if (!object)
- continue;
-
- FlushObjectHandler(tx, object);
- }
-}
-
-void ReplicationComponent::FlushObjectHandler(double tx, const DynamicObject::Ptr& object)
-{
- if (!ShouldReplicateObject(object))
- return;
-
- /* Don't replicate objects that haven't had any local updates. */
- if (object->GetLocalTx() < tx)
- return;
-
- RequestMessage request = MakeObjectMessage(object, "config::ObjectUpdate", tx, true);
- EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
-}
-
-void ReplicationComponent::RemoteObjectUpdateHandler(const RequestMessage& request)
-{
- MessagePart params;
- if (!request.GetParams(¶ms))
- return;
-
- String name;
- if (!params.Get("name", &name))
- return;
-
- String type;
- if (!params.Get("type", &type))
- return;
-
- String source;
- if (!params.Get("source", &source))
- return;
-
- Dictionary::Ptr update;
- if (!params.Get("update", &update))
- return;
-
- DynamicType::Ptr dtype = DynamicType::GetByName(type);
- DynamicObject::Ptr object = dtype->GetObject(name);
-
- // TODO: sanitize update, disallow __local
-
- if (!object) {
- object = dtype->CreateObject(update);
-
- if (source == EndpointManager::GetInstance()->GetIdentity()) {
- /* the peer sent us an object that was originally created by us -
- * however it was deleted locally so we have to tell the peer to destroy
- * its copy of the object. */
- EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
- MakeObjectMessage(object, "config::ObjectRemoved", 0, false));
-
- return;
- }
-
- Log(LogDebug, "replication", "Received object from source: " + source);
-
- object->SetSource(source);
- object->Register();
- } else {
- if (object->IsLocal())
- BOOST_THROW_EXCEPTION(std::invalid_argument("Replicated remote object is marked as local."));
-
- // TODO: disallow config updates depending on endpoint config
-
- object->ApplyUpdate(update, Attribute_All);
- }
-}
-
-void ReplicationComponent::RemoteObjectRemovedHandler(const RequestMessage& request)
-{
- MessagePart params;
- if (!request.GetParams(¶ms))
- return;
-
- String name;
- if (!params.Get("name", &name))
- return;
-
- String type;
- if (!params.Get("type", &type))
- return;
-
- DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
-
- if (!object)
- return;
-
- if (!object->IsLocal()) {
- object->Unregister();
- }
-}
+++ /dev/null
-/******************************************************************************
- * 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 REPLICATIONCOMPONENT_H
-#define REPLICATIONCOMPONENT_H
-
-#include "base/dynamicobject.h"
-#include "remoting/endpoint.h"
-
-namespace icinga
-{
-
-/**
- * @ingroup replication
- */
-class ReplicationComponent : public DynamicObject
-{
-public:
- DECLARE_PTR_TYPEDEFS(ReplicationComponent);
-
- ReplicationComponent(const Dictionary::Ptr& serializedUpdate);
-
- virtual void Start(void);
- virtual void Stop(void);
-
-private:
- Endpoint::Ptr m_Endpoint;
-
- static void CheckResultRequestHandler(const RequestMessage& request);
-
- void EndpointConnectedHandler(const Endpoint::Ptr& endpoint);
-
- void LocalObjectRegisteredHandler(const DynamicObject::Ptr& object);
- void LocalObjectUnregisteredHandler(const DynamicObject::Ptr& object);
- void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
- void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
-
- void RemoteObjectUpdateHandler(const RequestMessage& request);
- void RemoteObjectRemovedHandler(const RequestMessage& request);
-
- static RequestMessage MakeObjectMessage(const DynamicObject::Ptr& object,
- const String& method, double sinceTx, bool includeProperties);
-
- static bool ShouldReplicateObject(const DynamicObject::Ptr& object);
-};
-
-}
-
-#endif /* REPLICATIONCOMPONENT_H */
components/Makefile
components/checker/Makefile
components/compat/Makefile
-components/delegation/Makefile
components/demo/Makefile
components/ido_mysql/Makefile
components/livestatus/Makefile
components/notification/Makefile
-components/replication/Makefile
docs/Doxyfile
docs/Makefile
etc/Makefile
from icingadbg import register_icinga_printers
register_icinga_printers()
end
+
+python
+import sys
+sys.path.insert(0, '/home/gbeutner/gdb_printers/python')
+from libstdcxx.v6.printers import register_libstdcxx_printers
+register_libstdcxx_printers (None)
+end
echo "Done"
}
-# Reload Icinga 2
-reload() {
- printf "Reloading Icinga 2: "
- if [ ! -e $ICINGA2_PID_FILE ]; then
- echo "The PID file '$ICINGA2_PID_FILE' does not exist."
- exit 1
- fi
-
- pid=`cat $ICINGA2_PID_FILE`
-
- if ! kill -HUP $pid >/dev/null 2>&1; then
- echo "Failed - Icinga 2 is not running."
- else
- echo "Done"
- fi
-}
-
# Print status for Icinga 2
status() {
printf "Icinga 2 status: "
stop
start
;;
- reload)
- reload
- ;;
*)
- echo $"Usage: $0 {start|stop|restart|reload|status}"
+ echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
${top_builddir}/lib/config/libconfig.la \
-dlopen ${top_builddir}/lib/icinga/libicinga.la \
-dlopen ${top_builddir}/components/checker/libchecker.la \
- -dlopen ${top_builddir}/components/replication/libreplication.la \
-dlopen ${top_builddir}/components/compat/libcompat.la \
- -dlopen ${top_builddir}/components/delegation/libdelegation.la \
-dlopen ${top_builddir}/components/demo/libdemo.la \
-dlopen ${top_builddir}/components/livestatus/liblivestatus.la \
-dlopen ${top_builddir}/components/notification/libnotification.la
namespace po = boost::program_options;
static po::variables_map g_AppParams;
-static String g_ConfigUnit;
-
-#ifndef _WIN32
-static bool l_ReloadConfig = false;
-static Timer::Ptr l_ReloadConfigTimer;
-#endif /* _WIN32 */
static bool LoadConfigFiles(bool validateOnly)
{
- ConfigCompilerContext context;
-
- ConfigCompilerContext::SetContext(&context);
+ ConfigCompilerContext::GetInstance()->Reset();
BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<std::vector<String> >()) {
ConfigCompiler::CompileFile(configPath);
ConfigCompiler::CompileText(name, fragment);
}
- ConfigCompilerContext::SetContext(NULL);
-
bool hasError = false;
- BOOST_FOREACH(const ConfigCompilerError& error, context.GetErrors()) {
+ BOOST_FOREACH(const ConfigCompilerError& error, ConfigCompilerContext::GetInstance()->GetErrors()) {
if (!error.Warning) {
hasError = true;
break;
/* Don't link or validate if we have already encountered at least one error. */
if (!hasError) {
- context.LinkItems();
- context.ValidateItems();
+ ConfigItem::LinkItems();
+ ConfigItem::ValidateItems();
}
hasError = false;
- BOOST_FOREACH(const ConfigCompilerError& error, context.GetErrors()) {
+ BOOST_FOREACH(const ConfigCompilerError& error, ConfigCompilerContext::GetInstance()->GetErrors()) {
if (error.Warning) {
Log(LogWarning, "icinga-app", "Config warning: " + error.Message);
} else {
if (validateOnly)
return true;
- context.ActivateItems();
+ ConfigItem::ActivateItems();
- if (!g_ConfigUnit.IsEmpty()) {
- /* ActivateItems has taken care of replacing all previous items
- * with new versions - which are automatically in a different
- * compilation unit. This UnloadUnit() call takes care of
- * removing all left-over items from the previous config. */
- ConfigItem::UnloadUnit(g_ConfigUnit);
- }
-
- g_ConfigUnit = context.GetUnit();
+ ConfigItem::DiscardItems();
+ ConfigType::DiscardTypes();
return true;
}
-#ifndef _WIN32
-static void ReloadConfigTimerHandler(void)
-{
- if (l_ReloadConfig) {
- Log(LogInformation, "icinga-app", "Received SIGHUP. Reloading config files.");
- LoadConfigFiles(false);
-
- l_ReloadConfig = false;
- }
-}
-
-static void SigHupHandler(int signum)
-{
- ASSERT(signum == SIGHUP);
-
- l_ReloadConfig = true;
-}
-#endif /* _WIN32 */
-
static bool Daemonize(const String& stderrFile)
{
#ifndef _WIN32
if (!app)
BOOST_THROW_EXCEPTION(std::runtime_error("Configuration must create an Application object."));
-#ifndef _WIN32
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = &SigHupHandler;
- sigaction(SIGHUP, &sa, NULL);
-
- l_ReloadConfigTimer = boost::make_shared<Timer>();
- l_ReloadConfigTimer->SetInterval(1);
- l_ReloadConfigTimer->OnTimerExpired.connect(boost::bind(&ReloadConfigTimerHandler));
- l_ReloadConfigTimer->Start();
-#endif /* _WIN32 */
-
return app->Run();
}
icinga2itldir = ${pkgdatadir}/itl
icinga2itl_DATA = \
- cluster.conf \
command.conf \
command-common.conf \
constants.conf \
+++ /dev/null
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-
-library "replication"
-local object ReplicationComponent "replication" {}
******************************************************************************/
library "checker"
-local object CheckerComponent "checker" {}
-
-library "delegation"
-local object DelegationComponent "delegation" {}
+object CheckerComponent "checker" {}
library "notification"
-local object NotificationComponent "notification" {}
+object NotificationComponent "notification" {}
application.h \
array.cpp \
array.h \
- attribute.cpp \
- attribute.h \
bufferedstream.cpp \
bufferedstream.h \
consolelogger.cpp \
/**
* Constructor for the Application class.
*/
-Application::Application(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate), m_PidFile(NULL)
+void Application::Start(void)
{
- if (!IsLocal())
- BOOST_THROW_EXCEPTION(std::runtime_error("Application objects must be local."));
+ DynamicObject::Start();
+
+ m_PidFile = NULL;
#ifdef _WIN32
/* disable GUI-based error messages for LoadLibrary() */
/**
* Destructor for the application class.
*/
-Application::~Application(void)
+void Application::Stop(void)
{
- m_Instance = NULL;
-
m_ShuttingDown = true;
#ifdef _WIN32
ClosePidFile();
}
+Application::~Application(void)
+{
+ m_Instance = NULL;
+}
+
/**
* Retrieves a pointer to the application singleton object.
*
Log(LogInformation, "base", "Shutting down Icinga...");
Application::GetInstance()->OnShutdown();
- DynamicObject::DeactivateObjects();
+ DynamicObject::StopObjects();
GetTP().Stop();
m_ShuttingDown = false;
}
* Signal handler for SIGINT. Prepares the application for cleanly
* shutting down during the next execution of the event loop.
*
- * @param signum The signal number.
+ * @param - The signal number.
*/
-void Application::SigIntHandler(int signum)
+void Application::SigIntHandler(int)
{
- ASSERT(signum == SIGINT);
-
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
/**
* Signal handler for SIGABRT. Helps with debugging ASSERT()s.
*
- * @param signum The signal number.
+ * @param - The signal number.
*/
-void Application::SigAbrtHandler(int signum)
+void Application::SigAbrtHandler(int)
{
- ASSERT(signum == SIGABRT);
-
#ifndef _WIN32
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
public:
DECLARE_PTR_TYPEDEFS(Application);
- explicit Application(const Dictionary::Ptr& serializedUpdate);
~Application(void);
static Application::Ptr GetInstance(void);
static ThreadPool& GetTP(void);
protected:
+ virtual void Start(void);
+ virtual void Stop(void);
+
void RunEventLoop(void) const;
virtual void OnShutdown(void) = 0;
+++ /dev/null
-/******************************************************************************
- * 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 "base/attribute.h"
-#include "base/utility.h"
-
-using namespace icinga;
-
-static boost::mutex l_Mutex;
-
-AttributeBase::AttributeBase(void)
- : m_Value()
-{ }
-
-void AttributeBase::Set(const Value& value)
-{
- boost::mutex::scoped_lock lock(l_Mutex);
- InternalSet(value);
-}
-
-Value AttributeBase::Get(void) const
-{
- boost::mutex::scoped_lock lock(l_Mutex);
- return InternalGet();
-}
-
-AttributeBase::operator Value(void) const
-{
- boost::mutex::scoped_lock lock(l_Mutex);
- return InternalGet();
-}
-
-bool AttributeBase::IsEmpty(void) const
-{
- boost::mutex::scoped_lock lock(l_Mutex);
- return InternalGet().IsEmpty();
-}
-
-/**
- * Note: Caller must hold l_Mutex;
- */
-void AttributeBase::InternalSet(const Value& value)
-{
- m_Value = value;
-}
-
-/**
- * Note: Caller must hold l_Mutex.
- */
-const Value& AttributeBase::InternalGet(void) const
-{
- return m_Value;
-}
-
-AttributeHolder::AttributeHolder(AttributeType type, AttributeBase *boundAttribute)
- : m_Type(type), m_Tx(0)
-{
- if (boundAttribute) {
- m_Attribute = boundAttribute;
- m_OwnsAttribute = false;
- } else {
- m_Attribute = new Attribute<Value>();
- m_OwnsAttribute = true;
- }
-}
-
-AttributeHolder::AttributeHolder(const AttributeHolder& other)
-{
- m_Type = other.m_Type;
- m_Tx = other.m_Tx;
- m_OwnsAttribute = other.m_OwnsAttribute;
-
- if (other.m_OwnsAttribute) {
- m_Attribute = new Attribute<Value>();
- m_Attribute->Set(other.m_Attribute->Get());
- } else {
- m_Attribute = other.m_Attribute;
- }
-}
-
-AttributeHolder::~AttributeHolder(void)
-{
- if (m_OwnsAttribute)
- delete m_Attribute;
-}
-
-void AttributeHolder::Bind(AttributeBase *boundAttribute)
-{
- ASSERT(m_OwnsAttribute);
- boundAttribute->Set(m_Attribute->Get());
- if (m_OwnsAttribute)
- delete m_Attribute;
- m_Attribute = boundAttribute;
- m_OwnsAttribute = false;
-}
-
-void AttributeHolder::SetValue(double tx, const Value& value)
-{
- m_Tx = tx;
- m_Attribute->Set(value);
-}
-
-Value AttributeHolder::GetValue(void) const
-{
- return m_Attribute->Get();
-}
-
-void AttributeHolder::SetType(AttributeType type)
-{
- m_Type = type;
-}
-
-AttributeType AttributeHolder::GetType(void) const
-{
- return m_Type;
-}
-
-void AttributeHolder::SetTx(double tx)
-{
- m_Tx = tx;
-}
-
-double AttributeHolder::GetTx(void) const
-{
- return m_Tx;
-}
+++ /dev/null
-/******************************************************************************
- * 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 ATTRIBUTE_H
-#define ATTRIBUTE_H
-
-#include "base/value.h"
-
-namespace icinga
-{
-
-/**
- * The type of an attribute for a DynamicObject.
- *
- * @ingroup base
- */
-enum AttributeType
-{
- Attribute_Transient = 1,
-
- /* Unlike transient attributes local attributes are persisted
- * in the program state file. */
- Attribute_Local = 2,
-
- /* Replicated attributes are sent to other daemons for which
- * replication is enabled. */
- Attribute_Replicated = 4,
-
- /* Attributes read from the config file are implicitly marked
- * as config attributes. */
- Attribute_Config = 8,
-
- /* Combination of all attribute types */
- Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Replicated | Attribute_Config
-};
-
-class I2_BASE_API AttributeBase
-{
-public:
- AttributeBase(void);
-
- void Set(const Value& value);
- Value Get(void) const;
- operator Value(void) const;
- bool IsEmpty(void) const;
-
-protected:
- void InternalSet(const Value& value);
- const Value& InternalGet(void) const;
-
-private:
- Value m_Value;
-
- AttributeBase(const AttributeBase& other);
- AttributeBase& operator=(const AttributeBase& other);
-};
-
-template<typename T>
-class Attribute : public AttributeBase
-{
-public:
- void Set(const T& value)
- {
- AttributeBase::Set(value);
- }
-
- Attribute<T>& operator=(const T& rhs)
- {
- Set(rhs);
- return *this;
- }
-
- T Get(void) const
- {
- Value value = AttributeBase::Get();
-
- if (value.IsEmpty())
- return T();
-
- return static_cast<T>(value);
- }
-
- operator T(void) const
- {
- return Get();
- }
-};
-
-/**
- * An attribute for a DynamicObject.
- *
- * @ingroup base
- */
-class I2_BASE_API AttributeHolder
-{
-public:
- AttributeHolder(AttributeType type, AttributeBase *boundAttribute = NULL);
- AttributeHolder(const AttributeHolder& other);
- ~AttributeHolder(void);
-
- void Bind(AttributeBase *boundAttribute);
-
- void SetValue(double tx, const Value& value);
- Value GetValue(void) const;
-
- void SetType(AttributeType type);
- AttributeType GetType(void) const;
-
- void SetTx(double tx);
- double GetTx(void) const;
-
-private:
- AttributeType m_Type; /**< The type of the attribute. */
- double m_Tx; /**< The timestamp of the last value change. */
- bool m_OwnsAttribute; /**< Whether we own the Data pointer. */
- AttributeBase *m_Attribute; /**< The current value of the attribute. */
-};
-
-}
-
-#endif /* ATTRIBUTE_H */
<ItemGroup>
<ClCompile Include="application.cpp" />
<ClCompile Include="array.cpp" />
- <ClCompile Include="attribute.cpp" />
<ClCompile Include="bufferedstream.cpp" />
<ClCompile Include="consolelogger.cpp" />
<ClCompile Include="convert.cpp" />
<ItemGroup>
<ClInclude Include="application.h" />
<ClInclude Include="array.h" />
- <ClInclude Include="attribute.h" />
<ClInclude Include="bufferedstream.h" />
<ClInclude Include="consolelogger.h" />
<ClInclude Include="convert.h" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
<ClCompile Include="process-windows.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
- <ClCompile Include="attribute.cpp">
- <Filter>Quelldateien</Filter>
- </ClCompile>
<ClCompile Include="stacktrace.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClInclude Include="objectlock.h">
<Filter>Headerdateien</Filter>
</ClInclude>
- <ClInclude Include="attribute.h">
- <Filter>Headerdateien</Filter>
- </ClInclude>
<ClInclude Include="stacktrace.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<UniqueIdentifier>{7bbee99c-5763-4063-836c-ddbcc8966ae3}</UniqueIdentifier>
</Filter>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
/**
* Constructor for the ConsoleLogger class.
*/
-ConsoleLogger::ConsoleLogger(const Dictionary::Ptr& serializedUpdate)
- : StreamLogger(serializedUpdate)
+void ConsoleLogger::Start()
{
+ StreamLogger::Start();
+
BindStream(&std::cout, false);
}
public:
DECLARE_PTR_TYPEDEFS(ConsoleLogger);
- explicit ConsoleLogger(const Dictionary::Ptr& serializedUpdate);
+ virtual void Start(void);
};
}
#include "base/scriptfunction.h"
#include <fstream>
#include <boost/make_shared.hpp>
+#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_errno.hpp>
using namespace icinga;
-static double l_CurrentTx = 0;
-static std::set<DynamicObject::WeakPtr> l_ModifiedObjects;
-static boost::mutex l_TransactionMutex;
-static boost::once_flag l_TransactionOnce = BOOST_ONCE_INIT;
-static Timer::Ptr l_TransactionTimer;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStarted;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStopped;
+boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnStateChanged;
-boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnRegistered;
-boost::signals2::signal<void (const DynamicObject::Ptr&)> DynamicObject::OnUnregistered;
-boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> DynamicObject::OnTransactionClosing;
-boost::signals2::signal<void (double, const DynamicObject::Ptr&)> DynamicObject::OnFlushObject;
-boost::signals2::signal<void (const DynamicObject::Ptr&, const std::set<String, string_iless>&)> DynamicObject::OnAttributesChanged;
-
-DynamicObject::DynamicObject(const Dictionary::Ptr& serializedObject)
- : m_ConfigTx(0), m_LocalTx(0), m_Registered(false)
-{
- RegisterAttribute("__name", Attribute_Config, &m_Name);
- RegisterAttribute("__type", Attribute_Config, &m_Type);
- RegisterAttribute("__local", Attribute_Config, &m_Local);
- RegisterAttribute("__source", Attribute_Local, &m_Source);
- RegisterAttribute("__extensions", Attribute_Local, &m_Extensions);
- RegisterAttribute("methods", Attribute_Config, &m_Methods);
- RegisterAttribute("custom", Attribute_Config, &m_Custom);
-
- if (!serializedObject->Contains("configTx"))
- BOOST_THROW_EXCEPTION(std::invalid_argument("Serialized object must contain a config snapshot."));
-
- /* apply config state from the config item/remote update;
- * The DynamicType::CreateObject function takes care of restoring
- * non-config state after the object has been fully constructed */
- ApplyUpdate(serializedObject, Attribute_Config);
-
- boost::call_once(l_TransactionOnce, &DynamicObject::Initialize);
-}
+DynamicObject::DynamicObject(void)
+ : m_Active(false)
+{ }
DynamicObject::~DynamicObject(void)
{ }
-void DynamicObject::Initialize(void)
+Dictionary::Ptr DynamicObject::Serialize(int attributeTypes) const
{
- /* Set up a timer to periodically create a new transaction. */
- l_TransactionTimer = boost::make_shared<Timer>();
- l_TransactionTimer->SetInterval(0.5);
- l_TransactionTimer->OnTimerExpired.connect(boost::bind(&DynamicObject::NewTx));
- l_TransactionTimer->Start();
-}
-
-Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) const
-{
- ObjectLock olock(this);
-
- DynamicObject::AttributeConstIterator it;
-
- Dictionary::Ptr attrs = boost::make_shared<Dictionary>();
-
- {
- boost::mutex::scoped_lock lock(m_AttributeMutex);
-
- for (it = m_Attributes.begin(); it != m_Attributes.end(); ++it) {
- if (it->second.GetType() == Attribute_Transient)
- continue;
-
- if ((it->second.GetType() & attributeTypes) == 0)
- continue;
-
- if (it->second.GetTx() == 0)
- continue;
-
- if (it->second.GetTx() < sinceTx && !(it->second.GetType() == Attribute_Config && m_ConfigTx >= sinceTx))
- continue;
-
- Dictionary::Ptr attr = boost::make_shared<Dictionary>();
- attr->Set("data", it->second.GetValue());
- attr->Set("type", it->second.GetType());
- attr->Set("tx", it->second.GetTx());
-
- attrs->Set(it->first, attr);
- }
- }
-
Dictionary::Ptr update = boost::make_shared<Dictionary>();
- update->Set("attrs", attrs);
-
- if (m_ConfigTx >= sinceTx && attributeTypes & Attribute_Config)
- update->Set("configTx", m_ConfigTx);
- else if (attrs->GetLength() == 0)
- return Dictionary::Ptr();
-
- return update;
-}
-
-void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate,
- int allowedTypes)
-{
- ObjectLock olock(this);
-
- Value configTxValue = serializedUpdate->Get("configTx");
-
- boost::mutex::scoped_lock lock(m_AttributeMutex);
-
- if ((allowedTypes & Attribute_Config) != 0 && !configTxValue.IsEmpty()) {
- double configTx = configTxValue;
-
- if (configTx > m_ConfigTx) {
- DynamicObject::AttributeIterator at;
- for (at = m_Attributes.begin(); at != m_Attributes.end(); ++at) {
- if ((at->second.GetType() & Attribute_Config) == 0)
- continue;
-
- at->second.SetValue(0, Empty);
- }
- }
- }
-
- Dictionary::Ptr attrs = serializedUpdate->Get("attrs");
-
- {
- ObjectLock alock(attrs);
-
- Dictionary::Iterator it;
- for (it = attrs->Begin(); it != attrs->End(); ++it) {
- if (!it->second.IsObjectType<Dictionary>())
- continue;
-
- Dictionary::Ptr attr = it->second;
-
- int type = attr->Get("type");
-
- if ((type & ~allowedTypes) != 0)
- continue;
-
- Value data = attr->Get("data");
- double tx = attr->Get("tx");
- if (type & Attribute_Config)
- InternalRegisterAttribute(it->first, Attribute_Config);
-
- if (m_Attributes.find(it->first) == m_Attributes.end())
- InternalRegisterAttribute(it->first, static_cast<AttributeType>(type));
-
- InternalSetAttribute(it->first, data, tx, true);
- }
- }
-}
-
-void DynamicObject::RegisterAttribute(const String& name,
- AttributeType type, AttributeBase *boundAttribute)
-{
ASSERT(!OwnsLock());
ObjectLock olock(this);
- boost::mutex::scoped_lock lock(m_AttributeMutex);
-
- InternalRegisterAttribute(name, type, boundAttribute);
-}
-
-/**
- * Note: Caller must hold m_AttributeMutex.
- */
-void DynamicObject::InternalRegisterAttribute(const String& name,
- AttributeType type, AttributeBase *boundAttribute)
-{
- ASSERT(OwnsLock());
-
- AttributeHolder attr(type, boundAttribute);
-
- std::pair<DynamicObject::AttributeIterator, bool> tt;
- tt = m_Attributes.insert(std::make_pair(name, attr));
+ InternalSerialize(update, attributeTypes);
- if (!tt.second) {
- tt.first->second.SetType(type);
+ /* Make sure our own InternalSerialize() method was called. */
+ ASSERT(update->Contains("__marker"));
+ update->Remove("__marker");
- if (boundAttribute)
- tt.first->second.Bind(boundAttribute);
- }
+ return update;
}
-void DynamicObject::Set(const String& name, const Value& data)
+void DynamicObject::Deserialize(const Dictionary::Ptr& update, int attributeTypes)
{
ASSERT(!OwnsLock());
ObjectLock olock(this);
- boost::mutex::scoped_lock lock(m_AttributeMutex);
-
- InternalSetAttribute(name, data, GetCurrentTx());
+ InternalDeserialize(update, attributeTypes);
}
-void DynamicObject::Touch(const String& name)
+void DynamicObject::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
- ASSERT(OwnsLock());
-
- boost::mutex::scoped_lock lock(m_AttributeMutex);
-
- AttributeIterator it = m_Attributes.find(name);
-
- if (it == m_Attributes.end())
- BOOST_THROW_EXCEPTION(std::runtime_error("Touch() called for unknown attribute: " + name));
-
- double tx = GetCurrentTx();
- it->second.SetTx(tx);
- m_LocalTx = tx;
-
- m_ModifiedAttributes.insert(name);
-
- {
- boost::mutex::scoped_lock lock(l_TransactionMutex);
- l_ModifiedObjects.insert(GetSelf());
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("__name", m_Name);
+ bag->Set("__type", m_Type);
+ bag->Set("methods", m_Methods);
+ bag->Set("custom", m_Custom);
}
-}
-
-double DynamicObject::GetLocalTx(void) const
-{
- boost::mutex::scoped_lock lock(m_AttributeMutex);
- return m_LocalTx;
-}
-
-Value DynamicObject::Get(const String& name) const
-{
- ASSERT(!OwnsLock());
- ObjectLock olock(this);
- boost::mutex::scoped_lock lock(m_AttributeMutex);
+ bag->Set("extensions", m_Extensions);
- return InternalGetAttribute(name);
+ /* This attribute is used by Serialize() to check that this
+ * method was called. */
+ bag->Set("__marker", 1);
}
-/**
- * Note: Caller must hold m_AttributeMutex.
- */
-void DynamicObject::InternalSetAttribute(const String& name, const Value& data,
- double tx, bool allowEditConfig)
+void DynamicObject::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
- ASSERT(OwnsLock());
-
- DynamicObject::AttributeIterator it;
- it = m_Attributes.find(name);
-
- if (it == m_Attributes.end()) {
- AttributeHolder attr(Attribute_Transient);
- attr.SetValue(tx, data);
-
- m_Attributes.insert(std::make_pair(name, attr));
- } else {
- if (!allowEditConfig && (it->second.GetType() & Attribute_Config))
- BOOST_THROW_EXCEPTION(std::runtime_error("Config properties are immutable: '" + name + "'."));
-
- if (tx > it->second.GetTx()) {
- it->second.SetValue(tx, data);
-
- if (it->second.GetType() & Attribute_Config)
- m_ConfigTx = tx;
- }
- }
-
- if (IsRegistered()) {
- /* We can't call GetSelf() in the constructor or destructor.
- * The Register() function will take care of adding this
- * object to the list of modified objects later on if we can't
- * do it here. */
-
- {
- boost::mutex::scoped_lock lock(l_TransactionMutex);
- l_ModifiedObjects.insert(GetSelf());
- }
+ if (attributeTypes & Attribute_Config) {
+ m_Name = bag->Get("__name");
+ m_Type = bag->Get("__type");
+ m_Methods = bag->Get("methods");
+ m_Custom = bag->Get("custom");
}
- m_ModifiedAttributes.insert(name);
-}
-
-/**
- * Note: Caller must hold m_AttributeMutex.
- */
-Value DynamicObject::InternalGetAttribute(const String& name) const
-{
- ASSERT(OwnsLock());
-
- DynamicObject::AttributeConstIterator it;
- it = m_Attributes.find(name);
-
- if (it == m_Attributes.end())
- return Empty;
-
- return it->second.GetValue();
+ m_Extensions = bag->Get("extensions");
}
DynamicType::Ptr DynamicObject::GetType(void) const
return m_Name;
}
-bool DynamicObject::IsLocal(void) const
+bool DynamicObject::IsActive(void) const
{
- return m_Local;
-}
-
-bool DynamicObject::IsRegistered(void) const
-{
- ObjectLock olock(GetType());
- return m_Registered;
-}
-
-void DynamicObject::SetSource(const String& value)
-{
- m_Source = value;
- Touch("__source");
-}
-
-String DynamicObject::GetSource(void) const
-{
- return m_Source;
+ return m_Active;
}
void DynamicObject::SetExtension(const String& key, const Object::Ptr& object)
}
extensions->Set(key, object);
- Touch("__extensions");
}
Object::Ptr DynamicObject::GetExtension(const String& key)
return;
extensions->Remove(key);
- Touch("__extensions");
}
void DynamicObject::Register(void)
{
ASSERT(!OwnsLock());
- /* Add this new object to the list of modified objects.
- * We're doing this here because we can't construct
- * a while WeakPtr from within the object's constructor. */
- {
- boost::mutex::scoped_lock lock(l_TransactionMutex);
- l_ModifiedObjects.insert(GetSelf());
- }
-
DynamicType::Ptr dtype = GetType();
dtype->RegisterObject(GetSelf());
}
-void DynamicObject::OnRegistrationCompleted(void)
-{
- ASSERT(!OwnsLock());
-
- Start();
-
- OnRegistered(GetSelf());
-}
-
-void DynamicObject::OnUnregistrationCompleted(void)
-{
- ASSERT(!OwnsLock());
-
- Stop();
-
- OnUnregistered(GetSelf());
-}
-
void DynamicObject::Start(void)
{
ASSERT(!OwnsLock());
- /* Nothing to do here. */
-}
-
-void DynamicObject::Stop(void)
-{
- ASSERT(!OwnsLock());
+ ASSERT(!m_Active);
+ m_Active = true;
- /* Nothing to do here. */
+ OnStarted(GetSelf());
}
-void DynamicObject::Unregister(void)
+void DynamicObject::Stop(void)
{
ASSERT(!OwnsLock());
- DynamicType::Ptr dtype = GetType();
-
- if (!dtype)
- return;
+ ASSERT(m_Active);
+ m_Active = false;
- dtype->UnregisterObject(GetSelf());
+ OnStopped(GetSelf());
}
Value DynamicObject::InvokeMethod(const String& method,
return func->Invoke(arguments);
}
-void DynamicObject::DumpObjects(const String& filename)
+void DynamicObject::DumpObjects(const String& filename, int attributeTypes)
{
Log(LogInformation, "base", "Dumping program state to file '" + filename + "'");
BOOST_FOREACH(const DynamicType::Ptr& type, DynamicType::GetTypes()) {
BOOST_FOREACH(const DynamicObject::Ptr& object, type->GetObjects()) {
- if (object->IsLocal())
- continue;
-
Dictionary::Ptr persistentObject = boost::make_shared<Dictionary>();
persistentObject->Set("type", type->GetName());
persistentObject->Set("name", object->GetName());
- int types = Attribute_Local | Attribute_Replicated;
-
- /* only persist properties for replicated objects or for objects
- * that are marked as persistent */
- if (!object->GetSource().IsEmpty() /*|| object->IsPersistent()*/)
- types |= Attribute_Config;
-
- Dictionary::Ptr update = object->BuildUpdate(0, types);
+ Dictionary::Ptr update = object->Serialize(attributeTypes);
if (!update)
continue;
}
}
-void DynamicObject::RestoreObjects(const String& filename)
+void DynamicObject::RestoreObjects(const String& filename, int attributeTypes)
{
Log(LogInformation, "base", "Restoring program state from file '" + filename + "'");
String name = persistentObject->Get("name");
Dictionary::Ptr update = persistentObject->Get("update");
- bool hasConfig = update->Contains("configTx");
-
DynamicType::Ptr dt = DynamicType::GetByName(type);
if (!dt)
DynamicObject::Ptr object = dt->GetObject(name);
- if (hasConfig && !object) {
- object = dt->DynamicType::CreateObject(update);
- object->Register();
- } else if (object) {
- object->ApplyUpdate(update, Attribute_All);
- }
+ if (object)
+ object->Deserialize(update, attributeTypes);
restored++;
}
Log(LogInformation, "base", msgbuf.str());
}
-void DynamicObject::DeactivateObjects(void)
+void DynamicObject::StopObjects(void)
{
BOOST_FOREACH(const DynamicType::Ptr& dt, DynamicType::GetTypes()) {
BOOST_FOREACH(const DynamicObject::Ptr& object, dt->GetObjects()) {
- object->Unregister();
+ if (object->IsActive())
+ object->Stop();
}
}
}
-double DynamicObject::GetCurrentTx(void)
-{
- boost::mutex::scoped_lock lock(l_TransactionMutex);
-
- if (l_CurrentTx == 0) {
- /* Set the initial transaction ID. */
- l_CurrentTx = Utility::GetTime();
- }
-
- return l_CurrentTx;
-}
-
-void DynamicObject::Flush(void)
-{
- OnFlushObject(GetCurrentTx(), GetSelf());
-}
-
-void DynamicObject::NewTx(void)
-{
- double tx;
- std::set<DynamicObject::WeakPtr> objects;
-
- {
- boost::mutex::scoped_lock lock(l_TransactionMutex);
-
- tx = l_CurrentTx;
- l_ModifiedObjects.swap(objects);
- l_CurrentTx = Utility::GetTime();
- }
-
- BOOST_FOREACH(const DynamicObject::WeakPtr& wobject, objects) {
- DynamicObject::Ptr object = wobject.lock();
-
- if (!object || !object->IsRegistered())
- continue;
-
- std::set<String, string_iless> attrs;
-
- {
- ObjectLock olock(object);
- attrs.swap(object->m_ModifiedAttributes);
- }
-
- OnAttributesChanged(object, attrs);
-
- BOOST_FOREACH(const String& attr, attrs) {
- object->OnAttributeChanged(attr);
- }
- }
-
- OnTransactionClosing(tx, objects);
-}
-
-void DynamicObject::OnAttributeChanged(const String&)
-{
- ASSERT(!OwnsLock());
-}
-
DynamicObject::Ptr DynamicObject::GetObject(const String& type, const String& name)
{
DynamicType::Ptr dtype = DynamicType::GetByName(type);
return dtype->GetObject(name);
}
-const DynamicObject::AttributeMap& DynamicObject::GetAttributes(void) const
-{
- ASSERT(OwnsLock());
-
- return m_Attributes;
-}
-
Dictionary::Ptr DynamicObject::GetCustom(void) const
{
return m_Custom;
#define DYNAMICOBJECT_H
#include "base/i2-base.h"
-#include "base/attribute.h"
#include "base/object.h"
#include "base/dictionary.h"
#include <boost/signals2.hpp>
class DynamicType;
+/**
+ * The type of an attribute for a DynamicObject.
+ *
+ * @ingroup base
+ */
+enum AttributeType
+{
+ Attribute_Transient = 1,
+
+ /* Unlike transient attributes local attributes are persisted
+ * in the program state file. */
+ Attribute_Local = 2,
+
+ /* Attributes read from the config file are implicitly marked
+ * as config attributes. */
+ Attribute_Config = 4,
+
+ /* Combination of all attribute types */
+ Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Config
+};
+
/**
* A dynamic object that can be instantiated from the configuration file
* and that supports attribute replication to remote application instances.
public:
DECLARE_PTR_TYPEDEFS(DynamicObject);
- typedef std::map<String, AttributeHolder, string_iless> AttributeMap;
- typedef AttributeMap::iterator AttributeIterator;
- typedef AttributeMap::const_iterator AttributeConstIterator;
-
~DynamicObject(void);
- static void Initialize(void);
-
- Dictionary::Ptr BuildUpdate(double sinceTx, int attributeTypes) const;
- void ApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes);
-
- void RegisterAttribute(const String& name, AttributeType type, AttributeBase *boundAttribute = NULL);
-
- void Set(const String& name, const Value& data);
- void Touch(const String& name);
- Value Get(const String& name) const;
-
- void BindAttribute(const String& name, Value *boundValue);
+ Dictionary::Ptr Serialize(int attributeTypes) const;
+ void Deserialize(const Dictionary::Ptr& update, int attributeTypes);
- void ClearAttributesByType(AttributeType type);
-
- static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnRegistered;
- static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
- static boost::signals2::signal<void (double, const std::set<DynamicObject::WeakPtr>&)> OnTransactionClosing;
- static boost::signals2::signal<void (double, const DynamicObject::Ptr&)> OnFlushObject;
- static boost::signals2::signal<void (const DynamicObject::Ptr&, const std::set<String, string_iless>&)> OnAttributesChanged;
+ static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStarted;
+ static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStopped;
+ static boost::signals2::signal<void (const DynamicObject::Ptr&)> OnStateChanged;
Value InvokeMethod(const String& method, const std::vector<Value>& arguments);
shared_ptr<DynamicType> GetType(void) const;
String GetName(void) const;
- bool IsLocal(void) const;
- bool IsRegistered(void) const;
-
- void SetSource(const String& value);
- String GetSource(void) const;
+ bool IsActive(void) const;
void SetExtension(const String& key, const Object::Ptr& object);
Object::Ptr GetExtension(const String& key);
void ClearExtension(const String& key);
- void Flush(void);
-
void Register(void);
- void Unregister(void);
+
+ void Activate(void);
+ void Deactivate(void);
virtual void Start(void);
virtual void Stop(void);
- double GetLocalTx(void) const;
-
- const AttributeMap& GetAttributes(void) const;
-
- static DynamicObject::Ptr GetObject(const String& type, const String& name);
+ template<typename T>
+ static shared_ptr<T> GetObject(const String& name)
+ {
+ DynamicObject::Ptr object = GetObject(T::GetTypeName(), name);
- static void DumpObjects(const String& filename);
- static void RestoreObjects(const String& filename);
- static void DeactivateObjects(void);
+ return dynamic_pointer_cast<T>(object);
+ }
- static double GetCurrentTx(void);
+ static void DumpObjects(const String& filename, int attributeTypes = Attribute_Local);
+ static void RestoreObjects(const String& filename, int attributeTypes = Attribute_Local);
+ static void StopObjects(void);
Dictionary::Ptr GetCustom(void) const;
protected:
- explicit DynamicObject(const Dictionary::Ptr& serializedObject);
+ explicit DynamicObject(void);
- virtual void OnRegistrationCompleted(void);
- virtual void OnUnregistrationCompleted(void);
-
- virtual void OnAttributeChanged(const String& name);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- void InternalSetAttribute(const String& name, const Value& data, double tx, bool allowEditConfig = false);
- Value InternalGetAttribute(const String& name) const;
- void InternalRegisterAttribute(const String& name, AttributeType type, AttributeBase *boundAttribute = NULL);
-
- mutable boost::mutex m_AttributeMutex;
- AttributeMap m_Attributes;
- std::set<String, string_iless> m_ModifiedAttributes;
- double m_ConfigTx;
- double m_LocalTx;
-
- Attribute<String> m_Name;
- Attribute<String> m_Type;
- Attribute<bool> m_Local;
- Attribute<String> m_Source;
- Attribute<Dictionary::Ptr> m_Extensions;
- Attribute<Dictionary::Ptr> m_Methods;
- Attribute<Dictionary::Ptr> m_Custom;
-
- bool m_Registered; /**< protected by the type mutex */
+ String m_Name;
+ String m_Type;
+ Dictionary::Ptr m_Extensions;
+ Dictionary::Ptr m_Methods;
+ Dictionary::Ptr m_Custom;
- static double m_CurrentTx;
+ bool m_Active;
- static void NewTx(void);
-
- friend class DynamicType; /* for OnRegistrationCompleted. */
+ static DynamicObject::Ptr GetObject(const String& type, const String& name);
};
+#define DECLARE_TYPENAME(klass) \
+ inline static String GetTypeName(void) \
+ { \
+ return #klass; \
+ } \
+ \
+ inline static shared_ptr<klass> GetByName(const String& name) \
+ { \
+ return DynamicObject::GetObject<klass>(name); \
+ }
+
}
#endif /* DYNAMICOBJECT_H */
return typemap;
}
-DynamicType::TypeSet& DynamicType::InternalGetTypeSet(void)
+DynamicType::TypeVector& DynamicType::InternalGetTypeVector(void)
{
- static DynamicType::TypeSet typeset;
- return typeset;
+ static DynamicType::TypeVector typevector;
+ return typevector;
}
-DynamicType::TypeSet DynamicType::GetTypes(void)
+DynamicType::TypeVector DynamicType::GetTypes(void)
{
boost::mutex::scoped_lock lock(GetStaticMutex());
- return InternalGetTypeSet(); /* Making a copy of the set here. */
+ return InternalGetTypeVector(); /* Making a copy of the vector here. */
}
-std::set<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
+std::vector<DynamicObject::Ptr> DynamicType::GetObjects(const String& type)
{
DynamicType::Ptr dt = GetByName(type);
return dt->GetObjects();
}
-std::set<DynamicObject::Ptr> DynamicType::GetObjects(void) const
+std::vector<DynamicObject::Ptr> DynamicType::GetObjects(void) const
{
ObjectLock olock(this);
- return m_ObjectSet; /* Making a copy of the set here. */
+ return m_ObjectVector; /* Making a copy of the vector here. */
}
String DynamicType::GetName(void) const
}
m_ObjectMap[name] = object;
- m_ObjectSet.insert(object);
-
- object->m_Registered = true;
+ m_ObjectVector.push_back(object);
}
-
- object->OnRegistrationCompleted();
-}
-
-void DynamicType::UnregisterObject(const DynamicObject::Ptr& object)
-{
- {
- ObjectLock olock(this);
-
- m_ObjectMap.erase(object->GetName());
- m_ObjectSet.erase(object);
-
- object->m_Registered = false;
- }
-
- object->OnUnregistrationCompleted();
}
DynamicObject::Ptr DynamicType::GetObject(const String& name) const
type->GetName() + "': Objects of this type already exist."));
InternalGetTypeMap()[type->GetName()] = type;
- InternalGetTypeSet().insert(type);
+ InternalGetTypeVector().push_back(type);
}
DynamicObject::Ptr DynamicType::CreateObject(const Dictionary::Ptr& serializedUpdate)
factory = m_ObjectFactory;
}
- DynamicObject::Ptr object = factory(serializedUpdate);
+ DynamicObject::Ptr object = factory();
- /* apply the object's non-config attributes */
- object->ApplyUpdate(serializedUpdate, Attribute_All & ~Attribute_Config);
+ object->Deserialize(serializedUpdate, Attribute_All);
return object;
}
#include "base/i2-base.h"
#include "base/registry.h"
#include "base/dynamicobject.h"
+#include "base/utility.h"
#include <map>
#include <set>
#include <boost/function.hpp>
public:
DECLARE_PTR_TYPEDEFS(DynamicType);
- typedef boost::function<DynamicObject::Ptr (const Dictionary::Ptr&)> ObjectFactory;
+ typedef boost::function<DynamicObject::Ptr (void)> ObjectFactory;
DynamicType(const String& name, const ObjectFactory& factory);
DynamicObject::Ptr GetObject(const String& name) const;
void RegisterObject(const DynamicObject::Ptr& object);
- void UnregisterObject(const DynamicObject::Ptr& object);
- static std::set<DynamicType::Ptr> GetTypes(void);
- std::set<DynamicObject::Ptr> GetObjects(void) const;
+ static std::vector<DynamicType::Ptr> GetTypes(void);
+ std::vector<DynamicObject::Ptr> GetObjects(void) const;
- static std::set<DynamicObject::Ptr> GetObjects(const String& type);
+ template<typename T>
+ static std::vector<shared_ptr<T> > GetObjects(void)
+ {
+ std::vector<shared_ptr<T> > objects;
+
+ BOOST_FOREACH(const DynamicObject::Ptr& object, GetObjects(T::GetTypeName())) {
+ shared_ptr<T> tobject = dynamic_pointer_cast<T>(object);
+
+ ASSERT(tobject);
+
+ objects.push_back(tobject);
+ }
+
+ return objects;
+ }
private:
String m_Name;
ObjectFactory m_ObjectFactory;
typedef std::map<String, DynamicObject::Ptr, string_iless> ObjectMap;
- typedef std::set<DynamicObject::Ptr> ObjectSet;
+ typedef std::vector<DynamicObject::Ptr> ObjectVector;
ObjectMap m_ObjectMap;
- ObjectSet m_ObjectSet;
+ ObjectVector m_ObjectVector;
typedef std::map<String, DynamicType::Ptr, string_iless> TypeMap;
- typedef std::set<DynamicType::Ptr> TypeSet;
+ typedef std::vector<DynamicType::Ptr> TypeVector;
static TypeMap& InternalGetTypeMap(void);
- static TypeSet& InternalGetTypeSet(void);
+ static TypeVector& InternalGetTypeVector(void);
static boost::mutex& GetStaticMutex(void);
+
+ static std::vector<DynamicObject::Ptr> GetObjects(const String& type);
};
/**
* @ingroup base
*/
template<typename T>
-shared_ptr<T> DynamicObjectFactory(const Dictionary::Ptr& serializedUpdate)
+shared_ptr<T> DynamicObjectFactory(void)
{
- return boost::make_shared<T>(serializedUpdate);
+ return boost::make_shared<T>();
}
#define REGISTER_TYPE_ALIAS(type, alias) \
/**
* Constructor for the FileLogger class.
*/
-FileLogger::FileLogger(const Dictionary::Ptr& serializedUpdate)
- : StreamLogger(serializedUpdate)
+void FileLogger::Start()
{
- RegisterAttribute("path", Attribute_Config, &m_Path);
+ StreamLogger::Start();
std::ofstream *stream = new std::ofstream();
}
BindStream(stream, true);
-}
\ No newline at end of file
+}
+
+void FileLogger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ StreamLogger::InternalSerialize(bag, attributeTypes);
+
+ bag->Set("path", m_Path);
+}
+
+void FileLogger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ StreamLogger::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config)
+ m_Path = bag->Get("path");
+}
public:
DECLARE_PTR_TYPEDEFS(FileLogger);
- explicit FileLogger(const Dictionary::Ptr& serializedUpdate);
+ virtual void Start(void);
+
+protected:
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_Path;
+ String m_Path;
};
}
/**
* Constructor for the Logger class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
*/
-Logger::Logger(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("severity", Attribute_Config, &m_Severity);
-
- if (!IsLocal())
- BOOST_THROW_EXCEPTION(std::runtime_error("Logger objects must be local."));
-}
-
void Logger::Start(void)
{
+ DynamicObject::Start();
+
boost::mutex::scoped_lock(m_Mutex);
m_Loggers.insert(GetSelf());
}
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
}
-///**
-// * Retrieves the configuration object that belongs to this logger.
-// *
-// * @returns The configuration object.
-// */
-//DynamicObject::Ptr ILogger::GetConfig(void) const
-//{
-// return m_Config.lock();
-//}
+void Logger::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ bag->Set("severity", m_Severity);
+}
+
+void Logger::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config)
+ m_Severity = bag->Get("severity");
+}
public:
DECLARE_PTR_TYPEDEFS(Logger);
- explicit Logger(const Dictionary::Ptr& serializedUpdate);
-
static String SeverityToString(LogSeverity severity);
static LogSeverity StringToSeverity(const String& severity);
virtual void Start(void);
virtual void Stop(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_Severity;
+ String m_Severity;
LogSeverity m_MinSeverity;
#include <map>
#include <boost/thread/mutex.hpp>
#include <boost/signals2.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
namespace icinga
{
OnUnregistered(name);
}
+ void Clear(void)
+ {
+ typename Registry<T>::ItemMap items;
+
+ {
+ boost::mutex::scoped_lock lock(m_Mutex);
+ items = m_Items;
+ }
+
+ String name;
+ BOOST_FOREACH(boost::tie(name, boost::tuples::ignore), items) {
+ OnUnregistered(name);
+ }
+
+ {
+ boost::mutex::scoped_lock lock(m_Mutex);
+ m_Items.clear();
+ }
+ }
+
T GetItem(const String& name) const
{
boost::mutex::scoped_lock lock(m_Mutex);
REGISTER_TYPE(Script);
-/**
- * Constructor for the Script class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-Script::Script(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("language", Attribute_Config, &m_Language);
- RegisterAttribute("code", Attribute_Config, &m_Code);
-}
-
void Script::Start(void)
{
+ DynamicObject::Start();
+
ASSERT(OwnsLock());
SpawnInterpreter();
return m_Code;
}
-void Script::OnAttributeUpdate(const String& name)
-{
- ASSERT(!OwnsLock());
-
- if (name == "language" || name == "code")
- SpawnInterpreter();
-}
-
void Script::SpawnInterpreter(void)
{
Log(LogInformation, "base", "Reloading script '" + GetName() + "'");
ScriptLanguage::Ptr language = ScriptLanguage::GetByName(GetLanguage());
m_Interpreter = language->CreateInterpreter(GetSelf());
}
+
+void Script::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ bag->Set("language", m_Language);
+ bag->Set("code", m_Code);
+}
+
+void Script::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ m_Language = bag->Get("language");
+ m_Code = bag->Get("code");
+
+}
\ No newline at end of file
public:
DECLARE_PTR_TYPEDEFS(Script);
- Script(const Dictionary::Ptr& serializedUpdate);
-
virtual void Start(void);
String GetLanguage(void) const;
String GetCode(void) const;
protected:
- virtual void OnAttributeUpdate(const String& name);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_Language;
- Attribute<String> m_Code;
+ String m_Language;
+ String m_Code;
shared_ptr<ScriptInterpreter> m_Interpreter;
boost::function<Value (const std::vector<Value>& arguments)> I2_BASE_API WrapScriptFunction(void (*function)(void));
template<typename TR>
-Value ScriptFunctionWrapperR(TR (*function)(void), const std::vector<Value>& arguments)
+Value ScriptFunctionWrapperR(TR (*function)(void), const std::vector<Value>&)
{
return function();
}
/**
* Constructor for the StreamLogger class.
*/
-StreamLogger::StreamLogger(const Dictionary::Ptr& serializedUpdate)
- : Logger(serializedUpdate), m_Stream(NULL), m_OwnsStream(false), m_Tty(false)
-{ }
+void StreamLogger::Start(void)
+{
+ Logger::Start();
+
+ m_Stream = NULL;
+ m_OwnsStream = false;
+ m_Tty = false;
+}
/**
* Destructor for the StreamLogger class.
public:
DECLARE_PTR_TYPEDEFS(StreamLogger);
- StreamLogger(const Dictionary::Ptr& serializedUpdate);
+ virtual void Start(void);
~StreamLogger(void);
void BindStream(std::ostream *stream, bool ownsStream);
REGISTER_TYPE(SyslogLogger);
-/**
- * Constructor for the SyslogLogger class.
- */
-SyslogLogger::SyslogLogger(const Dictionary::Ptr& serializedUpdate)
- : Logger(serializedUpdate)
-{ }
-
/**
* Processes a log entry and outputs it to syslog.
*
public:
DECLARE_PTR_TYPEDEFS(SyslogLogger);
- explicit SyslogLogger(const Dictionary::Ptr& serializedUpdate);
-
protected:
virtual void ProcessLogEntry(const LogEntry& entry);
};
using namespace icinga;
ThreadPool::ThreadPool(void)
- : m_Stopped(false), m_ThreadDeaths(0), m_WaitTime(0),
- m_ServiceTime(0), m_TaskCount(0)
+ : m_ThreadDeaths(0), m_WaitTime(0), m_ServiceTime(0),
+ m_TaskCount(0), m_Stopped(false)
{
for (int i = 0; i < 2; i++)
SpawnWorker();
do {
alive = 0;
- for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
+ for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
if (m_ThreadStats[i].State != ThreadDead) {
alive++;
KillWorker();
Utility::SetThreadName(idbuf.str());
for (;;) {
- int pending, alive;
+ size_t pending, alive;
double avg_latency, max_latency;
double utilization = 0;
alive = 0;
- for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
+ for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
if (m_ThreadStats[i].State != ThreadDead) {
alive++;
utilization += m_ThreadStats[i].Utilization * 100;
*/
void ThreadPool::SpawnWorker(void)
{
- for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
+ for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++) {
if (m_ThreadStats[i].State == ThreadDead) {
Log(LogDebug, "debug", "Spawning worker thread.");
if (m_Stopped)
break;
- for (int i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++)
+ for (size_t i = 0; i < sizeof(m_ThreadStats) / sizeof(m_ThreadStats[0]); i++)
UpdateThreadUtilization(i);
}
}
String Utility::EscapeShellCmd(const String& s)
{
String result;
- int prev_quote = String::NPos;
+ size_t prev_quote = String::NPos;
int index = -1;
BOOST_FOREACH(char ch, s) {
******************************************************************************/
type DynamicObject {
- %require "__local",
- %attribute number "__local",
-
%require "__name",
%attribute string "__name",
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
-#define YY_NUM_RULES 60
-#define YY_END_OF_BUFFER 61
+#define YY_NUM_RULES 59
+#define YY_END_OF_BUFFER 60
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
-static yyconst flex_int16_t yy_accept[199] =
+static yyconst flex_int16_t yy_accept[195] =
{ 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 61, 59,
- 21, 21, 1, 59, 59, 59, 59, 59, 53, 59,
- 54, 59, 47, 47, 47, 47, 47, 47, 47, 47,
- 47, 47, 47, 59, 18, 19, 12, 3, 2, 60,
- 15, 15, 0, 0, 0, 57, 55, 53, 56, 16,
- 20, 58, 0, 50, 51, 52, 0, 45, 48, 46,
- 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
- 47, 47, 47, 47, 47, 47, 47, 47, 47, 0,
- 17, 12, 11, 4, 5, 9, 10, 6, 8, 7,
- 0, 0, 0, 0, 20, 53, 49, 47, 28, 47,
-
- 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
- 47, 47, 44, 47, 47, 47, 47, 13, 4, 5,
- 14, 0, 0, 0, 47, 47, 47, 47, 47, 47,
- 47, 47, 29, 40, 47, 47, 47, 47, 47, 47,
- 42, 22, 4, 0, 0, 0, 47, 24, 47, 43,
- 47, 47, 47, 34, 47, 47, 47, 47, 47, 47,
- 0, 0, 0, 47, 47, 47, 47, 47, 25, 35,
- 47, 27, 26, 47, 0, 0, 0, 47, 47, 37,
- 47, 38, 41, 47, 0, 31, 0, 33, 47, 39,
- 36, 0, 0, 47, 32, 30, 23, 0
+ 0, 0, 0, 0, 0, 0, 0, 0, 60, 58,
+ 21, 21, 1, 58, 58, 58, 58, 58, 52, 58,
+ 53, 58, 46, 46, 46, 46, 46, 46, 46, 46,
+ 46, 46, 46, 58, 18, 19, 12, 3, 2, 59,
+ 15, 15, 0, 0, 0, 56, 54, 52, 55, 16,
+ 20, 57, 0, 49, 50, 51, 0, 44, 47, 45,
+ 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
+ 46, 46, 46, 46, 46, 46, 46, 46, 0, 17,
+ 12, 11, 4, 5, 9, 10, 6, 8, 7, 0,
+ 0, 0, 0, 20, 52, 48, 46, 28, 46, 46,
+
+ 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
+ 43, 46, 46, 46, 46, 13, 4, 5, 14, 0,
+ 0, 0, 46, 46, 46, 46, 46, 46, 46, 29,
+ 39, 46, 46, 46, 46, 46, 46, 41, 22, 4,
+ 0, 0, 0, 46, 24, 46, 42, 46, 46, 46,
+ 46, 46, 46, 46, 46, 46, 0, 0, 0, 46,
+ 46, 46, 46, 46, 25, 34, 46, 27, 26, 46,
+ 0, 0, 0, 46, 46, 36, 46, 37, 40, 46,
+ 0, 31, 0, 33, 46, 38, 35, 0, 0, 46,
+ 32, 30, 23, 0
} ;
1, 1
} ;
-static yyconst flex_int16_t yy_base[207] =
+static yyconst flex_int16_t yy_base[203] =
{ 0,
- 0, 0, 247, 246, 40, 42, 209, 208, 249, 254,
- 254, 254, 254, 28, 233, 232, 37, 44, 44, 48,
- 254, 230, 0, 37, 218, 225, 212, 34, 46, 222,
- 222, 48, 52, 199, 254, 229, 0, 254, 254, 82,
- 254, 196, 200, 213, 216, 254, 254, 79, 254, 254,
- 0, 254, 65, 254, 198, 254, 217, 216, 254, 254,
- 0, 195, 190, 194, 207, 198, 52, 206, 204, 194,
- 52, 195, 187, 202, 183, 184, 188, 179, 183, 174,
- 254, 0, 254, 84, 86, 254, 254, 254, 254, 254,
- 172, 176, 178, 182, 0, 88, 254, 173, 0, 190,
-
- 171, 171, 177, 182, 169, 184, 179, 172, 180, 176,
- 161, 168, 0, 169, 162, 171, 170, 254, 92, 96,
- 254, 157, 153, 163, 154, 148, 160, 163, 147, 149,
- 164, 153, 0, 0, 158, 159, 152, 159, 146, 147,
- 0, 0, 99, 148, 147, 151, 153, 0, 139, 0,
- 148, 142, 133, 0, 132, 129, 146, 129, 138, 143,
- 141, 125, 140, 137, 126, 133, 118, 114, 0, 0,
- 124, 0, 0, 113, 105, 119, 86, 85, 102, 0,
- 84, 0, 0, 93, 75, 254, 69, 0, 54, 0,
- 0, 63, 48, 39, 254, 254, 0, 254, 124, 128,
-
- 132, 136, 47, 140, 144, 148
+ 0, 0, 243, 242, 40, 42, 205, 204, 245, 250,
+ 250, 250, 250, 28, 229, 228, 37, 44, 44, 48,
+ 250, 226, 0, 37, 214, 221, 208, 211, 46, 217,
+ 217, 48, 38, 194, 250, 224, 0, 250, 250, 75,
+ 250, 191, 195, 208, 211, 250, 250, 79, 250, 250,
+ 0, 250, 64, 250, 193, 250, 212, 211, 250, 250,
+ 0, 190, 185, 189, 202, 193, 56, 201, 190, 63,
+ 191, 183, 198, 179, 180, 184, 175, 179, 170, 250,
+ 0, 250, 85, 89, 250, 250, 250, 250, 250, 168,
+ 172, 174, 178, 0, 91, 250, 169, 0, 186, 167,
+
+ 167, 173, 178, 165, 176, 169, 177, 173, 158, 165,
+ 0, 166, 159, 168, 167, 250, 96, 102, 250, 154,
+ 150, 160, 151, 145, 157, 160, 144, 146, 161, 0,
+ 0, 156, 157, 150, 157, 144, 145, 0, 0, 107,
+ 146, 145, 149, 151, 0, 137, 0, 146, 140, 131,
+ 130, 127, 144, 127, 136, 141, 139, 123, 138, 135,
+ 122, 123, 108, 86, 0, 0, 96, 0, 0, 87,
+ 85, 99, 83, 79, 92, 0, 68, 0, 0, 75,
+ 57, 250, 57, 0, 48, 0, 0, 58, 44, 26,
+ 250, 250, 0, 250, 127, 131, 135, 139, 47, 143,
+
+ 147, 151
} ;
-static yyconst flex_int16_t yy_def[207] =
+static yyconst flex_int16_t yy_def[203] =
{ 0,
- 198, 1, 199, 199, 200, 200, 201, 201, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 202,
- 198, 198, 203, 203, 203, 203, 203, 203, 203, 203,
- 203, 203, 203, 198, 198, 198, 204, 198, 198, 205,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 206, 198, 198, 198, 198, 198, 202, 202, 198, 198,
- 203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
- 203, 203, 203, 203, 203, 203, 203, 203, 203, 198,
- 198, 204, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 206, 198, 198, 203, 203, 203,
-
- 203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
- 203, 203, 203, 203, 203, 203, 203, 198, 198, 198,
- 198, 198, 198, 198, 203, 203, 203, 203, 203, 203,
- 203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
- 203, 203, 198, 198, 198, 198, 203, 203, 203, 203,
- 203, 203, 203, 203, 203, 203, 203, 203, 203, 203,
- 198, 198, 198, 203, 203, 203, 203, 203, 203, 203,
- 203, 203, 203, 203, 198, 198, 198, 203, 203, 203,
- 203, 203, 203, 203, 198, 198, 198, 203, 203, 203,
- 203, 198, 198, 203, 198, 198, 203, 0, 198, 198,
-
- 198, 198, 198, 198, 198, 198
+ 194, 1, 195, 195, 196, 196, 197, 197, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 198,
+ 194, 194, 199, 199, 199, 199, 199, 199, 199, 199,
+ 199, 199, 199, 194, 194, 194, 200, 194, 194, 201,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 202, 194, 194, 194, 194, 194, 198, 198, 194, 194,
+ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
+ 199, 199, 199, 199, 199, 199, 199, 199, 194, 194,
+ 200, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 202, 194, 194, 199, 199, 199, 199,
+
+ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
+ 199, 199, 199, 199, 199, 194, 194, 194, 194, 194,
+ 194, 194, 199, 199, 199, 199, 199, 199, 199, 199,
+ 199, 199, 199, 199, 199, 199, 199, 199, 199, 194,
+ 194, 194, 194, 199, 199, 199, 199, 199, 199, 199,
+ 199, 199, 199, 199, 199, 199, 194, 194, 194, 199,
+ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
+ 194, 194, 194, 199, 199, 199, 199, 199, 199, 199,
+ 194, 194, 194, 199, 199, 199, 199, 194, 194, 199,
+ 194, 194, 199, 0, 194, 194, 194, 194, 194, 194,
+
+ 194, 194
} ;
-static yyconst flex_int16_t yy_nxt[297] =
+static yyconst flex_int16_t yy_nxt[293] =
{ 0,
10, 11, 12, 13, 14, 15, 16, 17, 10, 18,
19, 19, 10, 20, 21, 22, 23, 10, 24, 23,
29, 30, 31, 23, 23, 32, 33, 23, 23, 23,
34, 10, 38, 39, 38, 39, 43, 48, 48, 50,
61, 49, 53, 51, 48, 48, 62, 40, 52, 40,
- 68, 58, 44, 59, 70, 69, 45, 63, 74, 54,
- 75, 64, 103, 55, 77, 96, 96, 104, 197, 56,
- 108, 109, 196, 71, 76, 195, 78, 53, 194, 48,
- 48, 79, 84, 85, 119, 120, 120, 120, 96, 96,
-
- 193, 86, 143, 120, 54, 87, 120, 120, 55, 120,
- 120, 192, 88, 54, 56, 191, 89, 55, 90, 190,
- 189, 188, 187, 56, 35, 35, 35, 35, 37, 37,
- 37, 37, 41, 41, 41, 41, 57, 57, 57, 57,
- 82, 186, 185, 82, 83, 83, 83, 83, 95, 184,
- 95, 95, 183, 182, 181, 180, 179, 178, 177, 176,
- 175, 174, 173, 172, 171, 170, 169, 168, 167, 166,
- 165, 164, 163, 162, 161, 160, 159, 158, 157, 156,
- 155, 154, 153, 152, 151, 150, 149, 148, 147, 146,
- 145, 144, 142, 141, 140, 139, 138, 137, 136, 135,
-
- 134, 133, 132, 131, 130, 129, 128, 127, 126, 125,
- 124, 123, 122, 121, 118, 117, 116, 115, 114, 113,
- 112, 111, 110, 107, 106, 105, 102, 101, 100, 99,
- 98, 59, 59, 97, 94, 93, 92, 91, 81, 80,
- 73, 72, 67, 66, 65, 60, 47, 46, 198, 42,
- 42, 36, 36, 9, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198
+ 76, 58, 44, 59, 69, 193, 45, 63, 73, 54,
+ 74, 64, 77, 55, 95, 95, 102, 78, 192, 56,
+ 191, 103, 190, 70, 75, 83, 84, 53, 189, 48,
+ 48, 106, 107, 188, 85, 117, 118, 187, 86, 118,
+
+ 118, 95, 95, 186, 54, 87, 140, 118, 55, 88,
+ 185, 89, 118, 118, 56, 184, 54, 118, 118, 183,
+ 55, 182, 181, 180, 179, 178, 56, 35, 35, 35,
+ 35, 37, 37, 37, 37, 41, 41, 41, 41, 57,
+ 57, 57, 57, 81, 177, 176, 81, 82, 82, 82,
+ 82, 94, 175, 94, 94, 174, 173, 172, 171, 170,
+ 169, 168, 167, 166, 165, 164, 163, 162, 161, 160,
+ 159, 158, 157, 156, 155, 154, 153, 152, 151, 150,
+ 149, 148, 147, 146, 145, 144, 143, 142, 141, 139,
+ 138, 137, 136, 135, 134, 133, 132, 131, 130, 129,
+
+ 128, 127, 126, 125, 124, 123, 122, 121, 120, 119,
+ 116, 115, 114, 113, 112, 111, 110, 109, 108, 105,
+ 104, 101, 100, 99, 98, 97, 59, 59, 96, 93,
+ 92, 91, 90, 80, 79, 72, 71, 68, 67, 66,
+ 65, 60, 47, 46, 194, 42, 42, 36, 36, 9,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194
} ;
-static yyconst flex_int16_t yy_chk[297] =
+static yyconst flex_int16_t yy_chk[293] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 5, 5, 6, 6, 14, 17, 17, 18,
- 203, 17, 19, 18, 19, 19, 24, 5, 18, 6,
- 28, 20, 14, 20, 29, 28, 14, 24, 32, 19,
- 32, 24, 67, 19, 33, 53, 53, 67, 194, 19,
- 71, 71, 193, 29, 32, 192, 33, 48, 189, 48,
- 48, 33, 40, 40, 84, 84, 85, 85, 96, 96,
-
- 187, 40, 119, 119, 48, 40, 120, 120, 48, 143,
- 143, 185, 40, 96, 48, 184, 40, 96, 40, 181,
- 179, 178, 177, 96, 199, 199, 199, 199, 200, 200,
- 200, 200, 201, 201, 201, 201, 202, 202, 202, 202,
- 204, 176, 175, 204, 205, 205, 205, 205, 206, 174,
- 206, 206, 171, 168, 167, 166, 165, 164, 163, 162,
- 161, 160, 159, 158, 157, 156, 155, 153, 152, 151,
- 149, 147, 146, 145, 144, 140, 139, 138, 137, 136,
- 135, 132, 131, 130, 129, 128, 127, 126, 125, 124,
- 123, 122, 117, 116, 115, 114, 112, 111, 110, 109,
-
- 108, 107, 106, 105, 104, 103, 102, 101, 100, 98,
- 94, 93, 92, 91, 80, 79, 78, 77, 76, 75,
- 74, 73, 72, 70, 69, 68, 66, 65, 64, 63,
- 62, 58, 57, 55, 45, 44, 43, 42, 36, 34,
- 31, 30, 27, 26, 25, 22, 16, 15, 9, 8,
- 7, 4, 3, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198, 198, 198, 198, 198,
- 198, 198, 198, 198, 198, 198
+ 199, 17, 19, 18, 19, 19, 24, 5, 18, 6,
+ 33, 20, 14, 20, 29, 190, 14, 24, 32, 19,
+ 32, 24, 33, 19, 53, 53, 67, 33, 189, 19,
+ 188, 67, 185, 29, 32, 40, 40, 48, 183, 48,
+ 48, 70, 70, 181, 40, 83, 83, 180, 40, 84,
+
+ 84, 95, 95, 177, 48, 40, 117, 117, 48, 40,
+ 175, 40, 118, 118, 48, 174, 95, 140, 140, 173,
+ 95, 172, 171, 170, 167, 164, 95, 195, 195, 195,
+ 195, 196, 196, 196, 196, 197, 197, 197, 197, 198,
+ 198, 198, 198, 200, 163, 162, 200, 201, 201, 201,
+ 201, 202, 161, 202, 202, 160, 159, 158, 157, 156,
+ 155, 154, 153, 152, 151, 150, 149, 148, 146, 144,
+ 143, 142, 141, 137, 136, 135, 134, 133, 132, 129,
+ 128, 127, 126, 125, 124, 123, 122, 121, 120, 115,
+ 114, 113, 112, 110, 109, 108, 107, 106, 105, 104,
+
+ 103, 102, 101, 100, 99, 97, 93, 92, 91, 90,
+ 79, 78, 77, 76, 75, 74, 73, 72, 71, 69,
+ 68, 66, 65, 64, 63, 62, 58, 57, 55, 45,
+ 44, 43, 42, 36, 34, 31, 30, 28, 27, 26,
+ 25, 22, 16, 15, 9, 8, 7, 4, 3, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194
} ;
/* Table of booleans, true if rule could match eol. */
-static yyconst flex_int32_t yy_rule_can_match_eol[61] =
+static yyconst flex_int32_t yy_rule_can_match_eol[60] =
{ 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, };
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ };
/* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed.
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 199 )
+ if ( yy_current_state >= 195 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
- while ( yy_current_state != 198 );
+ while ( yy_current_state != 194 );
yy_cp = yyg->yy_last_accepting_cpos;
yy_current_state = yyg->yy_last_accepting_state;
{
std::ostringstream msgbuf;
msgbuf << "Unterminated string found: " << *yylloc;
- ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
BEGIN(INITIAL);
}
YY_BREAK
/* error, constant is out-of-bounds */
std::ostringstream msgbuf;
msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc;
- ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
}
lb_append_char(&string_buf, result);
*/
std::ostringstream msgbuf;
msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc;
- ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
}
YY_BREAK
case 6:
case 34:
YY_RULE_SETUP
#line 202 "config_lexer.ll"
-return T_LOCAL;
+return T_OBJECT;
YY_BREAK
case 35:
YY_RULE_SETUP
#line 203 "config_lexer.ll"
-return T_OBJECT;
+return T_TEMPLATE;
YY_BREAK
case 36:
YY_RULE_SETUP
#line 204 "config_lexer.ll"
-return T_TEMPLATE;
+return T_INCLUDE;
YY_BREAK
case 37:
YY_RULE_SETUP
#line 205 "config_lexer.ll"
-return T_INCLUDE;
+return T_LIBRARY;
YY_BREAK
case 38:
YY_RULE_SETUP
#line 206 "config_lexer.ll"
-return T_LIBRARY;
+return T_INHERITS;
YY_BREAK
case 39:
YY_RULE_SETUP
#line 207 "config_lexer.ll"
-return T_INHERITS;
+return T_NULL;
YY_BREAK
case 40:
YY_RULE_SETUP
#line 208 "config_lexer.ll"
-return T_NULL;
+return T_PARTIAL;
YY_BREAK
case 41:
YY_RULE_SETUP
#line 209 "config_lexer.ll"
-return T_PARTIAL;
+{ yylval->num = 1; return T_NUMBER; }
YY_BREAK
case 42:
YY_RULE_SETUP
#line 210 "config_lexer.ll"
-{ yylval->num = 1; return T_NUMBER; }
+{ yylval->num = 0; return T_NUMBER; }
YY_BREAK
case 43:
YY_RULE_SETUP
#line 211 "config_lexer.ll"
-{ yylval->num = 0; return T_NUMBER; }
+return T_SET;
YY_BREAK
case 44:
YY_RULE_SETUP
#line 212 "config_lexer.ll"
-return T_SET;
+return T_SHIFT_LEFT;
YY_BREAK
case 45:
YY_RULE_SETUP
#line 213 "config_lexer.ll"
-return T_SHIFT_LEFT;
+return T_SHIFT_RIGHT;
YY_BREAK
case 46:
YY_RULE_SETUP
#line 214 "config_lexer.ll"
-return T_SHIFT_RIGHT;
+{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
YY_BREAK
case 47:
+/* rule 47 can match eol */
YY_RULE_SETUP
#line 215 "config_lexer.ll"
-{ yylval->text = strdup(yytext); return T_IDENTIFIER; }
+{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
YY_BREAK
case 48:
-/* rule 48 can match eol */
YY_RULE_SETUP
#line 216 "config_lexer.ll"
-{ yytext[yyleng-1] = '\0'; yylval->text = strdup(yytext + 1); return T_STRING_ANGLE; }
+{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
YY_BREAK
case 49:
YY_RULE_SETUP
#line 217 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL) / 1000; return T_NUMBER; }
+{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
YY_BREAK
case 50:
YY_RULE_SETUP
#line 218 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL) * 60 * 60; return T_NUMBER; }
+{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
YY_BREAK
case 51:
YY_RULE_SETUP
#line 219 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL) * 60; return T_NUMBER; }
+{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
YY_BREAK
case 52:
YY_RULE_SETUP
case 53:
YY_RULE_SETUP
#line 221 "config_lexer.ll"
-{ yylval->num = strtod(yytext, NULL); return T_NUMBER; }
+{ yylval->op = OperatorSet; return T_EQUAL; }
YY_BREAK
case 54:
YY_RULE_SETUP
#line 222 "config_lexer.ll"
-{ yylval->op = OperatorSet; return T_EQUAL; }
+{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
YY_BREAK
case 55:
YY_RULE_SETUP
#line 223 "config_lexer.ll"
-{ yylval->op = OperatorPlus; return T_PLUS_EQUAL; }
+{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
YY_BREAK
case 56:
YY_RULE_SETUP
#line 224 "config_lexer.ll"
-{ yylval->op = OperatorMinus; return T_MINUS_EQUAL; }
+{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
YY_BREAK
case 57:
YY_RULE_SETUP
#line 225 "config_lexer.ll"
-{ yylval->op = OperatorMultiply; return T_MULTIPLY_EQUAL; }
- YY_BREAK
-case 58:
-YY_RULE_SETUP
-#line 226 "config_lexer.ll"
{ yylval->op = OperatorDivide; return T_DIVIDE_EQUAL; }
YY_BREAK
-case 59:
+case 58:
YY_RULE_SETUP
-#line 229 "config_lexer.ll"
+#line 228 "config_lexer.ll"
return yytext[0];
YY_BREAK
-case 60:
+case 59:
YY_RULE_SETUP
-#line 231 "config_lexer.ll"
+#line 230 "config_lexer.ll"
ECHO;
YY_BREAK
-#line 1399 "../../../lib/config/config_lexer.cc"
+#line 1394 "../../../lib/config/config_lexer.cc"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(C_COMMENT):
case YY_STATE_EOF(STRING):
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 199 )
+ if ( yy_current_state >= 195 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
- if ( yy_current_state >= 199 )
+ if ( yy_current_state >= 195 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
- yy_is_jam = (yy_current_state == 198);
+ yy_is_jam = (yy_current_state == 194);
return yy_is_jam ? 0 : yy_current_state;
}
#define YYTABLES_NAME "yytables"
-#line 231 "config_lexer.ll"
+#line 230 "config_lexer.ll"
<STRING>\n {
std::ostringstream msgbuf;
msgbuf << "Unterminated string found: " << *yylloc;
- ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
BEGIN(INITIAL);
}
/* error, constant is out-of-bounds */
std::ostringstream msgbuf;
msgbuf << "Constant is out-of-bounds: " << yytext << " " << *yylloc;
- ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
}
lb_append_char(&string_buf, result);
*/
std::ostringstream msgbuf;
msgbuf << "Bad escape sequence found: " << yytext << " " << *yylloc;
- ConfigCompilerContext::GetContext()->AddError(false, msgbuf.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, msgbuf.str());
}
<STRING>\\n { lb_append_char(&string_buf, '\n'); }
%require { return T_REQUIRE; }
%attribute { return T_ATTRIBUTE; }
abstract return T_ABSTRACT;
-local return T_LOCAL;
object return T_OBJECT;
template return T_TEMPLATE;
include return T_INCLUDE;
T_ATTRIBUTE = 280,
T_TYPE = 281,
T_ABSTRACT = 282,
- T_LOCAL = 283,
- T_OBJECT = 284,
- T_TEMPLATE = 285,
- T_INCLUDE = 286,
- T_LIBRARY = 287,
- T_INHERITS = 288,
- T_PARTIAL = 289
+ T_OBJECT = 283,
+ T_TEMPLATE = 284,
+ T_INCLUDE = 285,
+ T_LIBRARY = 286,
+ T_INHERITS = 287,
+ T_PARTIAL = 288
};
#endif
/* Tokens. */
#define T_ATTRIBUTE 280
#define T_TYPE 281
#define T_ABSTRACT 282
-#define T_LOCAL 283
-#define T_OBJECT 284
-#define T_TEMPLATE 285
-#define T_INCLUDE 286
-#define T_LIBRARY 287
-#define T_INHERITS 288
-#define T_PARTIAL 289
+#define T_OBJECT 283
+#define T_TEMPLATE 284
+#define T_INCLUDE 285
+#define T_LIBRARY 286
+#define T_INHERITS 287
+#define T_PARTIAL 288
/* Line 293 of yacc.c */
-#line 240 "../../../lib/config/config_parser.cc"
+#line 238 "../../../lib/config/config_parser.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
/* Copy the second part of user declarations. */
/* Line 343 of yacc.c */
-#line 120 "config_parser.yy"
+#line 119 "config_parser.yy"
int yylex(YYSTYPE *lvalp, YYLTYPE *llocp, void *scanner);
{
std::ostringstream message;
message << *locp << ": " << err;
- ConfigCompilerContext::GetContext()->AddError(false, message.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, message.str());
}
int yyparse(ConfigCompiler *context);
static std::stack<Array::Ptr> m_Arrays;
static bool m_Abstract;
-static bool m_Local;
static std::stack<TypeRuleList::Ptr> m_RuleLists;
static ConfigType::Ptr m_Type;
void ConfigCompiler::Compile(void)
{
- ASSERT(ConfigCompilerContext::GetContext() != NULL);
-
try {
yyparse(this);
} catch (const std::exception& ex) {
- ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
+ ConfigCompilerContext::GetInstance()->AddError(false, boost::diagnostic_information(ex));
}
}
/* Line 343 of yacc.c */
-#line 301 "../../../lib/config/config_parser.cc"
+#line 296 "../../../lib/config/config_parser.cc"
#ifdef short
# undef short
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 2
/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 147
+#define YYLAST 149
/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS 48
+#define YYNTOKENS 47
/* YYNNTS -- Number of nonterminals. */
#define YYNNTS 35
/* YYNRULES -- Number of rules. */
-#define YYNRULES 90
+#define YYNRULES 89
/* YYNRULES -- Number of states. */
-#define YYNSTATES 132
+#define YYNSTATES 131
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
-#define YYMAXUTOK 289
+#define YYMAXUTOK 288
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 39, 2,
- 44, 45, 37, 35, 43, 36, 2, 38, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 38, 2,
+ 43, 44, 36, 34, 42, 35, 2, 37, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 46, 2, 47, 2, 2, 2, 2, 2, 2,
+ 2, 45, 2, 46, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 41, 40, 42, 2, 2, 2, 2,
+ 2, 2, 2, 40, 39, 41, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
+ 25, 26, 27, 28, 29, 30, 31, 32, 33
};
#if YYDEBUG
20, 23, 26, 31, 33, 35, 36, 43, 44, 46,
47, 52, 54, 57, 58, 60, 64, 67, 70, 74,
81, 86, 87, 90, 92, 94, 96, 98, 100, 102,
- 104, 105, 112, 115, 117, 118, 121, 123, 125, 126,
- 128, 132, 133, 136, 140, 142, 145, 146, 148, 152,
- 156, 163, 165, 167, 169, 171, 173, 177, 179, 182,
- 183, 185, 189, 191, 193, 195, 197, 201, 203, 205,
- 209, 213, 217, 221, 225, 229, 233, 237, 241, 243,
- 245
+ 104, 105, 112, 115, 117, 118, 121, 123, 124, 126,
+ 130, 131, 134, 138, 140, 143, 144, 146, 150, 154,
+ 161, 163, 165, 167, 169, 171, 175, 177, 180, 181,
+ 183, 187, 189, 191, 193, 195, 199, 201, 203, 207,
+ 211, 215, 219, 223, 227, 231, 235, 239, 241, 243
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
- 49, 0, -1, -1, 49, 50, -1, 64, -1, 55,
- -1, 51, -1, 52, -1, 53, -1, 31, 3, -1,
- 31, 4, -1, 32, 3, -1, 13, 54, 8, 82,
- -1, 7, -1, 3, -1, -1, 57, 26, 54, 56,
- 63, 58, -1, -1, 34, -1, -1, 41, 59, 60,
- 42, -1, 61, -1, 61, 43, -1, -1, 62, -1,
- 61, 43, 62, -1, 24, 3, -1, 23, 3, -1,
- 25, 55, 3, -1, 25, 22, 44, 54, 45, 3,
- -1, 25, 55, 3, 58, -1, -1, 33, 54, -1,
+ 48, 0, -1, -1, 48, 49, -1, 63, -1, 54,
+ -1, 50, -1, 51, -1, 52, -1, 30, 3, -1,
+ 30, 4, -1, 31, 3, -1, 13, 53, 8, 81,
+ -1, 7, -1, 3, -1, -1, 56, 26, 53, 55,
+ 62, 57, -1, -1, 33, -1, -1, 40, 58, 59,
+ 41, -1, 60, -1, 60, 42, -1, -1, 61, -1,
+ 60, 42, 61, -1, 24, 3, -1, 23, 3, -1,
+ 25, 54, 3, -1, 25, 22, 43, 53, 44, 3,
+ -1, 25, 54, 3, 57, -1, -1, 32, 53, -1,
16, -1, 17, -1, 18, -1, 19, -1, 20, -1,
- 21, -1, 22, -1, -1, 65, 66, 54, 3, 70,
- 71, -1, 67, 29, -1, 30, -1, -1, 67, 68,
- -1, 27, -1, 28, -1, -1, 3, -1, 69, 43,
- 3, -1, -1, 33, 69, -1, 41, 72, 42, -1,
- 73, -1, 73, 43, -1, -1, 74, -1, 73, 43,
- 74, -1, 54, 75, 82, -1, 54, 46, 3, 47,
- 75, 82, -1, 8, -1, 9, -1, 10, -1, 11,
- -1, 12, -1, 46, 77, 47, -1, 78, -1, 78,
- 43, -1, -1, 82, -1, 78, 43, 82, -1, 3,
- -1, 5, -1, 6, -1, 76, -1, 44, 81, 45,
- -1, 5, -1, 54, -1, 81, 35, 81, -1, 81,
- 36, 81, -1, 81, 37, 81, -1, 81, 38, 81,
- -1, 81, 39, 81, -1, 81, 40, 81, -1, 81,
- 14, 81, -1, 81, 15, 81, -1, 44, 81, 45,
- -1, 79, -1, 71, -1, 80, -1
+ 21, -1, 22, -1, -1, 64, 65, 53, 3, 69,
+ 70, -1, 66, 28, -1, 29, -1, -1, 66, 67,
+ -1, 27, -1, -1, 3, -1, 68, 42, 3, -1,
+ -1, 32, 68, -1, 40, 71, 41, -1, 72, -1,
+ 72, 42, -1, -1, 73, -1, 72, 42, 73, -1,
+ 53, 74, 81, -1, 53, 45, 3, 46, 74, 81,
+ -1, 8, -1, 9, -1, 10, -1, 11, -1, 12,
+ -1, 45, 76, 46, -1, 77, -1, 77, 42, -1,
+ -1, 81, -1, 77, 42, 81, -1, 3, -1, 5,
+ -1, 6, -1, 75, -1, 43, 80, 44, -1, 5,
+ -1, 53, -1, 80, 34, 80, -1, 80, 35, 80,
+ -1, 80, 36, 80, -1, 80, 37, 80, -1, 80,
+ 38, 80, -1, 80, 39, 80, -1, 80, 14, 80,
+ -1, 80, 15, 80, -1, 43, 80, 44, -1, 78,
+ -1, 70, -1, 79, -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 156, 156, 157, 160, 160, 160, 160, 160, 163,
- 168, 174, 180, 187, 188, 195, 194, 224, 227, 234,
- 233, 245, 246, 248, 249, 250, 253, 258, 263, 270,
- 278, 287, 288, 295, 296, 297, 298, 299, 300, 301,
- 308, 308, 353, 354, 359, 360, 363, 367, 374, 377,
- 383, 396, 399, 405, 411, 415, 421, 424, 430, 442,
- 448, 462, 463, 464, 465, 466, 472, 478, 482, 488,
- 491, 506, 526, 531, 535, 539, 549, 554, 558, 563,
- 567, 571, 575, 579, 583, 587, 591, 595, 601, 602,
- 607
+ 0, 152, 152, 153, 156, 156, 156, 156, 156, 159,
+ 164, 170, 176, 183, 184, 191, 190, 220, 223, 230,
+ 229, 241, 242, 244, 245, 246, 249, 254, 259, 266,
+ 274, 283, 284, 291, 292, 293, 294, 295, 296, 297,
+ 304, 304, 345, 346, 351, 352, 355, 362, 365, 371,
+ 384, 387, 393, 399, 403, 409, 412, 418, 430, 436,
+ 450, 451, 452, 453, 454, 460, 466, 470, 476, 479,
+ 494, 514, 519, 523, 527, 537, 542, 546, 551, 555,
+ 559, 563, 567, 571, 575, 579, 583, 589, 590, 595
};
#endif
"\"any (T_TYPE_ANY)\"", "\"name (T_TYPE_NAME)\"",
"\"%validator (T_VALIDATOR)\"", "\"%require (T_REQUIRE)\"",
"\"%attribute (T_ATTRIBUTE)\"", "\"type (T_TYPE)\"",
- "\"abstract (T_ABSTRACT)\"", "\"local (T_LOCAL)\"",
- "\"object (T_OBJECT)\"", "\"template (T_TEMPLATE)\"",
- "\"include (T_INCLUDE)\"", "\"library (T_LIBRARY)\"",
- "\"inherits (T_INHERITS)\"", "\"partial (T_PARTIAL)\"", "'+'", "'-'",
- "'*'", "'/'", "'&'", "'|'", "'{'", "'}'", "','", "'('", "')'", "'['",
- "']'", "$accept", "statements", "statement", "include", "library",
- "variable", "identifier", "type", "$@1", "partial_specifier",
- "typerulelist", "$@2", "typerules", "typerules_inner", "typerule",
- "type_inherits_specifier", "object", "$@3", "object_declaration",
- "attributes", "attribute", "object_inherits_list",
- "object_inherits_specifier", "expressionlist", "expressions",
- "expressions_inner", "expression", "operator", "array", "array_items",
- "array_items_inner", "simplevalue", "constterm", "constexpression",
- "value", 0
+ "\"abstract (T_ABSTRACT)\"", "\"object (T_OBJECT)\"",
+ "\"template (T_TEMPLATE)\"", "\"include (T_INCLUDE)\"",
+ "\"library (T_LIBRARY)\"", "\"inherits (T_INHERITS)\"",
+ "\"partial (T_PARTIAL)\"", "'+'", "'-'", "'*'", "'/'", "'&'", "'|'",
+ "'{'", "'}'", "','", "'('", "')'", "'['", "']'", "$accept", "statements",
+ "statement", "include", "library", "variable", "identifier", "type",
+ "$@1", "partial_specifier", "typerulelist", "$@2", "typerules",
+ "typerules_inner", "typerule", "type_inherits_specifier", "object",
+ "$@3", "object_declaration", "attributes", "attribute",
+ "object_inherits_list", "object_inherits_specifier", "expressionlist",
+ "expressions", "expressions_inner", "expression", "operator", "array",
+ "array_items", "array_items_inner", "simplevalue", "constterm",
+ "constexpression", "value", 0
};
#endif
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
- 285, 286, 287, 288, 289, 43, 45, 42, 47, 38,
- 124, 123, 125, 44, 40, 41, 91, 93
+ 285, 286, 287, 288, 43, 45, 42, 47, 38, 124,
+ 123, 125, 44, 40, 41, 91, 93
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
- 0, 48, 49, 49, 50, 50, 50, 50, 50, 51,
- 51, 52, 53, 54, 54, 56, 55, 57, 57, 59,
- 58, 60, 60, 61, 61, 61, 62, 62, 62, 62,
- 62, 63, 63, 55, 55, 55, 55, 55, 55, 55,
- 65, 64, 66, 66, 67, 67, 68, 68, 69, 69,
- 69, 70, 70, 71, 72, 72, 73, 73, 73, 74,
- 74, 75, 75, 75, 75, 75, 76, 77, 77, 78,
- 78, 78, 79, 79, 79, 79, 80, 81, 81, 81,
- 81, 81, 81, 81, 81, 81, 81, 81, 82, 82,
- 82
+ 0, 47, 48, 48, 49, 49, 49, 49, 49, 50,
+ 50, 51, 52, 53, 53, 55, 54, 56, 56, 58,
+ 57, 59, 59, 60, 60, 60, 61, 61, 61, 61,
+ 61, 62, 62, 54, 54, 54, 54, 54, 54, 54,
+ 64, 63, 65, 65, 66, 66, 67, 68, 68, 68,
+ 69, 69, 70, 71, 71, 72, 72, 72, 73, 73,
+ 74, 74, 74, 74, 74, 75, 76, 76, 77, 77,
+ 77, 78, 78, 78, 78, 79, 80, 80, 80, 80,
+ 80, 80, 80, 80, 80, 80, 80, 81, 81, 81
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
2, 2, 4, 1, 1, 0, 6, 0, 1, 0,
4, 1, 2, 0, 1, 3, 2, 2, 3, 6,
4, 0, 2, 1, 1, 1, 1, 1, 1, 1,
- 0, 6, 2, 1, 0, 2, 1, 1, 0, 1,
- 3, 0, 2, 3, 1, 2, 0, 1, 3, 3,
- 6, 1, 1, 1, 1, 1, 3, 1, 2, 0,
- 1, 3, 1, 1, 1, 1, 3, 1, 1, 3,
- 3, 3, 3, 3, 3, 3, 3, 3, 1, 1,
- 1
+ 0, 6, 2, 1, 0, 2, 1, 0, 1, 3,
+ 0, 2, 3, 1, 2, 0, 1, 3, 3, 6,
+ 1, 1, 1, 1, 1, 3, 1, 2, 0, 1,
+ 3, 1, 1, 1, 1, 3, 1, 1, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 1, 1, 1
};
/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
2, 40, 1, 0, 33, 34, 35, 36, 37, 38,
39, 0, 0, 18, 3, 6, 7, 8, 5, 0,
4, 44, 14, 13, 0, 9, 10, 11, 0, 43,
- 0, 0, 0, 15, 0, 46, 47, 42, 45, 72,
- 73, 74, 56, 0, 69, 89, 75, 88, 90, 12,
- 31, 51, 0, 0, 54, 57, 77, 0, 78, 0,
- 0, 67, 70, 0, 0, 48, 0, 61, 62, 63,
- 64, 65, 0, 0, 53, 55, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 76, 66, 68, 32, 19,
- 16, 49, 52, 41, 0, 59, 58, 87, 85, 86,
- 79, 80, 81, 82, 83, 84, 71, 23, 0, 0,
- 0, 0, 17, 0, 21, 24, 50, 0, 27, 26,
- 39, 0, 20, 22, 60, 0, 28, 25, 0, 30,
- 0, 29
+ 0, 0, 0, 15, 0, 46, 42, 45, 71, 72,
+ 73, 55, 0, 68, 88, 74, 87, 89, 12, 31,
+ 50, 0, 0, 53, 56, 76, 0, 77, 0, 0,
+ 66, 69, 0, 0, 47, 0, 60, 61, 62, 63,
+ 64, 0, 0, 52, 54, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 75, 65, 67, 32, 19, 16,
+ 48, 51, 41, 0, 58, 57, 86, 84, 85, 78,
+ 79, 80, 81, 82, 83, 70, 23, 0, 0, 0,
+ 0, 17, 0, 21, 24, 49, 0, 27, 26, 39,
+ 0, 20, 22, 59, 0, 28, 25, 0, 30, 0,
+ 29
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
- -1, 1, 14, 15, 16, 17, 58, 18, 50, 19,
- 90, 107, 113, 114, 115, 64, 20, 21, 30, 31,
- 38, 92, 66, 45, 53, 54, 55, 73, 46, 60,
- 61, 47, 48, 59, 49
+ -1, 1, 14, 15, 16, 17, 57, 18, 49, 19,
+ 89, 106, 112, 113, 114, 63, 20, 21, 30, 31,
+ 37, 91, 65, 44, 52, 53, 54, 72, 45, 59,
+ 60, 46, 47, 58, 48
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
-#define YYPACT_NINF -44
+#define YYPACT_NINF -43
static const yytype_int8 yypact[] =
{
- -44, 35, -44, 0, -44, -44, -44, -44, -44, -44,
- -44, 19, 21, -44, -44, -44, -44, -44, -44, -17,
- -44, -19, -44, -44, 18, -44, -44, -44, 0, -44,
- 0, -10, -1, -44, 31, -44, -44, -44, -44, -44,
- -44, -44, 0, 3, -1, -44, -44, -44, -44, -44,
- 9, 16, 4, -6, -2, -44, -44, 3, -44, 44,
- 17, 22, -44, 0, 27, 70, 34, -44, -44, -44,
- -44, -44, 73, -1, -44, 0, 56, 3, 3, 3,
- 3, 3, 3, 3, 3, -44, -44, -1, -44, -44,
- -44, -44, 43, -44, 30, -44, -44, -44, 88, 88,
- 99, 99, 23, 23, 6, 14, -44, 8, 75, 107,
- 84, 85, 113, 48, 54, -44, -44, -1, -44, -44,
- 55, 95, -44, 8, -44, 0, 27, -44, 59, -44,
- 97, -44
+ -43, 35, -43, 1, -43, -43, -43, -43, -43, -43,
+ -43, 20, -1, -43, -43, -43, -43, -43, -43, -16,
+ -43, -17, -43, -43, 18, -43, -43, -43, 1, -43,
+ 1, 6, 0, -43, 28, -43, -43, -43, -43, -43,
+ -43, 1, 4, 0, -43, -43, -43, -43, -43, 9,
+ 10, 5, -9, -6, -43, -43, 4, -43, 48, -7,
+ 16, -43, 1, 24, 34, 27, -43, -43, -43, -43,
+ -43, 46, 0, -43, 1, 61, 4, 4, 4, 4,
+ 4, 4, 4, 4, -43, -43, 0, -43, -43, -43,
+ -43, 30, -43, 43, -43, -43, -43, 88, 88, 92,
+ 92, 55, 55, 7, 14, -43, -5, 57, 69, 70,
+ 87, 116, 50, 59, -43, -43, 0, -43, -43, 73,
+ 101, -43, -5, -43, 1, 24, -43, 74, -43, 114,
+ -43
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
- -44, -44, -44, -44, -44, -44, -3, 29, -44, -44,
- -5, -44, -44, -44, 20, -44, -44, -44, -44, -44,
- -44, -44, -44, 74, -44, -44, 45, 33, -44, -44,
- -44, -44, -44, 28, -43
+ -43, -43, -43, -43, -43, -43, -3, 8, -43, -43,
+ 15, -43, -43, -43, -2, -43, -43, -43, -43, -43,
+ -43, -43, -43, 76, -43, -43, 65, 36, -43, -43,
+ -43, -43, -43, 32, -42
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
#define YYTABLE_NINF -18
static const yytype_int16 yytable[] =
{
- 24, 62, 39, 22, 40, 41, 22, 23, 56, 28,
- 23, 29, 67, 68, 69, 70, 71, 35, 36, 37,
- 77, 78, 25, 26, 27, 33, 32, 34, 77, 78,
- 95, 110, 111, 112, 51, 2, 74, 77, 78, 52,
- 42, 75, 63, 43, 106, 44, 84, 57, 3, 65,
- 72, 4, 5, 6, 7, 8, 9, 10, 77, 78,
- 88, -17, 83, 84, 86, 87, 11, 12, 89, 13,
- 77, 78, 52, 91, 124, 42, 94, 109, 116, 79,
- 80, 81, 82, 83, 84, 76, 108, 118, 119, 85,
- 122, 79, 80, 81, 82, 83, 84, 123, 126, 125,
- 131, 97, 77, 78, 130, 98, 99, 100, 101, 102,
- 103, 104, 105, 77, 78, 67, 68, 69, 70, 71,
- 96, 129, 128, 79, 80, 81, 82, 83, 84, 4,
- 5, 6, 7, 8, 9, 120, 81, 82, 83, 84,
- 93, 121, 117, 127, 0, 0, 0, 13
+ 24, 61, 27, 38, 22, 39, 40, 22, 23, 55,
+ 28, 23, 29, 66, 67, 68, 69, 70, 109, 110,
+ 111, 76, 77, 25, 26, 33, 32, 34, 76, 77,
+ 94, 50, 73, 35, 36, 2, 74, 90, 51, 85,
+ 41, 62, 64, 42, 105, 43, 83, 56, 3, 93,
+ 71, 4, 5, 6, 7, 8, 9, 10, 86, 87,
+ 115, -17, 76, 77, 88, 11, 12, 41, 13, 76,
+ 77, 51, 107, 117, 123, 76, 77, 66, 67, 68,
+ 69, 70, 78, 79, 80, 81, 82, 83, 75, 108,
+ 118, 121, 84, 82, 83, 78, 79, 80, 81, 82,
+ 83, 122, 76, 77, 125, 96, 76, 77, 97, 98,
+ 99, 100, 101, 102, 103, 104, 124, 130, 129, 120,
+ 126, 127, 78, 79, 80, 81, 82, 83, 80, 81,
+ 82, 83, 4, 5, 6, 7, 8, 9, 119, 95,
+ 128, 92, 0, 0, 116, 0, 0, 0, 0, 13
};
#define yypact_value_is_default(yystate) \
- ((yystate) == (-44))
+ ((yystate) == (-43))
#define yytable_value_is_error(yytable_value) \
YYID (0)
static const yytype_int8 yycheck[] =
{
- 3, 44, 3, 3, 5, 6, 3, 7, 5, 26,
- 7, 30, 8, 9, 10, 11, 12, 27, 28, 29,
- 14, 15, 3, 4, 3, 28, 8, 30, 14, 15,
- 73, 23, 24, 25, 3, 0, 42, 14, 15, 42,
- 41, 43, 33, 44, 87, 46, 40, 44, 13, 33,
- 46, 16, 17, 18, 19, 20, 21, 22, 14, 15,
- 63, 26, 39, 40, 47, 43, 31, 32, 41, 34,
- 14, 15, 75, 3, 117, 41, 3, 47, 3, 35,
- 36, 37, 38, 39, 40, 57, 43, 3, 3, 45,
- 42, 35, 36, 37, 38, 39, 40, 43, 3, 44,
- 3, 45, 14, 15, 45, 77, 78, 79, 80, 81,
- 82, 83, 84, 14, 15, 8, 9, 10, 11, 12,
- 75, 126, 125, 35, 36, 37, 38, 39, 40, 16,
- 17, 18, 19, 20, 21, 22, 37, 38, 39, 40,
- 66, 112, 109, 123, -1, -1, -1, 34
+ 3, 43, 3, 3, 3, 5, 6, 3, 7, 5,
+ 26, 7, 29, 8, 9, 10, 11, 12, 23, 24,
+ 25, 14, 15, 3, 4, 28, 8, 30, 14, 15,
+ 72, 3, 41, 27, 28, 0, 42, 3, 41, 46,
+ 40, 32, 32, 43, 86, 45, 39, 43, 13, 3,
+ 45, 16, 17, 18, 19, 20, 21, 22, 42, 62,
+ 3, 26, 14, 15, 40, 30, 31, 40, 33, 14,
+ 15, 74, 42, 3, 116, 14, 15, 8, 9, 10,
+ 11, 12, 34, 35, 36, 37, 38, 39, 56, 46,
+ 3, 41, 44, 38, 39, 34, 35, 36, 37, 38,
+ 39, 42, 14, 15, 3, 44, 14, 15, 76, 77,
+ 78, 79, 80, 81, 82, 83, 43, 3, 44, 111,
+ 122, 124, 34, 35, 36, 37, 38, 39, 36, 37,
+ 38, 39, 16, 17, 18, 19, 20, 21, 22, 74,
+ 125, 65, -1, -1, 108, -1, -1, -1, -1, 33
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
- 0, 49, 0, 13, 16, 17, 18, 19, 20, 21,
- 22, 31, 32, 34, 50, 51, 52, 53, 55, 57,
- 64, 65, 3, 7, 54, 3, 4, 3, 26, 30,
- 66, 67, 8, 54, 54, 27, 28, 29, 68, 3,
- 5, 6, 41, 44, 46, 71, 76, 79, 80, 82,
- 56, 3, 54, 72, 73, 74, 5, 44, 54, 81,
- 77, 78, 82, 33, 63, 33, 70, 8, 9, 10,
- 11, 12, 46, 75, 42, 43, 81, 14, 15, 35,
- 36, 37, 38, 39, 40, 45, 47, 43, 54, 41,
- 58, 3, 69, 71, 3, 82, 74, 45, 81, 81,
- 81, 81, 81, 81, 81, 81, 82, 59, 43, 47,
- 23, 24, 25, 60, 61, 62, 3, 75, 3, 3,
- 22, 55, 42, 43, 82, 44, 3, 62, 54, 58,
- 45, 3
+ 0, 48, 0, 13, 16, 17, 18, 19, 20, 21,
+ 22, 30, 31, 33, 49, 50, 51, 52, 54, 56,
+ 63, 64, 3, 7, 53, 3, 4, 3, 26, 29,
+ 65, 66, 8, 53, 53, 27, 28, 67, 3, 5,
+ 6, 40, 43, 45, 70, 75, 78, 79, 81, 55,
+ 3, 53, 71, 72, 73, 5, 43, 53, 80, 76,
+ 77, 81, 32, 62, 32, 69, 8, 9, 10, 11,
+ 12, 45, 74, 41, 42, 80, 14, 15, 34, 35,
+ 36, 37, 38, 39, 44, 46, 42, 53, 40, 57,
+ 3, 68, 70, 3, 81, 73, 44, 80, 80, 80,
+ 80, 80, 80, 80, 80, 81, 58, 42, 46, 23,
+ 24, 25, 59, 60, 61, 3, 74, 3, 3, 22,
+ 54, 41, 42, 81, 43, 3, 61, 53, 57, 44,
+ 3
};
#define yyerrok (yyerrstatus = 0)
case 9:
/* Line 1806 of yacc.c */
-#line 164 "config_parser.yy"
+#line 160 "config_parser.yy"
{
context->HandleInclude((yyvsp[(2) - (2)].text), false, yylloc);
free((yyvsp[(2) - (2)].text));
case 10:
/* Line 1806 of yacc.c */
-#line 169 "config_parser.yy"
+#line 165 "config_parser.yy"
{
context->HandleInclude((yyvsp[(2) - (2)].text), true, yylloc);
free((yyvsp[(2) - (2)].text));
case 11:
/* Line 1806 of yacc.c */
-#line 175 "config_parser.yy"
+#line 171 "config_parser.yy"
{
context->HandleLibrary((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
case 12:
/* Line 1806 of yacc.c */
-#line 181 "config_parser.yy"
+#line 177 "config_parser.yy"
{
ScriptVariable::Set((yyvsp[(2) - (4)].text), *(yyvsp[(4) - (4)].variant));
free((yyvsp[(2) - (4)].text));
case 14:
/* Line 1806 of yacc.c */
-#line 189 "config_parser.yy"
+#line 185 "config_parser.yy"
{
(yyval.text) = (yyvsp[(1) - (1)].text);
}
case 15:
/* Line 1806 of yacc.c */
-#line 195 "config_parser.yy"
+#line 191 "config_parser.yy"
{
String name = String((yyvsp[(3) - (3)].text));
free((yyvsp[(3) - (3)].text));
- m_Type = ConfigCompilerContext::GetContext()->GetType(name);
+ m_Type = ConfigType::GetByName(name);
if (!m_Type) {
if ((yyvsp[(1) - (3)].num))
BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'"));
m_Type = boost::make_shared<ConfigType>(name, yylloc);
- ConfigCompilerContext::GetContext()->AddType(m_Type);
+ m_Type->Register();
}
}
break;
case 16:
/* Line 1806 of yacc.c */
-#line 210 "config_parser.yy"
+#line 206 "config_parser.yy"
{
TypeRuleList::Ptr ruleList = *(yyvsp[(6) - (6)].variant);
m_Type->GetRuleList()->AddRules(ruleList);
case 17:
/* Line 1806 of yacc.c */
-#line 224 "config_parser.yy"
+#line 220 "config_parser.yy"
{
(yyval.num) = 0;
}
case 18:
/* Line 1806 of yacc.c */
-#line 228 "config_parser.yy"
+#line 224 "config_parser.yy"
{
(yyval.num) = 1;
}
case 19:
/* Line 1806 of yacc.c */
-#line 234 "config_parser.yy"
+#line 230 "config_parser.yy"
{
m_RuleLists.push(boost::make_shared<TypeRuleList>());
}
case 20:
/* Line 1806 of yacc.c */
-#line 239 "config_parser.yy"
+#line 235 "config_parser.yy"
{
(yyval.variant) = new Value(m_RuleLists.top());
m_RuleLists.pop();
case 26:
/* Line 1806 of yacc.c */
-#line 254 "config_parser.yy"
+#line 250 "config_parser.yy"
{
m_RuleLists.top()->AddRequire((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
case 27:
/* Line 1806 of yacc.c */
-#line 259 "config_parser.yy"
+#line 255 "config_parser.yy"
{
m_RuleLists.top()->SetValidator((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
case 28:
/* Line 1806 of yacc.c */
-#line 264 "config_parser.yy"
+#line 260 "config_parser.yy"
{
TypeRule rule((yyvsp[(2) - (3)].type), String(), (yyvsp[(3) - (3)].text), TypeRuleList::Ptr(), yylloc);
free((yyvsp[(3) - (3)].text));
case 29:
/* Line 1806 of yacc.c */
-#line 271 "config_parser.yy"
+#line 267 "config_parser.yy"
{
TypeRule rule((yyvsp[(2) - (6)].type), (yyvsp[(4) - (6)].text), (yyvsp[(6) - (6)].text), TypeRuleList::Ptr(), yylloc);
free((yyvsp[(4) - (6)].text));
case 30:
/* Line 1806 of yacc.c */
-#line 279 "config_parser.yy"
+#line 275 "config_parser.yy"
{
TypeRule rule((yyvsp[(2) - (4)].type), String(), (yyvsp[(3) - (4)].text), *(yyvsp[(4) - (4)].variant), yylloc);
free((yyvsp[(3) - (4)].text));
case 32:
/* Line 1806 of yacc.c */
-#line 289 "config_parser.yy"
+#line 285 "config_parser.yy"
{
m_Type->SetParent((yyvsp[(2) - (2)].text));
free((yyvsp[(2) - (2)].text));
case 39:
/* Line 1806 of yacc.c */
-#line 302 "config_parser.yy"
+#line 298 "config_parser.yy"
{
(yyval.type) = (yyvsp[(1) - (1)].type);
}
case 40:
/* Line 1806 of yacc.c */
-#line 308 "config_parser.yy"
+#line 304 "config_parser.yy"
{
m_Abstract = false;
- m_Local = false;
}
break;
case 41:
/* Line 1806 of yacc.c */
-#line 313 "config_parser.yy"
+#line 308 "config_parser.yy"
{
ConfigItemBuilder::Ptr item = boost::make_shared<ConfigItemBuilder>(yylloc);
item->SetName((yyvsp[(4) - (6)].text));
free((yyvsp[(4) - (6)].text));
- item->SetUnit(ConfigCompilerContext::GetContext()->GetUnit());
-
if ((yyvsp[(5) - (6)].slist)) {
BOOST_FOREACH(const String& parent, *(yyvsp[(5) - (6)].slist)) {
item->AddParent(parent);
item->AddExpressionList(exprl);
}
- item->SetLocal(m_Local);
item->SetAbstract(m_Abstract);
- ConfigCompilerContext::GetContext()->AddItem(item->Compile());
+ item->Compile()->Register();
item.reset();
}
break;
case 43:
/* Line 1806 of yacc.c */
-#line 355 "config_parser.yy"
+#line 347 "config_parser.yy"
{
m_Abstract = true;
}
case 46:
/* Line 1806 of yacc.c */
-#line 364 "config_parser.yy"
+#line 356 "config_parser.yy"
{
m_Abstract = true;
}
case 47:
/* Line 1806 of yacc.c */
-#line 368 "config_parser.yy"
- {
- m_Local = true;
- }
- break;
-
- case 48:
-
-/* Line 1806 of yacc.c */
-#line 374 "config_parser.yy"
+#line 362 "config_parser.yy"
{
(yyval.slist) = NULL;
}
break;
- case 49:
+ case 48:
/* Line 1806 of yacc.c */
-#line 378 "config_parser.yy"
+#line 366 "config_parser.yy"
{
(yyval.slist) = new std::vector<String>();
(yyval.slist)->push_back((yyvsp[(1) - (1)].text));
}
break;
- case 50:
+ case 49:
/* Line 1806 of yacc.c */
-#line 384 "config_parser.yy"
+#line 372 "config_parser.yy"
{
if ((yyvsp[(1) - (3)].slist))
(yyval.slist) = (yyvsp[(1) - (3)].slist);
}
break;
- case 51:
+ case 50:
/* Line 1806 of yacc.c */
-#line 396 "config_parser.yy"
+#line 384 "config_parser.yy"
{
(yyval.slist) = NULL;
}
break;
- case 52:
+ case 51:
/* Line 1806 of yacc.c */
-#line 400 "config_parser.yy"
+#line 388 "config_parser.yy"
{
(yyval.slist) = (yyvsp[(2) - (2)].slist);
}
break;
- case 53:
+ case 52:
/* Line 1806 of yacc.c */
-#line 406 "config_parser.yy"
+#line 394 "config_parser.yy"
{
(yyval.exprl) = (yyvsp[(2) - (3)].exprl);
}
break;
- case 54:
+ case 53:
/* Line 1806 of yacc.c */
-#line 412 "config_parser.yy"
+#line 400 "config_parser.yy"
{
(yyval.exprl) = (yyvsp[(1) - (1)].exprl);
}
break;
- case 55:
+ case 54:
/* Line 1806 of yacc.c */
-#line 416 "config_parser.yy"
+#line 404 "config_parser.yy"
{
(yyval.exprl) = (yyvsp[(1) - (2)].exprl);
}
break;
- case 56:
+ case 55:
/* Line 1806 of yacc.c */
-#line 421 "config_parser.yy"
+#line 409 "config_parser.yy"
{
(yyval.exprl) = NULL;
}
break;
- case 57:
+ case 56:
/* Line 1806 of yacc.c */
-#line 425 "config_parser.yy"
+#line 413 "config_parser.yy"
{
(yyval.exprl) = new ExpressionList();
(yyval.exprl)->AddExpression(*(yyvsp[(1) - (1)].expr));
}
break;
- case 58:
+ case 57:
/* Line 1806 of yacc.c */
-#line 431 "config_parser.yy"
+#line 419 "config_parser.yy"
{
if ((yyvsp[(1) - (3)].exprl))
(yyval.exprl) = (yyvsp[(1) - (3)].exprl);
}
break;
- case 59:
+ case 58:
/* Line 1806 of yacc.c */
-#line 443 "config_parser.yy"
+#line 431 "config_parser.yy"
{
(yyval.expr) = new Expression((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc);
free((yyvsp[(1) - (3)].text));
}
break;
- case 60:
+ case 59:
/* Line 1806 of yacc.c */
-#line 449 "config_parser.yy"
+#line 437 "config_parser.yy"
{
Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc);
free((yyvsp[(3) - (6)].text));
}
break;
- case 65:
+ case 64:
/* Line 1806 of yacc.c */
-#line 467 "config_parser.yy"
+#line 455 "config_parser.yy"
{
(yyval.op) = (yyvsp[(1) - (1)].op);
}
break;
- case 66:
+ case 65:
/* Line 1806 of yacc.c */
-#line 473 "config_parser.yy"
+#line 461 "config_parser.yy"
{
(yyval.array) = (yyvsp[(2) - (3)].array);
}
break;
- case 67:
+ case 66:
/* Line 1806 of yacc.c */
-#line 479 "config_parser.yy"
+#line 467 "config_parser.yy"
{
(yyval.array) = (yyvsp[(1) - (1)].array);
}
break;
- case 68:
+ case 67:
/* Line 1806 of yacc.c */
-#line 483 "config_parser.yy"
+#line 471 "config_parser.yy"
{
(yyval.array) = (yyvsp[(1) - (2)].array);
}
break;
- case 69:
+ case 68:
/* Line 1806 of yacc.c */
-#line 488 "config_parser.yy"
+#line 476 "config_parser.yy"
{
(yyval.array) = NULL;
}
break;
- case 70:
+ case 69:
/* Line 1806 of yacc.c */
-#line 492 "config_parser.yy"
+#line 480 "config_parser.yy"
{
(yyval.array) = new Array();
}
break;
- case 71:
+ case 70:
/* Line 1806 of yacc.c */
-#line 507 "config_parser.yy"
+#line 495 "config_parser.yy"
{
if ((yyvsp[(1) - (3)].array))
(yyval.array) = (yyvsp[(1) - (3)].array);
}
break;
- case 72:
+ case 71:
/* Line 1806 of yacc.c */
-#line 527 "config_parser.yy"
+#line 515 "config_parser.yy"
{
(yyval.variant) = new Value((yyvsp[(1) - (1)].text));
free((yyvsp[(1) - (1)].text));
}
break;
- case 73:
+ case 72:
/* Line 1806 of yacc.c */
-#line 532 "config_parser.yy"
+#line 520 "config_parser.yy"
{
(yyval.variant) = new Value((yyvsp[(1) - (1)].num));
}
break;
- case 74:
+ case 73:
/* Line 1806 of yacc.c */
-#line 536 "config_parser.yy"
+#line 524 "config_parser.yy"
{
(yyval.variant) = new Value();
}
break;
- case 75:
+ case 74:
/* Line 1806 of yacc.c */
-#line 540 "config_parser.yy"
+#line 528 "config_parser.yy"
{
if ((yyvsp[(1) - (1)].array) == NULL)
(yyvsp[(1) - (1)].array) = new Array();
}
break;
- case 76:
+ case 75:
/* Line 1806 of yacc.c */
-#line 550 "config_parser.yy"
+#line 538 "config_parser.yy"
{
(yyval.num) = (yyvsp[(2) - (3)].num);
}
break;
- case 77:
+ case 76:
/* Line 1806 of yacc.c */
-#line 555 "config_parser.yy"
+#line 543 "config_parser.yy"
{
(yyval.num) = (yyvsp[(1) - (1)].num);
}
break;
- case 78:
+ case 77:
/* Line 1806 of yacc.c */
-#line 559 "config_parser.yy"
+#line 547 "config_parser.yy"
{
(yyval.num) = ScriptVariable::Get((yyvsp[(1) - (1)].text));
free((yyvsp[(1) - (1)].text));
}
break;
- case 79:
+ case 78:
/* Line 1806 of yacc.c */
-#line 564 "config_parser.yy"
+#line 552 "config_parser.yy"
{
(yyval.num) = (yyvsp[(1) - (3)].num) + (yyvsp[(3) - (3)].num);
}
break;
- case 80:
+ case 79:
/* Line 1806 of yacc.c */
-#line 568 "config_parser.yy"
+#line 556 "config_parser.yy"
{
(yyval.num) = (yyvsp[(1) - (3)].num) - (yyvsp[(3) - (3)].num);
}
break;
- case 81:
+ case 80:
/* Line 1806 of yacc.c */
-#line 572 "config_parser.yy"
+#line 560 "config_parser.yy"
{
(yyval.num) = (yyvsp[(1) - (3)].num) * (yyvsp[(3) - (3)].num);
}
break;
- case 82:
+ case 81:
/* Line 1806 of yacc.c */
-#line 576 "config_parser.yy"
+#line 564 "config_parser.yy"
{
(yyval.num) = (yyvsp[(1) - (3)].num) / (yyvsp[(3) - (3)].num);
}
break;
- case 83:
+ case 82:
/* Line 1806 of yacc.c */
-#line 580 "config_parser.yy"
+#line 568 "config_parser.yy"
{
(yyval.num) = (long)(yyvsp[(1) - (3)].num) & (long)(yyvsp[(3) - (3)].num);
}
break;
- case 84:
+ case 83:
/* Line 1806 of yacc.c */
-#line 584 "config_parser.yy"
+#line 572 "config_parser.yy"
{
(yyval.num) = (long)(yyvsp[(1) - (3)].num) | (long)(yyvsp[(3) - (3)].num);
}
break;
- case 85:
+ case 84:
/* Line 1806 of yacc.c */
-#line 588 "config_parser.yy"
+#line 576 "config_parser.yy"
{
(yyval.num) = (long)(yyvsp[(1) - (3)].num) << (long)(yyvsp[(3) - (3)].num);
}
break;
- case 86:
+ case 85:
/* Line 1806 of yacc.c */
-#line 592 "config_parser.yy"
+#line 580 "config_parser.yy"
{
(yyval.num) = (long)(yyvsp[(1) - (3)].num) >> (long)(yyvsp[(3) - (3)].num);
}
break;
- case 87:
+ case 86:
/* Line 1806 of yacc.c */
-#line 596 "config_parser.yy"
+#line 584 "config_parser.yy"
{
(yyval.num) = (yyvsp[(2) - (3)].num);
}
break;
- case 89:
+ case 88:
/* Line 1806 of yacc.c */
-#line 603 "config_parser.yy"
+#line 591 "config_parser.yy"
{
ExpressionList::Ptr exprl = ExpressionList::Ptr((yyvsp[(1) - (1)].exprl));
(yyval.variant) = new Value(exprl);
}
break;
- case 90:
+ case 89:
/* Line 1806 of yacc.c */
-#line 608 "config_parser.yy"
+#line 596 "config_parser.yy"
{
(yyval.variant) = new Value((yyvsp[(1) - (1)].num));
}
/* Line 1806 of yacc.c */
-#line 2404 "../../../lib/config/config_parser.cc"
+#line 2381 "../../../lib/config/config_parser.cc"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
/* Line 2067 of yacc.c */
-#line 612 "config_parser.yy"
+#line 600 "config_parser.yy"
T_ATTRIBUTE = 280,
T_TYPE = 281,
T_ABSTRACT = 282,
- T_LOCAL = 283,
- T_OBJECT = 284,
- T_TEMPLATE = 285,
- T_INCLUDE = 286,
- T_LIBRARY = 287,
- T_INHERITS = 288,
- T_PARTIAL = 289
+ T_OBJECT = 283,
+ T_TEMPLATE = 284,
+ T_INCLUDE = 285,
+ T_LIBRARY = 286,
+ T_INHERITS = 287,
+ T_PARTIAL = 288
};
#endif
/* Tokens. */
#define T_ATTRIBUTE 280
#define T_TYPE 281
#define T_ABSTRACT 282
-#define T_LOCAL 283
-#define T_OBJECT 284
-#define T_TEMPLATE 285
-#define T_INCLUDE 286
-#define T_LIBRARY 287
-#define T_INHERITS 288
-#define T_PARTIAL 289
+#define T_OBJECT 283
+#define T_TEMPLATE 284
+#define T_INCLUDE 285
+#define T_LIBRARY 286
+#define T_INHERITS 287
+#define T_PARTIAL 288
/* Line 2068 of yacc.c */
-#line 183 "../../../lib/config/config_parser.h"
+#line 181 "../../../lib/config/config_parser.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
%token T_ATTRIBUTE "%attribute (T_ATTRIBUTE)"
%token T_TYPE "type (T_TYPE)"
%token T_ABSTRACT "abstract (T_ABSTRACT)"
-%token T_LOCAL "local (T_LOCAL)"
%token T_OBJECT "object (T_OBJECT)"
%token T_TEMPLATE "template (T_TEMPLATE)"
%token T_INCLUDE "include (T_INCLUDE)"
{
std::ostringstream message;
message << *locp << ": " << err;
- ConfigCompilerContext::GetContext()->AddError(false, message.str());
+ ConfigCompilerContext::GetInstance()->AddError(false, message.str());
}
int yyparse(ConfigCompiler *context);
static std::stack<Array::Ptr> m_Arrays;
static bool m_Abstract;
-static bool m_Local;
static std::stack<TypeRuleList::Ptr> m_RuleLists;
static ConfigType::Ptr m_Type;
void ConfigCompiler::Compile(void)
{
- ASSERT(ConfigCompilerContext::GetContext() != NULL);
-
try {
yyparse(this);
} catch (const std::exception& ex) {
- ConfigCompilerContext::GetContext()->AddError(false, boost::diagnostic_information(ex));
+ ConfigCompilerContext::GetInstance()->AddError(false, boost::diagnostic_information(ex));
}
}
String name = String($3);
free($3);
- m_Type = ConfigCompilerContext::GetContext()->GetType(name);
+ m_Type = ConfigType::GetByName(name);
if (!m_Type) {
if ($1)
BOOST_THROW_EXCEPTION(std::invalid_argument("Partial type definition for unknown type '" + name + "'"));
m_Type = boost::make_shared<ConfigType>(name, yylloc);
- ConfigCompilerContext::GetContext()->AddType(m_Type);
+ m_Type->Register();
}
}
type_inherits_specifier typerulelist
object:
{
m_Abstract = false;
- m_Local = false;
}
object_declaration identifier T_STRING object_inherits_specifier expressionlist
{
item->SetName($4);
free($4);
- item->SetUnit(ConfigCompilerContext::GetContext()->GetUnit());
-
if ($5) {
BOOST_FOREACH(const String& parent, *$5) {
item->AddParent(parent);
item->AddExpressionList(exprl);
}
- item->SetLocal(m_Local);
item->SetAbstract(m_Abstract);
- ConfigCompilerContext::GetContext()->AddItem(item->Compile());
+ item->Compile()->Register();
item.reset();
}
;
{
m_Abstract = true;
}
- | T_LOCAL
- {
- m_Local = true;
- }
;
object_inherits_list:
#include "config/configcompilercontext.h"
#include "base/utility.h"
#include "base/logger_fwd.h"
+#include "base/singleton.h"
#include <boost/foreach.hpp>
-using std::ifstream;
-
using namespace icinga;
-ConfigCompilerContext *ConfigCompilerContext::m_Context = NULL;
-
-ConfigCompilerContext::ConfigCompilerContext(void)
- : m_Unit(Utility::NewUniqueID()), m_Flags(0)
-{ }
-
-void ConfigCompilerContext::AddItem(const ConfigItem::Ptr& item)
-{
- Log(LogDebug, "config", "Adding item to compiler context: type=" +
- item->GetType() + "; name=" + item->GetName());
-
- m_Items.push_back(item);
- m_ItemsMap[std::make_pair(item->GetType(), item->GetName())] = item;
-}
-
-ConfigItem::Ptr ConfigCompilerContext::GetItem(const String& type, const String& name) const
-{
- std::map<std::pair<String, String>, ConfigItem::Ptr, pair_string_iless>::const_iterator it;
-
- it = m_ItemsMap.find(std::make_pair(type, name));
-
- if (it == m_ItemsMap.end())
- return ConfigItem::Ptr();
-
- return it->second;
-}
-
-std::vector<ConfigItem::Ptr> ConfigCompilerContext::GetItems(void) const
-{
- return m_Items;
-}
-
-void ConfigCompilerContext::AddType(const ConfigType::Ptr& type)
-{
- m_Types[type->GetName()] = type;
-}
-
-ConfigType::Ptr ConfigCompilerContext::GetType(const String& name) const
-{
- std::map<String, ConfigType::Ptr, string_iless>::const_iterator it;
-
- it = m_Types.find(name);
-
- if (it == m_Types.end())
- return ConfigType::Ptr();
-
- return it->second;
-}
-
void ConfigCompilerContext::AddError(bool warning, const String& message)
{
m_Errors.push_back(ConfigCompilerError(warning, message));
return m_Errors;
}
-void ConfigCompilerContext::SetFlags(int flags)
+void ConfigCompilerContext::Reset(void)
{
- m_Flags = flags;
+ m_Errors.clear();
}
-int ConfigCompilerContext::GetFlags(void) const
+ConfigCompilerContext *ConfigCompilerContext::GetInstance(void)
{
- return m_Flags;
-}
-
-void ConfigCompilerContext::SetContext(ConfigCompilerContext *context)
-{
- ASSERT(m_Context == NULL || context == NULL);
-
- m_Context = context;
-}
-
-ConfigCompilerContext *ConfigCompilerContext::GetContext(void)
-{
- return m_Context;
-}
-
-String ConfigCompilerContext::GetUnit(void) const
-{
- return m_Unit;
-}
-
-void ConfigCompilerContext::LinkItems(void)
-{
- SetContext(this);
-
- Log(LogInformation, "config", "Linking config items...");
-
- BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
- item->Link();
- }
-
- SetContext(NULL);
-}
-
-void ConfigCompilerContext::ValidateItems(void)
-{
- SetContext(this);
-
- Log(LogInformation, "config", "Validating config items...");
-
- BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
- ConfigType::Ptr ctype;
-
- {
- ctype = GetType(item->GetType());
-
- if (!ctype) {
- AddError(true, "No validation type found for object '" + item->GetName() + "' of type '" + item->GetType() + "'");
-
- continue;
- }
- }
-
- ctype->ValidateItem(item);
- }
-
- SetContext(NULL);
-}
-
-void ConfigCompilerContext::ActivateItems(void)
-{
- ASSERT(m_Context == NULL);
-
- Log(LogInformation, "config", "Activating config items in compilation unit '" + m_Unit + "'");
- BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
- item->Register();
- }
-
- BOOST_FOREACH(const ConfigItem::Ptr& item, m_Items) {
- item->Commit();
- }
-}
+ return Singleton<ConfigCompilerContext>::GetInstance();
+}
\ No newline at end of file
namespace icinga
{
-/**
- * @ingroup config
- */
-enum ConfigCompilerFlag
-{
- CompilerStrict = 1, /**< Treat warnings as errors. */
- CompilerLinkExisting = 2 /**< Link objects to existing config items. */
-};
-
struct I2_CONFIG_API ConfigCompilerError
{
bool Warning;
class I2_CONFIG_API ConfigCompilerContext
{
public:
- ConfigCompilerContext(void);
-
- void AddItem(const ConfigItem::Ptr& item);
- ConfigItem::Ptr GetItem(const String& type, const String& name) const;
- std::vector<ConfigItem::Ptr> GetItems(void) const;
-
- void AddType(const ConfigType::Ptr& type);
- ConfigType::Ptr GetType(const String& name) const;
-
void AddError(bool warning, const String& message);
std::vector<ConfigCompilerError> GetErrors(void) const;
- void SetFlags(int flags);
- int GetFlags(void) const;
+ void Reset(void);
- String GetUnit(void) const;
-
- void LinkItems(void);
- void ValidateItems(void);
- void ActivateItems(void);
-
- static void SetContext(ConfigCompilerContext *context);
- static ConfigCompilerContext *GetContext(void);
+ static ConfigCompilerContext *GetInstance(void);
private:
- String m_Unit;
-
- int m_Flags;
-
- std::vector<ConfigItem::Ptr> m_Items;
- std::map<std::pair<String, String>, ConfigItem::Ptr, pair_string_iless> m_ItemsMap;
-
- std::map<String, shared_ptr<ConfigType>, string_iless> m_Types;
-
std::vector<ConfigCompilerError> m_Errors;
-
- static ConfigCompilerContext *m_Context;
};
}
boost::mutex ConfigItem::m_Mutex;
ConfigItem::ItemMap ConfigItem::m_Items;
-boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnCommitted;
-boost::signals2::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
/**
* Constructor for the ConfigItem class.
* @param debuginfo Debug information.
*/
ConfigItem::ConfigItem(const String& type, const String& name,
- const String& unit, bool abstract, const ExpressionList::Ptr& exprl,
+ bool abstract, const ExpressionList::Ptr& exprl,
const std::vector<String>& parents, const DebugInfo& debuginfo)
- : m_Type(type), m_Name(name), m_Unit(unit), m_Abstract(abstract),
+ : m_Type(type), m_Name(name), m_Abstract(abstract),
m_ExpressionList(exprl), m_ParentNames(parents), m_DebugInfo(debuginfo)
{
}
return m_Name;
}
-/**
- * Retrieves the name of the compilation unit this item belongs to.
- *
- * @returns The unit name.
- */
-String ConfigItem::GetUnit(void) const
-{
- return m_Unit;
-}
-
/**
* Checks whether the item is abstract.
*
return m_ExpressionList;
}
-/**
- * Retrieves the list of parents for the configuration item.
- *
- * @returns The list of parents.
- */
-std::vector<ConfigItem::Ptr> ConfigItem::GetParents(void) const
-{
- return m_Parents;
-}
-
void ConfigItem::Link(void)
{
ObjectLock olock(this);
m_LinkedExpressionList = boost::make_shared<ExpressionList>();
- m_Parents.clear();
-
BOOST_FOREACH(const String& name, m_ParentNames) {
- ConfigItem::Ptr parent;
-
- ConfigCompilerContext *context = ConfigCompilerContext::GetContext();
-
- if (context)
- parent = context->GetItem(m_Type, name);
-
- /* ignore already active objects while we're in the compiler
- * context and linking to existing items is disabled. */
- if (!parent && (!context || (context->GetFlags() & CompilerLinkExisting)))
- parent = ConfigItem::GetObject(m_Type, name);
+ ConfigItem::Ptr parent = ConfigItem::GetObject(m_Type, name);
if (!parent) {
std::ostringstream message;
ExpressionList::Ptr pexprl = parent->GetLinkedExpressionList();
m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, pexprl, m_DebugInfo));
-
- m_Parents.push_back(parent);
}
m_LinkedExpressionList->AddExpression(Expression("", OperatorExecute, m_ExpressionList, m_DebugInfo));
if (!dtype)
BOOST_THROW_EXCEPTION(std::runtime_error("Type '" + GetType() + "' does not exist."));
- /* Try to find an existing item with the same type and name. */
- std::pair<String, String> ikey = std::make_pair(GetType(), GetName());
- ConfigItem::Ptr oldItem;
+ if (m_DynamicObject.lock() || dtype->GetObject(m_Name))
+ BOOST_THROW_EXCEPTION(std::runtime_error("An object with type '" + GetType() + "' and name '" + GetName() + "' already exists."));
- {
- boost::mutex::scoped_lock lock(m_Mutex);
-
- ItemMap::iterator it = m_Items.find(ikey);
-
- if (it != m_Items.end())
- oldItem = it->second;
- }
-
- std::set<ConfigItem::WeakPtr> children;
-
- if (oldItem) {
- ObjectLock olock(oldItem);
-
- /* Unregister the old item from its parents. */
- oldItem->UnregisterFromParents();
-
- /* Steal the old item's children. */
- children = oldItem->m_ChildObjects;
- }
-
- {
- ObjectLock olock(this);
- m_ChildObjects = children;
- }
-
- ConfigItem::Ptr self = GetSelf();
-
- {
- boost::mutex::scoped_lock lock(m_Mutex);
-
- /* Register this item. */
- m_Items[ikey] = self;
- }
-
- DynamicObject::Ptr dobj = m_DynamicObject.lock();
-
- if (!dobj)
- dobj = dtype->GetObject(m_Name);
-
- /* Register this item with its parents. */
- BOOST_FOREACH(const ConfigItem::Ptr& parent, m_Parents) {
- parent->m_ChildObjects.insert(self);
- }
+ if (IsAbstract())
+ return DynamicObject::Ptr();
/* Create a fake update in the format that
- * DynamicObject::ApplyUpdate expects. */
+ * DynamicObject::Deserialize expects. */
Dictionary::Ptr attrs = boost::make_shared<Dictionary>();
- double tx = DynamicObject::GetCurrentTx();
-
Link();
Dictionary::Ptr properties = boost::make_shared<Dictionary>();
String key;
Value data;
BOOST_FOREACH(boost::tie(key, data), properties) {
- Dictionary::Ptr attr = boost::make_shared<Dictionary>();
- attr->Set("data", data);
- attr->Set("type", Attribute_Config);
- attr->Set("tx", tx);
- attr->Seal();
-
- attrs->Set(key, attr);
+ attrs->Set(key, data);
}
}
attrs->Seal();
- Dictionary::Ptr update = boost::make_shared<Dictionary>();
- update->Set("attrs", attrs);
- update->Set("configTx", DynamicObject::GetCurrentTx());
- update->Seal();
-
- /* Update or create the object and apply the configuration settings. */
- bool was_null = false;
-
- if (!dobj) {
- if (!IsAbstract())
- dobj = dtype->CreateObject(update);
-
- was_null = true;
- }
-
- if (!was_null)
- dobj->ApplyUpdate(update, Attribute_Config);
-
- {
- ObjectLock olock(this);
-
- m_DynamicObject = dobj;
- }
-
- if (dobj) {
- if (IsAbstract())
- dobj->Unregister();
- else
- dobj->Register();
- }
-
- /* notify our children of the update */
- BOOST_FOREACH(const ConfigItem::WeakPtr wchild, children) {
- const ConfigItem::Ptr& child = wchild.lock();
-
- if (!child)
- continue;
-
- child->OnParentCommitted();
- }
-
- OnCommitted(self);
+ DynamicObject::Ptr dobj = dtype->CreateObject(attrs);
+ dobj->Register();
return dobj;
}
}
}
-/**
- * Unregisters the configuration item.
- */
-void ConfigItem::Unregister(void)
-{
- ASSERT(!OwnsLock());
-
- DynamicObject::Ptr dobj = m_DynamicObject.lock();
-
- if (dobj)
- dobj->Unregister();
-
- {
- ObjectLock olock(this);
-
- ConfigItem::ItemMap::iterator it;
- it = m_Items.find(std::make_pair(m_Type, m_Name));
-
- if (it != m_Items.end())
- m_Items.erase(it);
-
- UnregisterFromParents();
- }
-
- OnRemoved(GetSelf());
-}
-
-void ConfigItem::UnregisterFromParents(void)
-{
- ASSERT(OwnsLock());
-
- BOOST_FOREACH(const ConfigItem::Ptr& parent, m_Parents) {
- parent->m_ChildObjects.erase(GetSelf());
- }
-}
-
-/*
- * Notifies an item that one of its parents has been committed.
- */
-void ConfigItem::OnParentCommitted(void)
-{
- ASSERT(!OwnsLock());
-
- ConfigItem::Ptr self = GetSelf();
-
- if (GetObject(m_Type, m_Name) != self)
- return;
-
- Commit();
-}
-
/**
* Retrieves the DynamicObject that belongs to the configuration item.
*
return ConfigItem::Ptr();
}
-/**
- * Dumps the config item to the specified stream using Icinga's config item
- * syntax.
- *
- * @param fp The stream.
- */
-void ConfigItem::Dump(std::ostream& fp) const
+void ConfigItem::LinkItems(void)
{
- ObjectLock olock(this);
+ Log(LogInformation, "config", "Linking config items...");
- fp << "object \"" << m_Type << "\" \"" << m_Name << "\"";
+ ConfigItem::Ptr item;
+ BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
+ item->Link();
+ }
+}
+
+void ConfigItem::ValidateItems(void)
+{
+ Log(LogInformation, "config", "Validating config items...");
- if (m_Parents.size() > 0) {
- fp << " inherits";
+ ConfigItem::Ptr item;
+ BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
+ ConfigType::Ptr ctype = ConfigType::GetByName(item->GetType());
- bool first = true;
- BOOST_FOREACH(const String& name, m_ParentNames) {
- if (!first)
- fp << ",";
- else
- first = false;
+ if (!ctype) {
+ ConfigCompilerContext::GetInstance()->AddError(true, "No validation type found for object '" + item->GetName() + "' of type '" + item->GetType() + "'");
- fp << " \"" << name << "\"";
+ continue;
}
- }
- fp << " {" << "\n";
- m_ExpressionList->Dump(fp, 1);
- fp << "}" << "\n";
+ ctype->ValidateItem(item);
+ }
}
-void ConfigItem::UnloadUnit(const String& unit)
+void ConfigItem::ActivateItems(void)
{
- std::vector<ConfigItem::Ptr> obsoleteItems;
+ Log(LogInformation, "config", "Activating config items");
- {
- boost::mutex::scoped_lock lock(m_Mutex);
+ std::vector<DynamicObject::Ptr> objects;
- Log(LogInformation, "config", "Unloading config items from compilation unit '" + unit + "'");
+ ConfigItem::Ptr item;
+ BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
+ DynamicObject::Ptr object = item->Commit();
- ConfigItem::Ptr item;
- BOOST_FOREACH(boost::tie(boost::tuples::ignore, item), m_Items) {
- ObjectLock olock(item);
+ if (object)
+ objects.push_back(object);
+ }
- if (item->m_Unit != unit)
- continue;
+ BOOST_FOREACH(const DynamicObject::Ptr& object, objects) {
+ Log(LogDebug, "config", "Activating object '" + object->GetName() + "' of type '" + object->GetType()->GetName() + "'");
+ object->Start();
- obsoleteItems.push_back(item);
- }
+ ASSERT(object->IsActive());
}
+}
- BOOST_FOREACH(const ConfigItem::Ptr& item, obsoleteItems) {
- item->Unregister();
- }
+void ConfigItem::DiscardItems(void)
+{
+ m_Items.clear();
}
public:
DECLARE_PTR_TYPEDEFS(ConfigItem);
- ConfigItem(const String& type, const String& name, const String& unit,
- bool abstract, const ExpressionList::Ptr& exprl, const std::vector<String>& parents,
+ ConfigItem(const String& type, const String& name, bool abstract,
+ const ExpressionList::Ptr& exprl, const std::vector<String>& parents,
const DebugInfo& debuginfo);
String GetType(void) const;
String GetName(void) const;
- String GetUnit(void) const;
bool IsAbstract(void) const;
std::vector<ConfigItem::Ptr> GetParents(void) const;
DynamicObject::Ptr Commit(void);
void Register(void);
- void Unregister(void);
-
- void Dump(std::ostream& fp) const;
DynamicObject::Ptr GetDynamicObject(void) const;
static ConfigItem::Ptr GetObject(const String& type,
const String& name);
- static void UnloadUnit(const String& unit);
-
- static boost::signals2::signal<void (const ConfigItem::Ptr&)> OnCommitted;
- static boost::signals2::signal<void (const ConfigItem::Ptr&)> OnRemoved;
+ static void LinkItems(void);
+ static void ValidateItems(void);
+ static void ActivateItems(void);
+ static void DiscardItems(void);
private:
ExpressionList::Ptr GetExpressionList(void) const;
- void UnregisterFromParents(void);
-
- void OnParentCommitted(void);
-
String m_Type; /**< The object type. */
String m_Name; /**< The name. */
- String m_Unit; /**< The compilation unit. */
bool m_Abstract; /**< Whether this is a template. */
ExpressionList::Ptr m_ExpressionList;
std::vector<String> m_ParentNames; /**< The names of parent configuration
items. */
- std::vector<ConfigItem::Ptr> m_Parents;
DebugInfo m_DebugInfo; /**< Debug information. */
ExpressionList::Ptr m_LinkedExpressionList;
DynamicObject::WeakPtr m_DynamicObject; /**< The instantiated version
* of this configuration item */
- std::set<ConfigItem::WeakPtr> m_ChildObjects; /**< Instantiated items
- * that inherit from this item */
static boost::mutex m_Mutex;
using namespace icinga;
ConfigItemBuilder::ConfigItemBuilder(void)
- : m_Local(false), m_Abstract(false),
- m_ExpressionList(boost::make_shared<ExpressionList>())
+ : m_Abstract(false), m_ExpressionList(boost::make_shared<ExpressionList>())
{
m_DebugInfo.FirstLine = 0;
m_DebugInfo.FirstColumn = 0;
}
ConfigItemBuilder::ConfigItemBuilder(const DebugInfo& debugInfo)
- : m_Local(false), m_Abstract(false),
- m_ExpressionList(boost::make_shared<ExpressionList>())
+ : m_Abstract(false), m_ExpressionList(boost::make_shared<ExpressionList>())
{
m_DebugInfo = debugInfo;
}
m_Name = name;
}
-void ConfigItemBuilder::SetUnit(const String& unit)
-{
- m_Unit = unit;
-}
-
-void ConfigItemBuilder::SetLocal(bool local)
-{
- m_Local = local;
-}
-
void ConfigItemBuilder::SetAbstract(bool abstract)
{
m_Abstract = abstract;
Expression nameExpr("__name", OperatorSet, m_Name, m_DebugInfo);
exprl->AddExpression(nameExpr);
- Expression localExpr("__local", OperatorSet, m_Local, m_DebugInfo);
- exprl->AddExpression(localExpr);
-
- return boost::make_shared<ConfigItem>(m_Type, m_Name, m_Unit, m_Abstract, exprl, m_Parents,
- m_DebugInfo);
+ return boost::make_shared<ConfigItem>(m_Type, m_Name, m_Abstract, exprl,
+ m_Parents, m_DebugInfo);
}
void SetType(const String& type);
void SetName(const String& name);
- void SetUnit(const String& unit);
- void SetLocal(bool local);
void SetAbstract(bool abstract);
void AddParent(const String& parent);
private:
String m_Type; /**< The object type. */
String m_Name; /**< The name. */
- String m_Unit; /**< The compilation unit. */
- bool m_Local; /**< Whether the item is local. */
bool m_Abstract; /**< Whether the item is abstract. */
std::vector<String> m_Parents; /**< The names of parent configuration
items. */
ConfigType::Ptr parent;
if (item->m_Parent.IsEmpty()) {
if (item->GetName() != "DynamicObject")
- parent = ConfigCompilerContext::GetContext()->GetType("DynamicObject");
+ parent = ConfigType::GetByName("DynamicObject");
} else {
- parent = ConfigCompilerContext::GetContext()->GetType(item->m_Parent);
+ parent = ConfigType::GetByName(item->m_Parent);
}
if (parent) {
Value value = dictionary->Get(require);
if (value.IsEmpty()) {
- ConfigCompilerContext::GetContext()->AddError(false,
+ ConfigCompilerContext::GetInstance()->AddError(false,
"Required attribute is missing: " + LocationToString(locations));
}
}
if (overallResult == ValidationUnknownField)
- ConfigCompilerContext::GetContext()->AddError(true, "Unknown attribute: " + LocationToString(locations));
+ ConfigCompilerContext::GetInstance()->AddError(true, "Unknown attribute: " + LocationToString(locations));
else if (overallResult == ValidationInvalidType) {
String message = "Invalid value for attribute: " + LocationToString(locations);
if (!hint.IsEmpty())
message += ": " + hint;
- ConfigCompilerContext::GetContext()->AddError(false, message);
+ ConfigCompilerContext::GetInstance()->AddError(false, message);
}
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
locations.push_back("Attribute '" + require + "'");
if (array->GetLength() < index) {
- ConfigCompilerContext::GetContext()->AddError(false,
+ ConfigCompilerContext::GetInstance()->AddError(false,
"Required array index is missing: " + LocationToString(locations));
}
}
if (overallResult == ValidationUnknownField)
- ConfigCompilerContext::GetContext()->AddError(true, "Unknown attribute: " + LocationToString(locations));
+ ConfigCompilerContext::GetInstance()->AddError(true, "Unknown attribute: " + LocationToString(locations));
else if (overallResult == ValidationInvalidType) {
String message = "Invalid value for array index: " + LocationToString(locations);
if (!hint.IsEmpty())
message += ": " + hint;
- ConfigCompilerContext::GetContext()->AddError(false, message);
+ ConfigCompilerContext::GetInstance()->AddError(false, message);
}
if (!subRuleLists.empty() && value.IsObjectType<Dictionary>())
locations.pop_back();
}
}
+
+void ConfigType::Register(void)
+{
+ Registry<ConfigType::Ptr>::GetInstance()->Register(GetName(), GetSelf());
+}
+
+ConfigType::Ptr ConfigType::GetByName(const String& name)
+{
+ return Registry<ConfigType::Ptr>::GetInstance()->GetItem(name);
+}
+
+Registry<ConfigType::Ptr>::ItemMap ConfigType::GetTypes(void)
+{
+ return Registry<ConfigType::Ptr>::GetInstance()->GetItems();
+}
+
+void ConfigType::DiscardTypes(void)
+{
+ Registry<ConfigType::Ptr>::GetInstance()->Clear();
+}
#include "config/typerulelist.h"\r
#include "config/configitem.h"\r
#include "base/array.h"\r
+#include "base/registry.h"\r
\r
namespace icinga\r
{\r
\r
void ValidateItem(const ConfigItem::Ptr& object);\r
\r
+ void Register(void);\r
+ static ConfigType::Ptr GetByName(const String& name);\r
+ static Registry<ConfigType::Ptr>::ItemMap GetTypes(void);\r
+ static void DiscardTypes(void);\r
+\r
private:\r
String m_Name; /**< The type name. */\r
String m_Parent; /**< The parent type. */\r
dictionary->Set(m_Key, newValue);
}
-void Expression::DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict)
-{
- ExpressionList::Ptr valueExprl;
- Dictionary::Ptr valueDict;
- if (value.IsObjectType<ExpressionList>()) {
- if (!inlineDict)
- fp << "{ " << "\n";
-
- static_cast<ExpressionList::Ptr>(value)->Dump(fp, indent);
-
- if (!inlineDict) {
- for (int i = 0; i < indent - 1; i++)
- fp << "\t";
-
- fp << "}";
- }
-
- return;
- }
-
- if (value.IsObjectType<Dictionary>()) {
- if (!inlineDict)
- fp << "{ " << "\n";
-
- String k;
- Value v;
- BOOST_FOREACH(boost::tie(k, v), static_cast<Dictionary::Ptr>(value)) {
- for (int i = 0; i < indent; i++)
- fp << "\t";
-
- fp << "\"" << k << "\" = ";
- DumpValue(fp, indent, v);
- fp << "," << "\n";
-
- fp << "}";
- }
-
- if (!inlineDict)
- fp << "}";
-
- return;
- }
-
- if (value.IsScalar()) {
- fp << "\"" << static_cast<String>(value) << "\"";
- return;
- }
-
- BOOST_THROW_EXCEPTION(std::runtime_error("Encountered unknown type while dumping value."));
-}
-
-void Expression::Dump(std::ostream& fp, int indent) const
-{
- if (m_Operator == OperatorExecute) {
- DumpValue(fp, indent, m_Value, true);
- return;
- }
-
- for (int i = 0; i < indent; i++)
- fp << "\t";
-
- fp << "\"" << m_Key << "\" ";
-
- switch (m_Operator) {
- case OperatorSet:
- fp << "=";
- break;
- case OperatorPlus:
- fp << "+=";
- break;
- default:
- BOOST_THROW_EXCEPTION(std::runtime_error("Not yet implemented."));
- }
-
- fp << " ";
-
- DumpValue(fp, indent + 1, m_Value);
-
- fp << ", " << "\n";
-}
-
void Expression::ExtractPath(const std::vector<String>& path, const ExpressionList::Ptr& result) const
{
ASSERT(!path.empty());
const DebugInfo& debuginfo);
void Execute(const Dictionary::Ptr& dictionary) const;
- void Dump(std::ostream& fp, int indent = 0) const;
void ExtractPath(const std::vector<String>& path, const shared_ptr<ExpressionList>& result) const;
void ExtractFiltered(const std::set<String, string_iless>& keys, const shared_ptr<ExpressionList>& result) const;
ExpressionOperator m_Operator;
Value m_Value;
DebugInfo m_DebugInfo;
-
- static void DumpValue(std::ostream& fp, int indent, const Value& value, bool inlineDict = false);
};
}
}
}
-/**
- * Dumps the expression list to the specified stream.
- *
- * @param fp The stream.
- * @param indent The indentation level.
- */
-void ExpressionList::Dump(std::ostream& fp, int indent) const
-{
- BOOST_FOREACH(const Expression& expression, m_Expressions) {
- expression.Dump(fp, indent);
- }
-}
-
void ExpressionList::ExtractPath(const std::vector<String>& path, const ExpressionList::Ptr& result) const
{
BOOST_FOREACH(const Expression& expression, m_Expressions) {
void AddExpression(const Expression& expression);
void Execute(const Dictionary::Ptr& dictionary) const;
- void Dump(std::ostream& fp, int indent) const;
size_t GetLength(void) const;
bool TypeRule::MatchValue(const Value& value, String *hint) const
{
- ConfigCompilerContext *context;
ConfigItem::Ptr item;
if (value.IsEmpty())
if (!value.IsScalar())
return false;
- context = ConfigCompilerContext::GetContext();
-
- if (context)
- item = context->GetItem(m_NameType, value);
-
- if (!item && (!context || (context->GetFlags() & CompilerLinkExisting)))
- item = ConfigItem::GetObject(m_NameType, value);
+ item = ConfigItem::GetObject(m_NameType, value);
if (!item) {
*hint = "Object '" + value + "' of type '" + m_NameType + "' does not exist.";
api.h \
checkcommand.cpp \
checkcommand.h \
- checkresultmessage.cpp \
- checkresultmessage.h \
cib.cpp \
cib.h \
command.cpp \
command.h \
compatutility.cpp \
compatutility.h \
- downtimemessage.cpp \
- downtimemessage.h \
eventcommand.cpp \
eventcommand.h \
externalcommandprocessor.cpp \
externalcommandprocessor.h \
- flappingmessage.cpp \
- flappingmessage.h \
host.cpp \
hostgroup.cpp \
hostgroup.h \
notification.h \
notificationcommand.cpp \
notificationcommand.h \
- notificationmessage.cpp \
- notificationmessage.h \
- notificationrequestmessage.cpp \
- notificationrequestmessage.h \
nullchecktask.cpp \
nullchecktask.h \
nulleventtask.cpp \
REGISTER_TYPE(CheckCommand);
-/**
- * Constructor for the CheckCommand class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-CheckCommand::CheckCommand(const Dictionary::Ptr& serializedUpdate)
- : Command(serializedUpdate)
-{ }
-
-CheckCommand::Ptr CheckCommand::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("CheckCommand", name);
-
- return dynamic_pointer_cast<CheckCommand>(configObject);
-}
-
Dictionary::Ptr CheckCommand::Execute(const Service::Ptr& service)
{
std::vector<Value> arguments;
{
public:
DECLARE_PTR_TYPEDEFS(CheckCommand);
-
- explicit CheckCommand(const Dictionary::Ptr& serializedUpdate);
-
- static CheckCommand::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(CheckCommand);
virtual Dictionary::Ptr Execute(const Service::Ptr& service);
};
+++ /dev/null
-/******************************************************************************
- * 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 "icinga/checkresultmessage.h"
-
-using namespace icinga;
-
-String CheckResultMessage::GetService(void) const
-{
- String service;
- Get("service", &service);
- return service;
-}
-
-void CheckResultMessage::SetService(const String& service)
-{
- Set("service", service);
-}
-
-Dictionary::Ptr CheckResultMessage::GetCheckResult(void) const
-{
- Dictionary::Ptr cr;
- Get("check_result", &cr);
- return cr;
-}
-
-void CheckResultMessage::SetCheckResult(const Dictionary::Ptr& result)
-{
- Set("check_result", result);
-}
+++ /dev/null
-/******************************************************************************
- * 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 CHECKRESULTMESSAGE_H
-#define CHECKRESULTMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A state change message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API CheckResultMessage : public MessagePart
-{
-public:
- CheckResultMessage(void) : MessagePart() { }
- explicit CheckResultMessage(const MessagePart& message) : MessagePart(message) { }
-
- String GetService(void) const;
- void SetService(const String& service);
-
- Dictionary::Ptr GetCheckResult(void) const;
- void SetCheckResult(const Dictionary::Ptr& result);
-};
-
-}
-
-#endif /* CHECKRESULTMESSAGE_H */
using namespace icinga;
-/**
- * Constructor for the Command class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-Command::Command(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
+Value Command::GetCommandLine(void) const
+{
+ return m_CommandLine;
+}
+
+double Command::GetTimeout(void) const
{
- RegisterAttribute("macros", Attribute_Config, &m_Macros);
- RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
+ if (m_Timeout.IsEmpty())
+ return 300;
+ else
+ return m_Timeout;
}
Dictionary::Ptr Command::GetMacros(void) const
return m_ExportMacros;
}
-bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool Command::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
{
Dictionary::Ptr macros = GetMacros();
return false;
}
-Value Command::GetCommandLine(void) const
+void Command::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("command", m_CommandLine);
+ bag->Set("timeout", m_Timeout);
+ bag->Set("macros", m_Macros);
+ bag->Set("export_macros", m_ExportMacros);
+ }
+}
+
+void Command::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
{
- return Get("command");
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_CommandLine = bag->Get("command");
+ m_Timeout = bag->Get("timeout");
+ m_Macros = bag->Get("macros");
+ m_Macros = bag->Get("macros");
+ m_ExportMacros = bag->Get("export_macros");
+ }
}
public:
DECLARE_PTR_TYPEDEFS(Command);
- explicit Command(const Dictionary::Ptr& serializedUpdate);
-
//virtual Dictionary::Ptr Execute(const Object::Ptr& context) = 0;
+ Value GetCommandLine(void) const;
+ double GetTimeout(void) const;
+
Dictionary::Ptr GetMacros(void) const;
Array::Ptr GetExportMacros(void) const;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
- Value GetCommandLine(void) const;
+protected:
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<Dictionary::Ptr> m_Macros;
- Attribute<Array::Ptr> m_ExportMacros;
+ Value m_CommandLine;
+ Value m_Timeout;
+ Dictionary::Ptr m_Macros;
+ Array::Ptr m_ExportMacros;
};
}
+++ /dev/null
-/******************************************************************************
- * 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 "icinga/downtimemessage.h"
-
-using namespace icinga;
-
-String DowntimeMessage::GetService(void) const
-{
- String service;
- Get("service", &service);
- return service;
-}
-
-void DowntimeMessage::SetService(const String& service)
-{
- Set("service", service);
-}
-
-DowntimeState DowntimeMessage::GetState(void) const
-{
- long state;
- Get("state", &state);
- return static_cast<DowntimeState>(state);
-}
-
-void DowntimeMessage::SetState(DowntimeState state)
-{
- Set("state", state);
-}
+++ /dev/null
-/******************************************************************************
- * 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 DOWNTIMEMESSAGE_H
-#define DOWNTIMEMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/service.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A downtime message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API DowntimeMessage : public MessagePart
-{
-public:
- DowntimeMessage(void) : MessagePart() { }
- explicit DowntimeMessage(const MessagePart& message) : MessagePart(message) { }
-
- String GetService(void) const;
- void SetService(const String& service);
-
- DowntimeState GetState(void) const;
- void SetState(DowntimeState state);
-};
-
-}
-
-#endif /* DOWNTIMEMESSAGE_H */
REGISTER_TYPE(EventCommand);
-/**
- * Constructor for the EventCommand class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-EventCommand::EventCommand(const Dictionary::Ptr& serializedUpdate)
- : Command(serializedUpdate)
-{ }
-
-EventCommand::Ptr EventCommand::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("EventCommand", name);
-
- return dynamic_pointer_cast<EventCommand>(configObject);
-}
-
void EventCommand::Execute(const Service::Ptr& service)
{
std::vector<Value> arguments;
{
public:
DECLARE_PTR_TYPEDEFS(EventCommand);
-
- explicit EventCommand(const Dictionary::Ptr& serializedUpdate);
-
- static EventCommand::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(EventCommand);
virtual void Execute(const Service::Ptr& context);
};
#include "icinga/hostgroup.h"
#include "icinga/servicegroup.h"
#include "icinga/pluginchecktask.h"
-#include "icinga/flappingmessage.h"
#include "base/convert.h"
#include "base/logger_fwd.h"
#include "base/objectlock.h"
#include "base/application.h"
#include "base/utility.h"
-#include "remoting/endpointmanager.h"
#include <fstream>
#include <boost/algorithm/string/classification.hpp>
#include <boost/foreach.hpp>
if (options & 2) {
ObjectLock olock(service);
service->SetForceNextNotification(true);
- service->Flush();
}
- service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
+ Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[2], arguments[3]);
}
}
if (options & 2) {
ObjectLock olock(service);
service->SetForceNextNotification(true);
- service->Flush();
}
- service->RequestNotifications(NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]);
+ Service::OnNotificationsRequested(service, NotificationCustom, service->GetLastCheckResult(), arguments[3], arguments[4]);
}
void ExternalCommandProcessor::DelayHostNotification(double, const std::vector<String>& arguments)
ObjectLock olock(service);
service->SetEnableFlapping(false);
-
- RequestMessage rm;
- rm.SetMethod("icinga::Flapping");
-
- FlappingMessage params;
- params.SetService(service->GetName());
- params.SetState(FlappingDisabled);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
}
}
+++ /dev/null
-/******************************************************************************
- * 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 "icinga/flappingmessage.h"
-
-using namespace icinga;
-
-String FlappingMessage::GetService(void) const
-{
- String service;
- Get("service", &service);
- return service;
-}
-
-void FlappingMessage::SetService(const String& service)
-{
- Set("service", service);
-}
-
-FlappingState FlappingMessage::GetState(void) const
-{
- long state;
- Get("state", &state);
- return static_cast<FlappingState>(state);
-}
-
-void FlappingMessage::SetState(FlappingState state)
-{
- Set("state", state);
-}
+++ /dev/null
-/******************************************************************************
- * 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 FLAPPINGMESSAGE_H
-#define FLAPPINGMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/service.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A downtime message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API FlappingMessage : public MessagePart
-{
-public:
- FlappingMessage(void) : MessagePart() { }
- explicit FlappingMessage(const MessagePart& message) : MessagePart(message) { }
-
- String GetService(void) const;
- void SetService(const String& service);
-
- FlappingState GetState(void) const;
- void SetState(FlappingState state);
-};
-
-}
-
-#endif /* FLAPPINGMESSAGE_H */
using namespace icinga;
-static boost::mutex l_ServiceMutex;
-static std::map<String, std::map<String, Service::WeakPtr> > l_ServicesCache;
-static bool l_ServicesCacheNeedsUpdate = false;
-static Timer::Ptr l_ServicesCacheTimer;
-
REGISTER_SCRIPTFUNCTION(ValidateServiceDictionary, &Host::ValidateServiceDictionary);
REGISTER_TYPE(Host);
-Host::Host(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
+void Host::Start(void)
{
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
- RegisterAttribute("hostgroups", Attribute_Config, &m_HostGroups);
- RegisterAttribute("macros", Attribute_Config, &m_Macros);
- RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
- RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
- RegisterAttribute("hostcheck", Attribute_Config, &m_HostCheck);
+ DynamicObject::Start();
-}
+ ASSERT(!OwnsLock());
-Host::~Host(void)
-{
- HostGroup::InvalidateMembersCache();
+ Array::Ptr groups = GetGroups();
+
+ if (groups) {
+ BOOST_FOREACH(const String& name, groups) {
+ HostGroup::Ptr hg = HostGroup::GetByName(name);
- if (m_SlaveServices) {
- ConfigItem::Ptr service;
- BOOST_FOREACH(boost::tie(boost::tuples::ignore, service), m_SlaveServices) {
- service->Unregister();
+ if (hg)
+ hg->AddMember(GetSelf());
}
}
+
+ UpdateSlaveServices();
}
-void Host::OnRegistrationCompleted(void)
+void Host::Stop(void)
{
- ASSERT(!OwnsLock());
+ DynamicObject::Stop();
- DynamicObject::OnRegistrationCompleted();
+ Array::Ptr groups = GetGroups();
- Host::InvalidateServicesCache();
- UpdateSlaveServices();
+ if (groups) {
+ BOOST_FOREACH(const String& name, groups) {
+ HostGroup::Ptr hg = HostGroup::GetByName(name);
+
+ if (hg)
+ hg->RemoveMember(GetSelf());
+ }
+ }
+
+ // TODO: unregister slave services/notifications?
}
String Host::GetDisplayName(void) const
return GetName();
}
-Host::Ptr Host::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("Host", name);
-
- return dynamic_pointer_cast<Host>(configObject);
-}
-
Array::Ptr Host::GetGroups(void) const
{
return m_HostGroups;
return m_HostCheck;
}
+Dictionary::Ptr Host::GetNotificationDescriptions(void) const
+{
+ return m_NotificationDescriptions;
+}
+
bool Host::IsReachable(void) const
{
ASSERT(!OwnsLock());
if (!item)
return;
- Dictionary::Ptr oldServices = m_SlaveServices;
- Dictionary::Ptr serviceDescs = Get("services");
-
- Dictionary::Ptr newServices = boost::make_shared<Dictionary>();
+ if (!m_ServiceDescriptions)
+ return;
- if (serviceDescs) {
- ObjectLock olock(serviceDescs);
- String svcname;
- Value svcdesc;
- BOOST_FOREACH(boost::tie(svcname, svcdesc), serviceDescs) {
- if (svcdesc.IsScalar())
- svcname = svcdesc;
+ ObjectLock olock(m_ServiceDescriptions);
+ String svcname;
+ Value svcdesc;
+ BOOST_FOREACH(boost::tie(svcname, svcdesc), m_ServiceDescriptions) {
+ if (svcdesc.IsScalar())
+ svcname = svcdesc;
- std::ostringstream namebuf;
- namebuf << GetName() << ":" << svcname;
- String name = namebuf.str();
+ std::ostringstream namebuf;
+ namebuf << 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, GetName());
- builder->AddExpression("display_name", OperatorSet, svcname);
- builder->AddExpression("short_name", OperatorSet, svcname);
+ ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
+ builder->SetType("Service");
+ builder->SetName(name);
+ builder->AddExpression("host_name", OperatorSet, GetName());
+ builder->AddExpression("display_name", OperatorSet, svcname);
+ builder->AddExpression("short_name", OperatorSet, svcname);
- if (!svcdesc.IsObjectType<Dictionary>())
- BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
+ if (!svcdesc.IsObjectType<Dictionary>())
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Service description must be either a string or a dictionary."));
- Dictionary::Ptr service = svcdesc;
+ Dictionary::Ptr service = svcdesc;
- Array::Ptr templates = service->Get("templates");
+ Array::Ptr templates = service->Get("templates");
- if (templates) {
- ObjectLock olock(templates);
+ if (templates) {
+ ObjectLock olock(templates);
- BOOST_FOREACH(const Value& tmpl, templates) {
- builder->AddParent(tmpl);
- }
+ BOOST_FOREACH(const Value& tmpl, templates) {
+ builder->AddParent(tmpl);
}
-
- /* Clone attributes from the host object. */
- std::set<String, string_iless> keys;
- keys.insert("check_interval");
- keys.insert("retry_interval");
- keys.insert("servicegroups");
- keys.insert("checkers");
- keys.insert("notification_interval");
- keys.insert("notification_type_filter");
- keys.insert("notification_state_filter");
- keys.insert("check_period");
- keys.insert("servicedependencies");
- keys.insert("hostdependencies");
- keys.insert("export_macros");
- keys.insert("macros");
- keys.insert("custom");
-
- ExpressionList::Ptr host_exprl = boost::make_shared<ExpressionList>();
- item->GetLinkedExpressionList()->ExtractFiltered(keys, host_exprl);
- builder->AddExpressionList(host_exprl);
-
- /* Clone attributes from the service expression list. */
- std::vector<String> path;
- path.push_back("services");
- path.push_back(svcname);
-
- ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
- item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl);
- builder->AddExpressionList(svc_exprl);
-
- ConfigItem::Ptr serviceItem = builder->Compile();
- DynamicObject::Ptr dobj = serviceItem->Commit();
-
- newServices->Set(name, serviceItem);
}
- }
-
- if (oldServices) {
- ObjectLock olock(oldServices);
- ConfigItem::Ptr service;
- BOOST_FOREACH(boost::tie(boost::tuples::ignore, service), oldServices) {
- if (!service)
- continue;
-
- if (!newServices->Contains(service->GetName()))
- service->Unregister();
- }
- }
-
- newServices->Seal();
-
- Set("slave_services", newServices);
-}
-
-void Host::OnAttributeChanged(const String& name)
-{
- ASSERT(!OwnsLock());
-
- if (name == "hostgroups")
- HostGroup::InvalidateMembersCache();
- else if (name == "services") {
- UpdateSlaveServices();
- } else if (name == "notifications") {
- BOOST_FOREACH(const Service::Ptr& service, GetServices()) {
- service->UpdateSlaveNotifications();
- }
+ /* Clone attributes from the host object. */
+ std::set<String, string_iless> keys;
+ keys.insert("check_interval");
+ keys.insert("retry_interval");
+ keys.insert("servicegroups");
+ keys.insert("checkers");
+ keys.insert("notification_interval");
+ keys.insert("notification_type_filter");
+ keys.insert("notification_state_filter");
+ keys.insert("check_period");
+ keys.insert("servicedependencies");
+ keys.insert("hostdependencies");
+ keys.insert("export_macros");
+ keys.insert("macros");
+ keys.insert("custom");
+
+ ExpressionList::Ptr host_exprl = boost::make_shared<ExpressionList>();
+ item->GetLinkedExpressionList()->ExtractFiltered(keys, host_exprl);
+ builder->AddExpressionList(host_exprl);
+
+ /* Clone attributes from the service expression list. */
+ std::vector<String> path;
+ path.push_back("services");
+ path.push_back(svcname);
+
+ ExpressionList::Ptr svc_exprl = boost::make_shared<ExpressionList>();
+ item->GetLinkedExpressionList()->ExtractPath(path, svc_exprl);
+ builder->AddExpressionList(svc_exprl);
+
+ ConfigItem::Ptr serviceItem = builder->Compile();
+ DynamicObject::Ptr dobj = serviceItem->Commit();
}
}
std::set<Service::Ptr> Host::GetServices(void) const
{
- std::set<Service::Ptr> services;
-
- boost::mutex::scoped_lock lock(l_ServiceMutex);
+ boost::mutex::scoped_lock lock(m_ServicesMutex);
+ std::set<Service::Ptr> services;
Service::WeakPtr wservice;
- BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), l_ServicesCache[GetName()]) {
+ BOOST_FOREACH(boost::tie(boost::tuples::ignore, wservice), m_Services) {
Service::Ptr service = wservice.lock();
if (!service)
return services;
}
-int Host::GetTotalServices(void) const
+void Host::AddService(const Service::Ptr& service)
{
- return GetServices().size();
+ boost::mutex::scoped_lock lock(m_ServicesMutex);
+
+ m_Services[service->GetShortName()] = service;
}
-void Host::InvalidateServicesCache(void)
+void Host::RemoveService(const Service::Ptr& service)
{
- {
- boost::mutex::scoped_lock lock(l_ServiceMutex);
-
- if (l_ServicesCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
+ boost::mutex::scoped_lock lock(m_ServicesMutex);
- if (!l_ServicesCacheTimer) {
- l_ServicesCacheTimer = boost::make_shared<Timer>();
- l_ServicesCacheTimer->SetInterval(0.5);
- l_ServicesCacheTimer->OnTimerExpired.connect(boost::bind(&Host::RefreshServicesCache));
- l_ServicesCacheTimer->Start();
- }
-
- l_ServicesCacheNeedsUpdate = true;
- }
+ m_Services.erase(service->GetShortName());
}
-void Host::RefreshServicesCache(void)
+int Host::GetTotalServices(void) const
{
- {
- boost::mutex::scoped_lock lock(l_ServiceMutex);
-
- if (!l_ServicesCacheNeedsUpdate)
- return;
-
- l_ServicesCacheNeedsUpdate = false;
- }
-
- Log(LogDebug, "icinga", "Updating Host services cache.");
-
- std::map<String, std::map<String, Service::WeakPtr> > newServicesCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- const Service::Ptr& service = static_pointer_cast<Service>(object);
-
- Host::Ptr host = service->GetHost();
-
- if (!host)
- continue;
-
- // TODO: assert for duplicate short_names
-
- newServicesCache[host->GetName()][service->GetShortName()] = service;
- }
-
- boost::mutex::scoped_lock lock(l_ServiceMutex);
- l_ServicesCache.swap(newServicesCache);
+ return GetServices().size();
}
Value Host::ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs)
}
BOOST_FOREACH(const String& name, templates) {
- ConfigItem::Ptr item;
-
- ConfigCompilerContext *context = ConfigCompilerContext::GetContext();
-
- if (context)
- item = context->GetItem("Service", name);
+ ConfigItem::Ptr item = ConfigItem::GetObject("Service", name);
- /* ignore already active objects while we're in the compiler
- * context and linking to existing items is disabled. */
- if (!item && (!context || (context->GetFlags() & CompilerLinkExisting)))
- item = ConfigItem::GetObject("Service", name);
-
- if (!item) {
- ConfigCompilerContext::GetContext()->AddError(false, "Validation failed for " +
- location + ": Template '" + name + "' not found.");
- }
+ if (!item)
+ ConfigCompilerContext::GetInstance()->AddError(false, "Validation failed for " +
+ location + ": Template '" + name + "' not found.");
}
}
{
if (name.IsScalar()) {
{
- boost::mutex::scoped_lock lock(l_ServiceMutex);
+ boost::mutex::scoped_lock lock(m_ServicesMutex);
- std::map<String, Service::WeakPtr>& services = l_ServicesCache[GetName()];
- std::map<String, Service::WeakPtr>::iterator it = services.find(name);
+ std::map<String, Service::Ptr>::const_iterator it = m_Services.find(name);
- if (it != services.end()) {
- Service::Ptr service = it->second.lock();
- ASSERT(service);
- return service;
- }
+ if (it != m_Services.end())
+ return it->second;
}
return Service::Ptr();
{
std::set<Host::Ptr> childs;
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
- const Host::Ptr& host = static_pointer_cast<Host>(object);
-
+ BOOST_FOREACH(const Host::Ptr& host, DynamicType::GetObjects<Host>()) {
Array::Ptr dependencies = host->GetHostDependencies();
if (dependencies) {
return false;
}
+
+void Host::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("display_name", m_DisplayName);
+ bag->Set("hostgroups", m_HostGroups);
+ bag->Set("macros", m_Macros);
+ bag->Set("hostdependencies", m_HostDependencies);
+ bag->Set("servicedependencies", m_ServiceDependencies);
+ bag->Set("hostcheck", m_HostCheck);
+ bag->Set("services", m_ServiceDescriptions);
+ bag->Set("notifications", m_NotificationDescriptions);
+ }
+}
+
+void Host::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_DisplayName = bag->Get("display_name");
+ m_HostGroups = bag->Get("hostgroups");
+ m_Macros = bag->Get("macros");
+ m_HostDependencies = bag->Get("hostdependencies");
+ m_ServiceDependencies = bag->Get("servicedependencies");
+ m_HostCheck = bag->Get("hostcheck");
+ m_ServiceDescriptions = bag->Get("services");
+ m_NotificationDescriptions = bag->Get("notifications");
+ }
+}
#include "icinga/i2-icinga.h"
#include "icinga/macroresolver.h"
-//#include "base/i2-base.h"
#include "base/array.h"
#include "base/dynamicobject.h"
#include "base/dictionary.h"
{
public:
DECLARE_PTR_TYPEDEFS(Host);
-
- explicit Host(const Dictionary::Ptr& serializedUpdate);
- ~Host(void);
-
- static Host::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(Host);
String GetDisplayName(void) const;
Array::Ptr GetGroups(void) const;
Array::Ptr GetHostDependencies(void) const;
Array::Ptr GetServiceDependencies(void) const;
String GetHostCheck(void) const;
+ //Dictionary::Ptr GetServiceDescriptions(void) const;
+ Dictionary::Ptr GetNotificationDescriptions(void) const;
shared_ptr<Service> GetHostCheckService(void) const;
std::set<Host::Ptr> GetParentHosts(void) const;
shared_ptr<Service> GetServiceByShortName(const Value& name) const;
std::set<shared_ptr<Service> > GetServices(void) const;
+ void AddService(const shared_ptr<Service>& service);
+ void RemoveService(const shared_ptr<Service>& service);
+
int GetTotalServices(void) const;
- static void InvalidateServicesCache(void);
static Value ValidateServiceDictionary(const String& location, const Dictionary::Ptr& attrs);
static String StateToString(HostState state);
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
+
protected:
- virtual void OnRegistrationCompleted(void);
- virtual void OnAttributeChanged(const String& name);
+ virtual void Start(void);
+ virtual void Stop(void);
+
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_DisplayName;
- Attribute<Array::Ptr> m_HostGroups;
- Attribute<Dictionary::Ptr> m_Macros;
- Attribute<Array::Ptr> m_HostDependencies;
- Attribute<Array::Ptr> m_ServiceDependencies;
- Attribute<String> m_HostCheck;
- Dictionary::Ptr m_SlaveServices;
+ String m_DisplayName;
+ Array::Ptr m_HostGroups;
+ Dictionary::Ptr m_Macros;
+ Array::Ptr m_HostDependencies;
+ Array::Ptr m_ServiceDependencies;
+ String m_HostCheck;
+ Dictionary::Ptr m_ServiceDescriptions;
+ Dictionary::Ptr m_NotificationDescriptions;
+
+ mutable boost::mutex m_ServicesMutex;
+ std::map<String, shared_ptr<Service> > m_Services;
void UpdateSlaveServices(void);
using namespace icinga;
-static boost::mutex l_Mutex;
-static std::map<String, std::vector<Host::WeakPtr> > l_MembersCache;
-static bool l_MembersCacheNeedsUpdate = false;
-static Timer::Ptr l_MembersCacheTimer;
-boost::signals2::signal<void (void)> HostGroup::OnMembersChanged;
-
REGISTER_TYPE(HostGroup);
-HostGroup::HostGroup(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-}
-
-HostGroup::~HostGroup(void)
-{
- InvalidateMembersCache();
-}
-
-void HostGroup::OnRegistrationCompleted(void)
-{
- ASSERT(!OwnsLock());
-
- InvalidateMembersCache();
-}
-
String HostGroup::GetDisplayName(void) const
{
if (!m_DisplayName.IsEmpty())
return GetName();
}
-HostGroup::Ptr HostGroup::GetByName(const String& name)
+std::set<Host::Ptr> HostGroup::GetMembers(void) const
{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("HostGroup", name);
-
- if (!configObject)
- BOOST_THROW_EXCEPTION(std::invalid_argument("HostGroup '" + name + "' does not exist."));
-
- return dynamic_pointer_cast<HostGroup>(configObject);
+ return m_Members;
}
-std::set<Host::Ptr> HostGroup::GetMembers(void) const
+void HostGroup::AddMember(const Host::Ptr& host)
{
- std::set<Host::Ptr> hosts;
-
- {
- boost::mutex::scoped_lock lock(l_Mutex);
-
- BOOST_FOREACH(const Host::WeakPtr& whost, l_MembersCache[GetName()]) {
- Host::Ptr host = whost.lock();
-
- if (!host)
- continue;
-
- hosts.insert(host);
- }
- }
-
- return hosts;
+ m_Members.insert(host);
}
-void HostGroup::InvalidateMembersCache(void)
+void HostGroup::RemoveMember(const Host::Ptr& host)
{
- boost::mutex::scoped_lock lock(l_Mutex);
-
- if (l_MembersCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
-
- if (!l_MembersCacheTimer) {
- l_MembersCacheTimer = boost::make_shared<Timer>();
- l_MembersCacheTimer->SetInterval(0.5);
- l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&HostGroup::RefreshMembersCache));
- l_MembersCacheTimer->Start();
- }
-
- l_MembersCacheNeedsUpdate = true;
+ m_Members.erase(host);
}
-void HostGroup::RefreshMembersCache(void)
+void HostGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
- {
- boost::mutex::scoped_lock lock(l_Mutex);
-
- if (!l_MembersCacheNeedsUpdate)
- return;
+ DynamicObject::InternalSerialize(bag, attributeTypes);
- l_MembersCacheNeedsUpdate = false;
- }
-
- Log(LogDebug, "icinga", "Updating HostGroup members cache.");
-
- std::map<String, std::vector<Host::WeakPtr> > newMembersCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Host")) {
- const Host::Ptr& host = static_pointer_cast<Host>(object);
-
- Array::Ptr groups;
- groups = host->GetGroups();
-
- if (groups) {
- ObjectLock mlock(groups);
- BOOST_FOREACH(const Value& group, groups) {
- newMembersCache[group].push_back(host);
- }
- }
- }
+ if (attributeTypes & Attribute_Config)
+ bag->Set("display_name", m_DisplayName);
+}
- {
- boost::mutex::scoped_lock lock(l_Mutex);
- l_MembersCache.swap(newMembersCache);
- }
+void HostGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
- OnMembersChanged();
+ if (attributeTypes & Attribute_Config)
+ m_DisplayName = bag->Get("display_name");
}
#include "icinga/i2-icinga.h"
#include "icinga/host.h"
#include "base/dynamicobject.h"
-#include <set>
namespace icinga
{
{
public:
DECLARE_PTR_TYPEDEFS(HostGroup);
-
- explicit HostGroup(const Dictionary::Ptr& serializedUpdate);
- ~HostGroup(void);
-
- static HostGroup::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(HostGroup);
String GetDisplayName(void) const;
std::set<Host::Ptr> GetMembers(void) const;
-
- static void InvalidateMembersCache(void);
-
- static boost::signals2::signal<void (void)> OnMembersChanged;
+ void AddMember(const Host::Ptr& host);
+ void RemoveMember(const Host::Ptr& host);
protected:
- virtual void OnRegistrationCompleted(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_DisplayName;
-
- static void RefreshMembersCache(void);
+ String m_DisplayName;
+ std::set<Host::Ptr> m_Members;
};
}
# define ICINGA_VERSION GIT_MESSAGE
#endif /* _WIN32 */
-IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate)
- : Application(serializedUpdate)
-{
- RegisterAttribute("cert_path", Attribute_Config, &m_CertPath);
- RegisterAttribute("ca_path", Attribute_Config, &m_CAPath);
- RegisterAttribute("node", Attribute_Config, &m_Node);
- RegisterAttribute("service", Attribute_Config, &m_Service);
- RegisterAttribute("pid_path", Attribute_Config, &m_PidPath);
- RegisterAttribute("state_path", Attribute_Config, &m_StatePath);
- RegisterAttribute("macros", Attribute_Config, &m_Macros);
-}
-
/**
* The entry point for the Icinga application.
*
return false;
}
+
+void IcingaApplication::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("cert_path", m_CertPath);
+ bag->Set("ca_path", m_CAPath);
+ bag->Set("node", m_Node);
+ bag->Set("service", m_Service);
+ bag->Set("pid_path", m_PidPath);
+ bag->Set("state_path", m_StatePath);
+ bag->Set("macros", m_Macros);
+ }
+}
+
+void IcingaApplication::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_CertPath = bag->Get("cert_path");
+ m_CAPath = bag->Get("ca_path");
+ m_Node = bag->Get("node");
+ m_Service = bag->Get("service");
+ m_PidPath = bag->Get("pid_path");
+ m_StatePath = bag->Get("state_path");
+ m_Macros = bag->Get("macros");
+ }
+}
{
public:
DECLARE_PTR_TYPEDEFS(IcingaApplication);
-
- explicit IcingaApplication(const Dictionary::Ptr& serializedUpdate);
+ DECLARE_TYPENAME(IcingaApplication);
int Main(void);
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
+protected:
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_CertPath;
- Attribute<String> m_CAPath;
- Attribute<String> m_Node;
- Attribute<String> m_Service;
- Attribute<String> m_PidPath;
- Attribute<String> m_StatePath;
- Attribute<Dictionary::Ptr> m_Macros;
+ String m_CertPath;
+ String m_CAPath;
+ String m_Node;
+ String m_Service;
+ String m_PidPath;
+ String m_StatePath;
+ Dictionary::Ptr m_Macros;
shared_ptr<SSL_CTX> m_SSLContext;
{
Array::Ptr segments = boost::make_shared<Array>();
- Dictionary::Ptr ranges = tp->Get("ranges");
+ Dictionary::Ptr ranges = tp->GetRanges();
if (ranges) {
for (int i = 0; i <= (end - begin) / (24 * 60 * 60); i++) {
offset = pos_first + resolved_macro.GetLength();
}
+ if (escapeFn)
+ result = escapeFn(result);
+
return result;
}
m_Macros->Set(macro, value);
}
-bool StaticMacroResolver::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool StaticMacroResolver::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
{
if (m_Macros->Contains(macro)) {
*result = m_Macros->Get(macro);
#include "icinga/notificationcommand.h"
#include "icinga/macroprocessor.h"
#include "icinga/service.h"
-#include "icinga/notificationmessage.h"
#include "remoting/endpointmanager.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
REGISTER_TYPE(Notification);
-Notification::Notification(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
+void Notification::Start(void)
{
- RegisterAttribute("notification_command", Attribute_Config, &m_NotificationCommand);
- RegisterAttribute("notification_interval", Attribute_Config, &m_NotificationInterval);
- RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
- RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
- RegisterAttribute("next_notification", Attribute_Replicated, &m_NextNotification);
- RegisterAttribute("notification_number", Attribute_Replicated, &m_NotificationNumber);
- RegisterAttribute("macros", Attribute_Config, &m_Macros);
- RegisterAttribute("users", Attribute_Config, &m_Users);
- RegisterAttribute("groups", Attribute_Config, &m_Groups);
- RegisterAttribute("times", Attribute_Config, &m_Times);
- RegisterAttribute("notification_type_filter", Attribute_Config, &m_NotificationTypeFilter);
- RegisterAttribute("notification_state_filter", Attribute_Config, &m_NotificationStateFilter);
- RegisterAttribute("host_name", Attribute_Config, &m_HostName);
- RegisterAttribute("service", Attribute_Config, &m_Service);
- RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
-}
+ DynamicObject::Start();
-Notification::~Notification(void)
-{
- Service::InvalidateNotificationsCache();
+ GetService()->AddNotification(GetSelf());
}
-Notification::Ptr Notification::GetByName(const String& name)
+void Notification::Stop(void)
{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("Notification", name);
+ DynamicObject::Stop();
- return dynamic_pointer_cast<Notification>(configObject);
+ GetService()->RemoveNotification(GetSelf());
}
Service::Ptr Notification::GetService(void) const
void Notification::SetLastNotification(double time)
{
m_LastNotification = time;
- Touch("last_notification");
}
double Notification::GetNextNotification(void) const
void Notification::SetNextNotification(double time)
{
m_NextNotification = time;
- Touch("next_notification");
}
-int Notification::GetNotificationNumber(void) const
+long Notification::GetNotificationNumber(void) const
{
if (m_NotificationNumber.IsEmpty())
return 0;
void Notification::UpdateNotificationNumber(void)
{
m_NotificationNumber = m_NotificationNumber + 1;
- Touch("notification_number");
}
void Notification::ResetNotificationNumber(void)
{
m_NotificationNumber = 0;
- Touch("notification_number");
}
String Notification::NotificationTypeToString(NotificationType type)
SetLastNotification(Utility::GetTime());
}
- RequestMessage rm;
- rm.SetMethod("icinga::NotificationSent");
-
- NotificationMessage params;
-
- params.SetService(GetService()->GetName());
- params.SetUser(user->GetName());
- params.SetType(type);
- params.SetAuthor(author);
- params.SetCommentText(text);
- params.SetCheckResult(cr);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
+ Service::OnNotificationSentChanged(GetSelf(), user, type, cr, author, text);
Log(LogInformation, "icinga", "Completed sending notification for service '" + GetService()->GetName() + "'");
} catch (const std::exception& ex) {
}
}
-void Notification::OnAttributeChanged(const String& name)
-{
- ASSERT(!OwnsLock());
-
- if (name == "host_name" || name == "service")
- Service::InvalidateNotificationsCache();
-}
-
bool Notification::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
{
Dictionary::Ptr macros = GetMacros();
return false;
}
+
+void Notification::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ bag->Set("notification_command", m_NotificationCommand);
+ bag->Set("notification_interval", m_NotificationInterval);
+ bag->Set("notification_period", m_NotificationPeriod);
+ bag->Set("last_notification", m_LastNotification);
+ bag->Set("next_notification", m_NextNotification);
+ bag->Set("notification_number", m_NotificationNumber);
+ bag->Set("macros", m_Macros);
+ bag->Set("users", m_Users);
+ bag->Set("groups", m_Groups);
+ bag->Set("times", m_Times);
+ bag->Set("notification_type_filter", m_NotificationTypeFilter);
+ bag->Set("notification_state_filter", m_NotificationStateFilter);
+ bag->Set("host_name", m_HostName);
+ bag->Set("export_macros", m_ExportMacros);
+ bag->Set("service", m_Service);
+}
+
+void Notification::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ m_NotificationCommand = bag->Get("notification_command");
+ m_NotificationInterval = bag->Get("notification_interval");
+ m_NotificationPeriod = bag->Get("notification_period");
+ m_LastNotification = bag->Get("last_notification");
+ m_NextNotification = bag->Get("next_notification");
+ m_NotificationNumber = bag->Get("notification_number");
+ m_Macros = bag->Get("macros");
+ m_Users = bag->Get("users");
+ m_Groups = bag->Get("groups");
+ m_Times = bag->Get("times");
+ m_NotificationTypeFilter = bag->Get("notification_type_filter");
+ m_NotificationStateFilter = bag->Get("notification_state_filter");
+ m_HostName = bag->Get("host_name");
+ m_ExportMacros = bag->Get("export_macros");
+ m_Service = bag->Get("service");
+}
{
public:
DECLARE_PTR_TYPEDEFS(Notification);
-
- explicit Notification(const Dictionary::Ptr& serializedUpdate);
- ~Notification(void);
-
- static Notification::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(Notification);
shared_ptr<Service> GetService(void) const;
shared_ptr<NotificationCommand> GetNotificationCommand(void) const;
double GetNextNotification(void) const;
void SetNextNotification(double time);
- int GetNotificationNumber(void) const;
+ long GetNotificationNumber(void) const;
void UpdateNotificationNumber(void);
void ResetNotificationNumber(void);
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
protected:
- void OnAttributeChanged(const String& name);
+ virtual void Start(void);
+ virtual void Stop(void);
-private:
- Attribute<String> m_NotificationCommand;
- Attribute<double> m_NotificationInterval;
- Attribute<String> m_NotificationPeriod;
- Attribute<double> m_LastNotification;
- Attribute<double> m_NextNotification;
- Attribute<int> m_NotificationNumber;
- Attribute<Dictionary::Ptr> m_Macros;
- Attribute<Array::Ptr> m_ExportMacros;
- Attribute<Array::Ptr> m_Users;
- Attribute<Array::Ptr> m_Groups;
- Attribute<Dictionary::Ptr> m_Times;
- Attribute<long> m_NotificationTypeFilter;
- Attribute<long> m_NotificationStateFilter;
- Attribute<String> m_HostName;
- Attribute<String> m_Service;
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+private:
+ String m_NotificationCommand;
+ Value m_NotificationInterval;
+ String m_NotificationPeriod;
+ Value m_LastNotification;
+ Value m_NextNotification;
+ Value m_NotificationNumber;
+ Dictionary::Ptr m_Macros;
+ Array::Ptr m_ExportMacros;
+ Array::Ptr m_Users;
+ Array::Ptr m_Groups;
+ Dictionary::Ptr m_Times;
+ Value m_NotificationTypeFilter;
+ Value m_NotificationStateFilter;
+ String m_HostName;
+ String m_Service;
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force, const String& author = "", const String& text = "");
};
REGISTER_TYPE(NotificationCommand);
-/**
- * Constructor for the NotificationCommand class.
- *
- * @param serializedUpdate A serialized dictionary containing attributes.
- */
-NotificationCommand::NotificationCommand(const Dictionary::Ptr& serializedUpdate)
- : Command(serializedUpdate)
-{ }
-
-NotificationCommand::Ptr NotificationCommand::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("NotificationCommand", name);
-
- return dynamic_pointer_cast<NotificationCommand>(configObject);
-}
-
Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification,
const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type)
{
{
public:
DECLARE_PTR_TYPEDEFS(NotificationCommand);
-
- explicit NotificationCommand(const Dictionary::Ptr& serializedUpdate);
-
- static NotificationCommand::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(NotificationCommand);
virtual Dictionary::Ptr Execute(const shared_ptr<Notification>& notification,
const User::Ptr& user, const Dictionary::Ptr& cr, const NotificationType& type);
+++ /dev/null
-/******************************************************************************
- * 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 "icinga/notificationmessage.h"
-
-using namespace icinga;
-
-String NotificationMessage::GetService(void) const
-{
- String service;
- Get("service", &service);
- return service;
-}
-
-void NotificationMessage::SetService(const String& service)
-{
- Set("service", service);
-}
-
-String NotificationMessage::GetUser(void) const
-{
- String user;
- Get("user", &user);
- return user;
-}
-
-void NotificationMessage::SetUser(const String& user)
-{
- Set("user", user);
-}
-
-NotificationType NotificationMessage::GetType(void) const
-{
- long type;
- Get("type", &type);
- return static_cast<NotificationType>(type);
-}
-
-void NotificationMessage::SetType(NotificationType type)
-{
- Set("type", type);
-}
-
-String NotificationMessage::GetAuthor(void) const
-{
- String author;
- Get("author", &author);
- return author;
-}
-
-void NotificationMessage::SetAuthor(const String& author)
-{
- Set("author", author);
-}
-
-String NotificationMessage::GetCommentText(void) const
-{
- String comment_text;
- Get("comment_text", &comment_text);
- return comment_text;
-}
-
-void NotificationMessage::SetCommentText(const String& comment_text)
-{
- Set("comment_text", comment_text);
-}
-
-Dictionary::Ptr NotificationMessage::GetCheckResult(void) const
-{
- Dictionary::Ptr cr;
- Get("check_result", &cr);
- return cr;
-}
-
-void NotificationMessage::SetCheckResult(const Dictionary::Ptr& result)
-{
- Set("check_result", result);
-}
-
+++ /dev/null
-/******************************************************************************
- * 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 NOTIFICATIONMESSAGE_H
-#define NOTIFICATIONMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/notification.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * A notification message for a service.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API NotificationMessage : public MessagePart
-{
-public:
- NotificationMessage(void) : MessagePart() { }
- explicit NotificationMessage(const MessagePart& message) : MessagePart(message) { }
-
- String GetService(void) const;
- void SetService(const String& service);
-
- String GetUser(void) const;
- void SetUser(const String& user);
-
- NotificationType GetType(void) const;
- void SetType(NotificationType type);
-
- String GetAuthor(void) const;
- void SetAuthor(const String& author);
-
- String GetCommentText(void) const;
- void SetCommentText(const String& comment_text);
-
- Dictionary::Ptr GetCheckResult(void) const;
- void SetCheckResult(const Dictionary::Ptr& result);
-};
-
-}
-
-#endif /* NOTIFICATIONMESSAGE_H */
+++ /dev/null
-/******************************************************************************
- * 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 "icinga/notificationrequestmessage.h"
-
-using namespace icinga;
-
-String NotificationRequestMessage::GetService(void) const
-{
- String service;
- Get("service", &service);
- return service;
-}
-
-void NotificationRequestMessage::SetService(const String& service)
-{
- Set("service", service);
-}
-
-NotificationType NotificationRequestMessage::GetType(void) const
-{
- int type;
- Get("type", &type);
- return static_cast<NotificationType>(type);
-}
-
-void NotificationRequestMessage::SetType(NotificationType type)
-{
- Set("type", type);
-}
-
-Dictionary::Ptr NotificationRequestMessage::GetCheckResult(void) const
-{
- Dictionary::Ptr cr;
- Get("check_result", &cr);
- return cr;
-}
-
-void NotificationRequestMessage::SetCheckResult(const Dictionary::Ptr& cr)
-{
- Set("check_result", cr);
-}
-
-String NotificationRequestMessage::GetAuthor(void) const
-{
- String author;
- Get("author", &author);
- return author;
-}
-
-void NotificationRequestMessage::SetAuthor(const String& author)
-{
- Set("author", author);
-}
-
-String NotificationRequestMessage::GetText(void) const
-{
- String text;
- Get("text", &text);
- return text;
-}
-
-void NotificationRequestMessage::SetText(const String& text)
-{
- Set("text", text);
-}
+++ /dev/null
-/******************************************************************************
- * 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 NOTIFICATIONREQUESTMESSAGE_H
-#define NOTIFICATIONREQUESTMESSAGE_H
-
-#include "icinga/i2-icinga.h"
-#include "icinga/notification.h"
-#include "remoting/messagepart.h"
-
-namespace icinga
-{
-
-/**
- * An API request for sending notifications.
- *
- * @ingroup icinga
- */
-class I2_ICINGA_API NotificationRequestMessage : public MessagePart
-{
-public:
- NotificationRequestMessage(void) : MessagePart() { }
- explicit NotificationRequestMessage(const MessagePart& message) : MessagePart(message) { }
-
- String GetService(void) const;
- void SetService(const String& service);
-
- NotificationType GetType(void) const;
- void SetType(NotificationType type);
-
- Dictionary::Ptr GetCheckResult(void) const;
- void SetCheckResult(const Dictionary::Ptr& cr);
-
- String GetAuthor(void) const;
- void SetAuthor(const String& author);
-
- String GetText(void) const;
- void SetText(const String& text);
-};
-
-}
-
-#endif /* NOTIFICATIONREQUESTMESSAGE_H */
REGISTER_SCRIPTFUNCTION(NullCheck, &NullCheckTask::ScriptFunc);
-Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr& service)
+Dictionary::Ptr NullCheckTask::ScriptFunc(const Service::Ptr&)
{
Dictionary::Ptr cr = boost::make_shared<Dictionary>();
- cr->Set("state", StateUnknown);
+ cr->Set("state", StateOK);
return cr;
}
REGISTER_SCRIPTFUNCTION(NullEvent, &NullEventTask::ScriptFunc);
-void NullEventTask::ScriptFunc(const Service::Ptr& service)
-{
-}
+void NullEventTask::ScriptFunc(const Service::Ptr&)
+{ }
******************************************************************************/
#include "icinga/perfdatawriter.h"
-#include "icinga/checkresultmessage.h"
#include "icinga/service.h"
#include "icinga/macroprocessor.h"
#include "icinga/icingaapplication.h"
REGISTER_TYPE(PerfdataWriter);
-PerfdataWriter::PerfdataWriter(const Dictionary::Ptr& properties)
- : DynamicObject(properties)
-{
- RegisterAttribute("perfdata_path", Attribute_Config, &m_PerfdataPath);
- RegisterAttribute("format_template", Attribute_Config, &m_FormatTemplate);
- RegisterAttribute("rotation_interval", Attribute_Config, &m_RotationInterval);
-}
-
-void PerfdataWriter::OnAttributeChanged(const String& name)
-{
- ASSERT(!OwnsLock());
-
- if (name == "rotation_interval") {
- m_RotationTimer->SetInterval(GetRotationInterval());
- }
-}
+PerfdataWriter::PerfdataWriter(void)
+ : m_RotationInterval(30)
+{ }
void PerfdataWriter::Start(void)
{
- m_Endpoint = Endpoint::MakeEndpoint("perfdata_" + GetName(), false);
- m_Endpoint->RegisterTopicHandler("checker::CheckResult",
- boost::bind(&PerfdataWriter::CheckResultRequestHandler, this, _3));
+ DynamicObject::Start();
+
+ Service::OnNewCheckResult.connect(bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
m_RotationTimer = boost::make_shared<Timer>();
m_RotationTimer->OnTimerExpired.connect(boost::bind(&PerfdataWriter::RotationTimerHandler, this));
RotateFile();
}
-PerfdataWriter::Ptr PerfdataWriter::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("PerfdataWriter", name);
-
- return dynamic_pointer_cast<PerfdataWriter>(configObject);
-}
-
String PerfdataWriter::GetPerfdataPath(void) const
{
if (!m_PerfdataPath.IsEmpty())
double PerfdataWriter::GetRotationInterval(void) const
{
- if (!m_RotationInterval.IsEmpty())
- return m_RotationInterval;
- else
- return 30;
+ return m_RotationInterval;
}
-void PerfdataWriter::CheckResultRequestHandler(const RequestMessage& request)
+void PerfdataWriter::CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr)
{
- CheckResultMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
+ Host::Ptr host = service->GetHost();
- Dictionary::Ptr cr = params.GetCheckResult();
- if (!cr)
+ if (!host)
return;
std::vector<MacroResolver::Ptr> resolvers;
resolvers.push_back(service);
- resolvers.push_back(service->GetHost());
+ resolvers.push_back(host);
resolvers.push_back(IcingaApplication::GetInstance());
String line = MacroProcessor::ResolveMacros(GetFormatTemplate(), resolvers, cr);
{
RotateFile();
}
+
+void PerfdataWriter::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("perfdata_path", m_PerfdataPath);
+ bag->Set("format_template", m_FormatTemplate);
+ bag->Set("rotation_interval", m_RotationInterval);
+ }
+}
+
+void PerfdataWriter::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_PerfdataPath = bag->Get("perfdata_path");
+ m_FormatTemplate = bag->Get("format_template");
+ m_RotationInterval = bag->Get("rotation_interval");
+ }
+}
#define PERFDATAWRITER_H
#include "icinga/i2-icinga.h"
-#include "remoting/endpoint.h"
+#include "icinga/service.h"
#include "base/dynamicobject.h"
#include "base/timer.h"
#include <fstream>
{
public:
DECLARE_PTR_TYPEDEFS(PerfdataWriter);
+ DECLARE_TYPENAME(PerfdataWriter);
- PerfdataWriter(const Dictionary::Ptr& properties);
-
- static PerfdataWriter::Ptr GetByName(const String& name);
+ PerfdataWriter(void);
String GetPerfdataPath(void) const;
String GetFormatTemplate(void) const;
double GetRotationInterval(void) const;
protected:
- virtual void OnAttributeChanged(const String& name);
virtual void Start(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_PerfdataPath;
- Attribute<String> m_FormatTemplate;
- Attribute<double> m_RotationInterval;
+ String m_PerfdataPath;
+ String m_FormatTemplate;
+ double m_RotationInterval;
- Endpoint::Ptr m_Endpoint;
- void CheckResultRequestHandler(const RequestMessage& request);
+ void CheckResultHandler(const Service::Ptr& service, const Dictionary::Ptr& cr);
Timer::Ptr m_RotationTimer;
void RotationTimerHandler(void);
Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
- Value timeout = commandObj->Get("timeout");
-
- if (!timeout.IsEmpty())
- process->SetTimeout(timeout);
+ process->SetTimeout(commandObj->GetTimeout());
ProcessResult pr = process->Run();
Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
- Value timeout = commandObj->Get("timeout");
-
- if (!timeout.IsEmpty())
- process->SetTimeout(timeout);
+ process->SetTimeout(commandObj->GetTimeout());
process->Run();
}
Process::Ptr process = boost::make_shared<Process>(Process::SplitCommand(command), envMacros);
- Value timeout = commandObj->Get("timeout");
-
- if (!timeout.IsEmpty())
- process->SetTimeout(timeout);
+ process->SetTimeout(commandObj->GetTimeout());
ProcessResult pr = process->Run();
#include "icinga/service.h"
#include "icinga/checkcommand.h"
#include "icinga/icingaapplication.h"
-#include "icinga/checkresultmessage.h"
-#include "icinga/flappingmessage.h"
#include "icinga/cib.h"
-#include "remoting/endpointmanager.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/convert.h"
+#include "base/utility.h"
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
const double Service::DefaultCheckInterval = 5 * 60;
const double Service::CheckIntervalDivisor = 5.0;
-boost::signals2::signal<void (const Service::Ptr&)> Service::OnCheckerChanged;
+boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> Service::OnNewCheckResult;
+boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationsRequested;
boost::signals2::signal<void (const Service::Ptr&)> Service::OnNextCheckChanged;
boost::signals2::signal<void (const Service::Ptr&, FlappingState)> Service::OnFlappingChanged;
void Service::SetNextCheck(double nextCheck)
{
m_NextCheck = nextCheck;
- Touch("next_check");
+
+ Utility::QueueAsyncCallback(bind(boost::ref(Service::OnNextCheckChanged), GetSelf()));
}
double Service::GetNextCheck(void)
void Service::SetCurrentChecker(const String& checker)
{
m_CurrentChecker = checker;
- Touch("current_checker");
}
String Service::GetCurrentChecker(void) const
void Service::SetCurrentCheckAttempt(long attempt)
{
m_CheckAttempt = attempt;
- Touch("check_attempt");
}
long Service::GetCurrentCheckAttempt(void) const
void Service::SetState(ServiceState state)
{
m_State = static_cast<long>(state);
- Touch("state");
}
ServiceState Service::GetState(void) const
void Service::SetLastState(ServiceState state)
{
m_LastState = static_cast<long>(state);
-
- Touch("last_state");
}
ServiceState Service::GetLastState(void) const
void Service::SetLastHardState(ServiceState state)
{
m_LastHardState = static_cast<long>(state);
-
- Touch("last_hard_state");
}
ServiceState Service::GetLastHardState(void) const
void Service::SetStateType(StateType type)
{
m_StateType = static_cast<long>(type);
- Touch("state_type");
}
StateType Service::GetStateType(void) const
void Service::SetLastStateType(StateType type)
{
m_LastStateType = static_cast<long>(type);
- Touch("last_state_type");
}
StateType Service::GetLastStateType(void) const
void Service::SetLastStateOK(double ts)
{
m_LastStateOK = ts;
- Touch("last_state_ok");
}
double Service::GetLastStateOK(void) const
void Service::SetLastStateWarning(double ts)
{
m_LastStateWarning = ts;
- Touch("last_state_warning");
}
double Service::GetLastStateWarning(void) const
void Service::SetLastStateCritical(double ts)
{
m_LastStateCritical = ts;
- Touch("last_state_critical");
}
double Service::GetLastStateCritical(void) const
void Service::SetLastStateUnknown(double ts)
{
m_LastStateUnknown = ts;
- Touch("last_state_unknown");
}
double Service::GetLastStateUnknown(void) const
void Service::SetLastStateUnreachable(double ts)
{
m_LastStateUnreachable = ts;
- Touch("last_state_unreachable");
}
double Service::GetLastStateUnreachable(void) const
void Service::SetLastReachable(bool reachable)
{
m_LastReachable = reachable;
- Touch("last_reachable");
}
bool Service::GetLastReachable(void) const
void Service::SetLastCheckResult(const Dictionary::Ptr& result)
{
m_LastResult = result;
- Touch("last_result");
}
Dictionary::Ptr Service::GetLastCheckResult(void) const
void Service::SetLastStateChange(double ts)
{
m_LastStateChange = ts;
- Touch("last_state_change");
}
double Service::GetLastStateChange(void) const
void Service::SetLastHardStateChange(double ts)
{
m_LastHardStateChange = ts;
- Touch("last_hard_state_change");
}
double Service::GetLastHardStateChange(void) const
void Service::SetEnableActiveChecks(bool enabled)
{
m_EnableActiveChecks = enabled ? 1 : 0;
- Touch("enable_active_checks");
}
bool Service::GetEnablePassiveChecks(void) const
void Service::SetEnablePassiveChecks(bool enabled)
{
m_EnablePassiveChecks = enabled ? 1 : 0;
- Touch("enable_passive_checks");
}
bool Service::GetForceNextCheck(void) const
void Service::SetForceNextCheck(bool forced)
{
m_ForceNextCheck = forced ? 1 : 0;
- Touch("force_next_check");
}
void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
bool send_downtime_notification = m_LastInDowntime != in_downtime;
m_LastInDowntime = in_downtime;
- Touch("last_in_downtime");
olock.Unlock();
" threshold: " + Convert::ToString(GetFlappingThreshold()) +
"% current: " + Convert::ToString(GetFlappingCurrent()) + "%.");
- /* Flush the object so other instances see the service's
- * new state when they receive the CheckResult message */
- Flush();
-
- RequestMessage rm;
- rm.SetMethod("checker::CheckResult");
-
- /* TODO: add _old_ state to message */
- CheckResultMessage params;
- params.SetService(GetName());
- params.SetCheckResult(cr);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
+ OnNewCheckResult(GetSelf(), cr);
+ OnStateChanged(GetSelf());
if (call_eventhandler)
ExecuteEventHandler();
if (send_downtime_notification)
- RequestNotifications(in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr);
+ OnNotificationsRequested(GetSelf(), in_downtime ? NotificationDowntimeStart : NotificationDowntimeEnd, cr, "", "");
if (!was_flapping && is_flapping) {
- RequestNotifications(NotificationFlappingStart, cr);
-
- RequestMessage rm;
- rm.SetMethod("icinga::Flapping");
-
- FlappingMessage params;
- params.SetService(GetName());
- params.SetState(FlappingStarted);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
+ OnNotificationsRequested(GetSelf(), NotificationFlappingStart, cr, "", "");
Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " started flapping (" + Convert::ToString(GetFlappingThreshold()) + "% < " + Convert::ToString(GetFlappingCurrent()) + "%).");
- }
- else if (was_flapping && !is_flapping) {
- RequestNotifications(NotificationFlappingEnd, cr);
-
- RequestMessage rm;
- rm.SetMethod("icinga::Flapping");
-
- FlappingMessage params;
- params.SetService(GetName());
- params.SetState(FlappingStopped);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
+ OnFlappingChanged(GetSelf(), FlappingStarted);
+ } else if (was_flapping && !is_flapping) {
+ OnNotificationsRequested(GetSelf(), NotificationFlappingEnd, cr, "", "");
Log(LogDebug, "icinga", "Flapping: Service " + GetName() + " stopped flapping (" + Convert::ToString(GetFlappingThreshold()) + "% >= " + Convert::ToString(GetFlappingCurrent()) + "%).");
- }
- else if (send_notification)
- RequestNotifications(recovery ? NotificationRecovery : NotificationProblem, cr);
+ OnFlappingChanged(GetSelf(), FlappingStopped);
+ } else if (send_notification)
+ OnNotificationsRequested(GetSelf(), recovery ? NotificationRecovery : NotificationProblem, cr, "", "");
}
ServiceState Service::StateFromString(const String& state)
if (!result->Contains("active"))
result->Set("active", 1);
-
- if (!result->Contains("current_checker"))
- result->Set("current_checker", EndpointManager::GetInstance()->GetIdentity());
}
if (result)
static boost::mutex l_CommentMutex;
static std::map<int, String> l_LegacyCommentsCache;
static std::map<String, Service::WeakPtr> l_CommentsCache;
-static bool l_CommentsCacheNeedsUpdate = false;
-static Timer::Ptr l_CommentsCacheTimer;
+//static bool l_CommentsCacheNeedsUpdate = false;
+//static Timer::Ptr l_CommentsCacheTimer;
static Timer::Ptr l_CommentsExpireTimer;
boost::signals2::signal<void (const Service::Ptr&, const String&, CommentChangedType)> Service::OnCommentsChanged;
ObjectLock olock(this);
comments->Set(id, comment);
- Touch("comments");
}
{
boost::mutex::scoped_lock lock(l_CommentMutex);
+ l_LegacyCommentsCache[legacy_id] = id;
l_CommentsCache[id] = GetSelf();
}
void Service::RemoveAllComments(void)
{
- OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
-
m_Comments = Empty;
- Touch("comments");
+
+ {
+ boost::mutex::scoped_lock lock(l_CommentMutex);
+ l_LegacyCommentsCache.clear();
+ l_CommentsCache.clear();
+ }
+
+ OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
}
void Service::RemoveComment(const String& id)
if (comments) {
ObjectLock olock(owner);
+ Dictionary::Ptr comment = comments->Get(id);
+
+ if (!comment)
+ return;
+
+ int legacy_id = comment->Get("legacy_id");
+
comments->Remove(id);
- owner->Touch("comments");
+
+ {
+ boost::mutex::scoped_lock lock(l_CommentMutex);
+ l_LegacyCommentsCache.erase(legacy_id);
+ l_CommentsCache.erase(id);
+ }
OnCommentsChanged(owner, id, CommentChangedDeleted);
}
return (expire_time != 0 && expire_time < Utility::GetTime());
}
-void Service::InvalidateCommentsCache(void)
+void Service::AddCommentsToCache(void)
{
- boost::mutex::scoped_lock lock(l_CommentMutex);
-
- if (l_CommentsCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
-
- if (!l_CommentsCacheTimer) {
- l_CommentsCacheTimer = boost::make_shared<Timer>();
- l_CommentsCacheTimer->SetInterval(0.5);
- l_CommentsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshCommentsCache));
- l_CommentsCacheTimer->Start();
- }
-
- l_CommentsCacheNeedsUpdate = true;
-}
-
-void Service::RefreshCommentsCache(void)
-{
- {
- boost::mutex::scoped_lock lock(l_CommentMutex);
-
- if (!l_CommentsCacheNeedsUpdate)
- return;
-
- l_CommentsCacheNeedsUpdate = false;
- }
-
Log(LogDebug, "icinga", "Updating Service comments cache.");
- std::map<int, String> newLegacyCommentsCache;
- std::map<String, Service::WeakPtr> newCommentsCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = dynamic_pointer_cast<Service>(object);
-
- Dictionary::Ptr comments = service->GetComments();
-
- if (!comments)
- continue;
-
- ObjectLock olock(comments);
-
- String id;
- Dictionary::Ptr comment;
- BOOST_FOREACH(tie(id, comment), comments) {
- int legacy_id = comment->Get("legacy_id");
-
- if (legacy_id >= l_NextCommentID)
- l_NextCommentID = legacy_id + 1;
-
- if (newLegacyCommentsCache.find(legacy_id) != newLegacyCommentsCache.end()) {
- /* The legacy_id is already in use by another comment;
- * this shouldn't usually happen - assign it a new ID */
-
- legacy_id = l_NextCommentID++;
- comment->Set("legacy_id", legacy_id);
+ Dictionary::Ptr comments = GetComments();
- {
- ObjectLock olock(service);
- service->Touch("comments");
- }
- }
+ if (!comments)
+ return;
- newLegacyCommentsCache[legacy_id] = id;
- newCommentsCache[id] = service;
- }
- }
+ ObjectLock olock(comments);
boost::mutex::scoped_lock lock(l_CommentMutex);
- l_CommentsCache.swap(newCommentsCache);
- l_LegacyCommentsCache.swap(newLegacyCommentsCache);
+ String id;
+ Dictionary::Ptr comment;
+ BOOST_FOREACH(tie(id, comment), comments) {
+ int legacy_id = comment->Get("legacy_id");
+
+ if (legacy_id >= l_NextCommentID)
+ l_NextCommentID = legacy_id + 1;
- if (!l_CommentsExpireTimer) {
- l_CommentsExpireTimer = boost::make_shared<Timer>();
- l_CommentsExpireTimer->SetInterval(300);
- l_CommentsExpireTimer->OnTimerExpired.connect(boost::bind(&Service::CommentsExpireTimerHandler));
- l_CommentsExpireTimer->Start();
+ l_LegacyCommentsCache[legacy_id] = id;
+ l_CommentsCache[id] = GetSelf();
}
}
if (!removedComments.empty()) {
BOOST_FOREACH(const String& id, removedComments) {
- comments->Remove(id);
+ RemoveComment(id);
}
-
- OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
-
- ObjectLock olock(this);
- Touch("comments");
}
-
}
void Service::RemoveExpiredComments(void)
if (!expiredComments.empty()) {
BOOST_FOREACH(const String& id, expiredComments) {
- comments->Remove(id);
+ RemoveComment(id);
}
-
- OnCommentsChanged(GetSelf(), Empty, CommentChangedDeleted);
-
- ObjectLock olock(this);
- Touch("comments");
}
}
void Service::CommentsExpireTimerHandler(void)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = dynamic_pointer_cast<Service>(object);
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
service->RemoveExpiredComments();
}
}
******************************************************************************/
#include "icinga/service.h"
-#include "icinga/downtimemessage.h"
-#include "remoting/endpointmanager.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
static boost::mutex l_DowntimeMutex;
static std::map<int, String> l_LegacyDowntimesCache;
static std::map<String, Service::WeakPtr> l_DowntimesCache;
-static bool l_DowntimesCacheNeedsUpdate = false;
-static Timer::Ptr l_DowntimesCacheTimer;
static Timer::Ptr l_DowntimesExpireTimer;
boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> Service::OnDowntimeChanged;
boost::signals2::signal<void (const Service::Ptr&, const String&, DowntimeChangedType)> Service::OnDowntimesChanged;
-void Service::DowntimeRequestHandler(const RequestMessage& request)
-{
- DowntimeMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
-
- OnDowntimeChanged(service, params.GetState());
-}
-
int Service::GetNextDowntimeID(void)
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
if (!triggeredBy.IsEmpty()) {
Service::Ptr otherOwner = GetOwnerByDowntimeID(triggeredBy);
- Dictionary::Ptr otherDowntimes = otherOwner->Get("downtimes");
+ Dictionary::Ptr otherDowntimes = otherOwner->m_Downtimes;
Dictionary::Ptr otherDowntime = otherDowntimes->Get(triggeredBy);
Dictionary::Ptr triggers = otherDowntime->Get("triggers");
{
ObjectLock olock(otherOwner);
triggers->Set(triggeredBy, triggeredBy);
- otherOwner->Touch("downtimes");
}
}
String id = Utility::NewUniqueID();
downtimes->Set(id, downtime);
- {
- ObjectLock olock(this);
- Touch("downtimes");
- }
-
(void) AddComment(CommentDowntime, author, comment, endTime);
{
boost::mutex::scoped_lock lock(l_DowntimeMutex);
+ l_LegacyDowntimesCache[legacy_id] = id;
l_DowntimesCache[id] = GetSelf();
}
{
ObjectLock olock(owner);
- downtimes->Remove(id);
-
- RequestMessage rm;
- rm.SetMethod("icinga::Downtime");
-
- DowntimeMessage params;
- params.SetService(owner->GetName());
- params.SetState(DowntimeCancelled);
+ Dictionary::Ptr downtime = downtimes->Get(id);
- rm.SetParams(params);
+ int legacy_id = downtime->Get("legacy_id");
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
+ downtimes->Remove(id);
- owner->Touch("downtimes");
+ {
+ boost::mutex::scoped_lock lock(l_DowntimeMutex);
+ l_LegacyDowntimesCache.erase(legacy_id);
+ l_DowntimesCache.erase(id);
+ }
}
+ OnDowntimeChanged(owner, DowntimeCancelled);
+
OnDowntimesChanged(owner, id, DowntimeChangedDeleted);
}
String id;
BOOST_FOREACH(boost::tie(id, boost::tuples::ignore), downtimes) {
ids.push_back(id);
-
}
}
TriggerDowntime(tid);
}
- RequestMessage rm;
- rm.SetMethod("icinga::Downtime");
-
- DowntimeMessage params;
- params.SetService(owner->GetName());
- params.SetState(DowntimeStarted);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
-
- owner->Touch("downtimes");
-
+ OnDowntimeChanged(owner, DowntimeStarted);
OnDowntimesChanged(owner, Empty, DowntimeChangedUpdated);
}
return (downtime->Get("end_time") < Utility::GetTime());
}
-void Service::InvalidateDowntimesCache(void)
-{
- boost::mutex::scoped_lock lock(l_DowntimeMutex);
-
- if (l_DowntimesCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
-
- if (!l_DowntimesCacheTimer) {
- l_DowntimesCacheTimer = boost::make_shared<Timer>();
- l_DowntimesCacheTimer->SetInterval(0.5);
- l_DowntimesCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshDowntimesCache));
- l_DowntimesCacheTimer->Start();
- }
-
- l_DowntimesCacheNeedsUpdate = true;
-}
-
-void Service::RefreshDowntimesCache(void)
+void Service::AddDowntimesToCache(void)
{
- {
- boost::mutex::scoped_lock lock(l_DowntimeMutex);
-
- if (!l_DowntimesCacheNeedsUpdate)
- return;
-
- l_DowntimesCacheNeedsUpdate = false;
- }
-
Log(LogDebug, "icinga", "Updating Service downtimes cache.");
- std::map<int, String> newLegacyDowntimesCache;
- std::map<String, Service::WeakPtr> newDowntimesCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = dynamic_pointer_cast<Service>(object);
-
- Dictionary::Ptr downtimes = service->GetDowntimes();
-
- if (!downtimes)
- continue;
-
- ObjectLock olock(downtimes);
-
- String id;
- Dictionary::Ptr downtime;
- BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
- int legacy_id = downtime->Get("legacy_id");
+ Dictionary::Ptr downtimes = GetDowntimes();
- if (legacy_id >= l_NextDowntimeID)
- l_NextDowntimeID = legacy_id + 1;
+ if (!downtimes)
+ return;
- if (newLegacyDowntimesCache.find(legacy_id) != newLegacyDowntimesCache.end()) {
- /* The legacy_id is already in use by another downtime;
- * this shouldn't usually happen - assign it a new ID. */
- legacy_id = l_NextDowntimeID++;
- downtime->Set("legacy_id", legacy_id);
- service->Touch("downtimes");
- }
+ boost::mutex::scoped_lock lock(l_DowntimeMutex);
- newLegacyDowntimesCache[legacy_id] = id;
- newDowntimesCache[id] = service;
- }
- }
+ ObjectLock olock(downtimes);
- boost::mutex::scoped_lock lock(l_DowntimeMutex);
+ String id;
+ Dictionary::Ptr downtime;
+ BOOST_FOREACH(boost::tie(id, downtime), downtimes) {
+ int legacy_id = downtime->Get("legacy_id");
- l_DowntimesCache.swap(newDowntimesCache);
- l_LegacyDowntimesCache.swap(newLegacyDowntimesCache);
+ if (legacy_id >= l_NextDowntimeID)
+ l_NextDowntimeID = legacy_id + 1;
- if (!l_DowntimesExpireTimer) {
- l_DowntimesExpireTimer = boost::make_shared<Timer>();
- l_DowntimesExpireTimer->SetInterval(300);
- l_DowntimesExpireTimer->OnTimerExpired.connect(boost::bind(&Service::DowntimesExpireTimerHandler));
- l_DowntimesExpireTimer->Start();
+ l_LegacyDowntimesCache[legacy_id] = id;
+ l_DowntimesCache[id] = GetSelf();
}
}
if (!expiredDowntimes.empty()) {
BOOST_FOREACH(const String& id, expiredDowntimes) {
- RequestMessage rm;
- rm.SetMethod("icinga::Downtime");
-
- DowntimeMessage params;
- params.SetService(GetName());
- params.SetState(DowntimeStopped);
-
- rm.SetParams(params);
-
- EndpointManager::GetInstance()->SendMulticastMessage(rm);
-
- downtimes->Remove(id);
+ RemoveDowntime(id);
}
-
- {
- ObjectLock olock(this);
- Touch("downtimes");
- }
-
- OnDowntimesChanged(GetSelf(), Empty, DowntimeChangedDeleted);
}
}
void Service::DowntimesExpireTimerHandler(void)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = dynamic_pointer_cast<Service>(object);
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
service->RemoveExpiredDowntimes();
}
}
******************************************************************************/
#include "icinga/service.h"
-#include "icinga/flappingmessage.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
double Service::GetFlappingCurrent(void) const
{
- if (m_FlappingNegative.IsEmpty() || m_FlappingPositive.IsEmpty())
- return 0;
-
if (m_FlappingPositive + m_FlappingNegative <= 0)
return 0;
return m_FlappingThreshold;
}
-void Service::FlappingRequestHandler(const RequestMessage& request)
-{
- FlappingMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
-
- OnFlappingChanged(service, params.GetState());
-}
-
bool Service::GetEnableFlapping(void) const
{
if (m_EnableFlapping.IsEmpty())
void Service::SetEnableFlapping(bool enabled)
{
- m_EnableFlapping = enabled ? 1 : 0;
- Touch("enable_flapping");
+ OnFlappingChanged(GetSelf(), enabled ? FlappingEnabled : FlappingDisabled);
+
+ m_EnableFlapping = enabled;
}
void Service::UpdateFlappingStatus(bool stateChange)
Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative));
m_FlappingPositive = positive;
- Touch("flapping_positive");
-
m_FlappingNegative = negative;
- Touch("flapping_negative");
-
m_FlappingLastChange = now;
- Touch("flapping_lastchange");
}
bool Service::IsFlapping(void) const
******************************************************************************/
#include "icinga/service.h"
-#include "icinga/notificationrequestmessage.h"
-#include "icinga/notificationmessage.h"
-#include "remoting/endpointmanager.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
#include "base/logger_fwd.h"
+#include "base/timer.h"
#include "config/configitembuilder.h"
#include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp>
using namespace icinga;
-static boost::mutex l_NotificationMutex;
-static std::map<String, std::set<Notification::WeakPtr> > l_NotificationsCache;
-static bool l_NotificationsCacheNeedsUpdate = false;
-static Timer::Ptr l_NotificationsCacheTimer;
+boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
-boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> Service::OnNotificationSentChanged;
+Dictionary::Ptr Service::GetNotificationDescriptions(void) const
+{
+ return m_NotificationDescriptions;
+}
void Service::ResetNotificationNumbers(void)
{
}
}
-void Service::NotificationSentRequestHandler(const RequestMessage& request)
-{
- NotificationMessage params;
- if (!request.GetParams(¶ms))
- return;
-
- String svcname = params.GetService();
- Service::Ptr service = Service::GetByName(svcname);
-
- String username = params.GetUser();
- String author = params.GetAuthor();
- String comment_text = params.GetCommentText();
-
- NotificationType notification_type = params.GetType();
- Dictionary::Ptr cr = params.GetCheckResult();
-
- OnNotificationSentChanged(service, username, notification_type, cr, author, comment_text);
-}
-
-void Service::RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text)
-{
- RequestMessage msg;
- msg.SetMethod("icinga::SendNotifications");
-
- NotificationRequestMessage params;
- msg.SetParams(params);
-
- params.SetService(GetName());
- params.SetType(type);
- params.SetCheckResult(cr);
- params.SetAuthor(author);
- params.SetText(text);
-
- Log(LogDebug, "icinga", "Sending notification anycast request for service '" + GetName() + "'");
- EndpointManager::GetInstance()->SendAnycastMessage(Endpoint::Ptr(), msg);
-}
-
void Service::SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author, const String& text)
{
bool force = false;
}
}
-void Service::InvalidateNotificationsCache(void)
+std::set<Notification::Ptr> Service::GetNotifications(void) const
{
- boost::mutex::scoped_lock lock(l_NotificationMutex);
-
- if (l_NotificationsCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
-
- if (!l_NotificationsCacheTimer) {
- l_NotificationsCacheTimer = boost::make_shared<Timer>();
- l_NotificationsCacheTimer->SetInterval(0.5);
- l_NotificationsCacheTimer->OnTimerExpired.connect(boost::bind(&Service::RefreshNotificationsCache));
- l_NotificationsCacheTimer->Start();
- }
-
- l_NotificationsCacheNeedsUpdate = true;
+ return m_Notifications;
}
-void Service::RefreshNotificationsCache(void)
+void Service::AddNotification(const Notification::Ptr& notification)
{
- {
- boost::mutex::scoped_lock lock(l_NotificationMutex);
-
- if (!l_NotificationsCacheNeedsUpdate)
- return;
-
- l_NotificationsCacheNeedsUpdate = false;
- }
-
- Log(LogDebug, "icinga", "Updating Service notifications cache.");
-
- std::map<String, std::set<Notification::WeakPtr> > newNotificationsCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Notification")) {
- const Notification::Ptr& notification = static_pointer_cast<Notification>(object);
-
- Service::Ptr service = notification->GetService();
-
- if (!service)
- continue;
-
- newNotificationsCache[service->GetName()].insert(notification);
- }
-
- boost::mutex::scoped_lock lock(l_NotificationMutex);
- l_NotificationsCache.swap(newNotificationsCache);
+ m_Notifications.insert(notification);
}
-std::set<Notification::Ptr> Service::GetNotifications(void) const
+void Service::RemoveNotification(const Notification::Ptr& notification)
{
- std::set<Notification::Ptr> notifications;
-
- {
- boost::mutex::scoped_lock lock(l_NotificationMutex);
-
- BOOST_FOREACH(const Notification::WeakPtr& wservice, l_NotificationsCache[GetName()]) {
- Notification::Ptr notification = wservice.lock();
-
- if (!notification)
- continue;
-
- notifications.insert(notification);
- }
- }
-
- return notifications;
+ m_Notifications.erase(notification);
}
void Service::UpdateSlaveNotifications(void)
{
- Dictionary::Ptr oldNotifications;
ConfigItem::Ptr serviceItem, hostItem;
serviceItem = ConfigItem::GetObject("Service", GetName());
if (!hostItem)
return;
- {
- ObjectLock olock(this);
- oldNotifications = m_SlaveNotifications;
- }
-
std::vector<Dictionary::Ptr> descLists;
- descLists.push_back(Get("notifications"));
-
- Dictionary::Ptr newNotifications;
- newNotifications = boost::make_shared<Dictionary>();
-
- descLists.push_back(host->Get("notifications"));
+ descLists.push_back(GetNotificationDescriptions());
+ descLists.push_back(host->GetNotificationDescriptions());
for (int i = 0; i < 2; i++) {
Dictionary::Ptr descs;
if (i == 0) {
/* Host notification descs */
- descs = host->Get("notifications");
+ descs = host->GetNotificationDescriptions();
item = hostItem;
} else {
/* Service notification descs */
- descs = Get("notifications");
+ descs = GetNotificationDescriptions();
item = serviceItem;
}
ConfigItem::Ptr notificationItem = builder->Compile();
notificationItem->Commit();
-
- newNotifications->Set(name, notificationItem);
}
}
-
- if (oldNotifications) {
- ObjectLock olock(oldNotifications);
-
- ConfigItem::Ptr notification;
- BOOST_FOREACH(boost::tie(boost::tuples::ignore, notification), oldNotifications) {
- if (!notification)
- continue;
-
- if (!newNotifications->Contains(notification->GetName()))
- notification->Unregister();
- }
- }
-
- {
- ObjectLock olock(this);
- m_SlaveNotifications = newNotifications;
- }
}
bool Service::GetEnableNotifications(void) const
void Service::SetEnableNotifications(bool enabled)
{
m_EnableNotifications = enabled;
- Touch("enable_notifications");
}
bool Service::GetForceNextNotification(void) const
void Service::SetForceNextNotification(bool forced)
{
m_ForceNextNotification = forced ? 1 : 0;
- Touch("force_next_notification");
}
#include "icinga/checkcommand.h"
#include "icinga/icingaapplication.h"
#include "icinga/macroprocessor.h"
-#include "icinga/downtimemessage.h"
#include "config/configitembuilder.h"
#include "base/dynamictype.h"
#include "base/objectlock.h"
REGISTER_TYPE(Service);
-Endpoint::Ptr Service::m_Endpoint;
-boost::once_flag Service::m_OnceFlag = BOOST_ONCE_INIT;
-
-Service::Service(const Dictionary::Ptr& serializedObject)
- : DynamicObject(serializedObject), m_CheckRunning(false)
+void Service::Start(void)
{
-
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
- RegisterAttribute("macros", Attribute_Config, &m_Macros);
- RegisterAttribute("hostdependencies", Attribute_Config, &m_HostDependencies);
- RegisterAttribute("servicedependencies", Attribute_Config, &m_ServiceDependencies);
- RegisterAttribute("servicegroups", Attribute_Config, &m_ServiceGroups);
-
- RegisterAttribute("check_command", Attribute_Config, &m_CheckCommand);
- RegisterAttribute("max_check_attempts", Attribute_Config, &m_MaxCheckAttempts);
- RegisterAttribute("check_period", Attribute_Config, &m_CheckPeriod);
- RegisterAttribute("check_interval", Attribute_Config, &m_CheckInterval);
- RegisterAttribute("retry_interval", Attribute_Config, &m_RetryInterval);
- RegisterAttribute("checkers", Attribute_Config, &m_Checkers);
-
- RegisterAttribute("event_command", Attribute_Config, &m_EventCommand);
- RegisterAttribute("volatile", Attribute_Config, &m_Volatile);
-
- RegisterAttribute("next_check", Attribute_Replicated, &m_NextCheck);
- RegisterAttribute("current_checker", Attribute_Replicated, &m_CurrentChecker);
- RegisterAttribute("check_attempt", Attribute_Replicated, &m_CheckAttempt);
- RegisterAttribute("state", Attribute_Replicated, &m_State);
- RegisterAttribute("state_type", Attribute_Replicated, &m_StateType);
- RegisterAttribute("last_state", Attribute_Replicated, &m_LastState);
- RegisterAttribute("last_hard_state", Attribute_Replicated, &m_LastHardState);
- RegisterAttribute("last_state_type", Attribute_Replicated, &m_LastStateType);
- RegisterAttribute("last_reachable", Attribute_Replicated, &m_LastReachable);
- RegisterAttribute("last_result", Attribute_Replicated, &m_LastResult);
- RegisterAttribute("last_state_change", Attribute_Replicated, &m_LastStateChange);
- RegisterAttribute("last_hard_state_change", Attribute_Replicated, &m_LastHardStateChange);
- RegisterAttribute("last_state_ok", Attribute_Replicated, &m_LastStateOK);
- RegisterAttribute("last_state_warning", Attribute_Replicated, &m_LastStateWarning);
- RegisterAttribute("last_state_critical", Attribute_Replicated, &m_LastStateCritical);
- RegisterAttribute("last_state_unknown", Attribute_Replicated, &m_LastStateUnknown);
- RegisterAttribute("last_state_unreachable", Attribute_Replicated, &m_LastStateUnreachable);
- RegisterAttribute("last_in_downtime", Attribute_Replicated, &m_LastInDowntime);
- RegisterAttribute("enable_active_checks", Attribute_Replicated, &m_EnableActiveChecks);
- RegisterAttribute("enable_passive_checks", Attribute_Replicated, &m_EnablePassiveChecks);
- RegisterAttribute("force_next_check", Attribute_Replicated, &m_ForceNextCheck);
-
- RegisterAttribute("short_name", Attribute_Config, &m_ShortName);
- RegisterAttribute("host_name", Attribute_Config, &m_HostName);
-
- RegisterAttribute("acknowledgement", Attribute_Replicated, &m_Acknowledgement);
- RegisterAttribute("acknowledgement_expiry", Attribute_Replicated, &m_AcknowledgementExpiry);
-
- RegisterAttribute("comments", Attribute_Replicated, &m_Comments);
-
- RegisterAttribute("downtimes", Attribute_Replicated, &m_Downtimes);
-
- RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
- RegisterAttribute("force_next_notification", Attribute_Replicated, &m_ForceNextNotification);
-
- RegisterAttribute("flapping_positive", Attribute_Replicated, &m_FlappingPositive);
- RegisterAttribute("flapping_negative", Attribute_Replicated, &m_FlappingNegative);
- RegisterAttribute("flapping_lastchange", Attribute_Replicated, &m_FlappingLastChange);
- RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold);
- RegisterAttribute("enable_flapping", Attribute_Replicated, &m_EnableFlapping);
+ DynamicObject::Start();
SetSchedulingOffset(rand());
+ UpdateNextCheck();
- boost::call_once(m_OnceFlag, &Service::Initialize);
-}
+ Array::Ptr groups = GetGroups();
-Service::~Service(void)
-{
- ServiceGroup::InvalidateMembersCache();
- Host::InvalidateServicesCache();
- Service::InvalidateDowntimesCache();
- Service::InvalidateCommentsCache();
-}
+ if (groups) {
+ BOOST_FOREACH(const String& name, groups) {
+ ServiceGroup::Ptr sg = ServiceGroup::GetByName(name);
-void Service::Initialize(void)
-{
- m_Endpoint = Endpoint::MakeEndpoint("service", false);
- m_Endpoint->RegisterTopicHandler("icinga::NotificationSent",
- boost::bind(&Service::NotificationSentRequestHandler, _3));
- m_Endpoint->RegisterTopicHandler("icinga::Downtime",
- boost::bind(&Service::DowntimeRequestHandler, _3));
- m_Endpoint->RegisterTopicHandler("icinga::Flapping",
- boost::bind(&Service::FlappingRequestHandler, _3));
-}
-
-void Service::OnRegistrationCompleted(void)
-{
- ASSERT(!OwnsLock());
+ if (sg)
+ sg->AddMember(GetSelf());
+ }
+ }
- DynamicObject::OnRegistrationCompleted();
+ AddDowntimesToCache();
+ AddCommentsToCache();
- InvalidateNotificationsCache();
+ Host::Ptr host = GetHost();
+ if (host)
+ host->AddService(GetSelf());
}
String Service::GetDisplayName(void) const
return m_DisplayName;
}
-Service::Ptr Service::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("Service", name);
-
- return dynamic_pointer_cast<Service>(configObject);
-}
-
Service::Ptr Service::GetByNamePair(const String& hostName, const String& serviceName)
{
if (!hostName.IsEmpty()) {
void Service::SetAcknowledgement(AcknowledgementType acknowledgement)
{
m_Acknowledgement = acknowledgement;
- Touch("acknowledgement");
}
bool Service::IsAcknowledged(void)
void Service::SetAcknowledgementExpiry(double timestamp)
{
m_AcknowledgementExpiry = timestamp;
- Touch("acknowledgement_expiry");
}
void Service::AcknowledgeProblem(const String& author, const String& comment, AcknowledgementType type, double expiry)
(void) AddComment(CommentAcknowledgement, author, comment, 0);
- RequestNotifications(NotificationAcknowledgement, GetLastCheckResult(), author, comment);
+ OnNotificationsRequested(GetSelf(), NotificationAcknowledgement, GetLastCheckResult(), author, comment);
}
void Service::ClearAcknowledgement(void)
SetAcknowledgementExpiry(0);
}
-void Service::OnAttributeChanged(const String& name)
-{
- ASSERT(!OwnsLock());
-
- Service::Ptr self = GetSelf();
-
- if (name == "current_checker")
- OnCheckerChanged(self);
- else if (name == "next_check")
- OnNextCheckChanged(self);
- else if (name == "servicegroups")
- ServiceGroup::InvalidateMembersCache();
- else if (name == "host_name" || name == "short_name") {
- Host::InvalidateServicesCache();
-
- UpdateSlaveNotifications();
- } else if (name == "downtimes")
- Service::InvalidateDowntimesCache();
- else if (name == "comments")
- Service::InvalidateCommentsCache();
- else if (name == "notifications")
- UpdateSlaveNotifications();
- else if (name == "check_interval") {
- ConfigItem::Ptr item = ConfigItem::GetObject("Service", GetName());
-
- /* update the next check timestamp if we're the owner of this service */
- if (item)
- UpdateNextCheck();
- }
-}
-
std::set<Host::Ptr> Service::GetParentHosts(void) const
{
std::set<Host::Ptr> parents;
return false;
}
+
+void Service::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("display_name", m_DisplayName);
+ bag->Set("macros", m_Macros);
+ bag->Set("hostdependencies", m_HostDependencies);
+ bag->Set("servicedependencies", m_ServiceDependencies);
+ bag->Set("servicegroups", m_ServiceGroups);
+ bag->Set("check_command", m_CheckCommand);
+ bag->Set("max_check_attempts", m_MaxCheckAttempts);
+ bag->Set("check_period", m_CheckPeriod);
+ bag->Set("check_interval", m_CheckInterval);
+ bag->Set("retry_interval", m_RetryInterval);
+ bag->Set("checkers", m_Checkers);
+ bag->Set("event_command", m_EventCommand);
+ bag->Set("volatile", m_Volatile);
+ bag->Set("short_name", m_ShortName);
+ bag->Set("host_name", m_HostName);
+ bag->Set("flapping_threshold", m_FlappingThreshold);
+ bag->Set("notifications", m_NotificationDescriptions);
+ }
+
+ bag->Set("next_check", m_NextCheck);
+ bag->Set("current_checker", m_CurrentChecker);
+ bag->Set("check_attempt", m_CheckAttempt);
+ bag->Set("state", m_State);
+ bag->Set("state_type", m_StateType);
+ bag->Set("last_state", m_LastState);
+ bag->Set("last_hard_state", m_LastHardState);
+ bag->Set("last_state_type", m_LastStateType);
+ bag->Set("last_reachable", m_LastReachable);
+ bag->Set("last_result", m_LastResult);
+ bag->Set("last_state_change", m_LastStateChange);
+ bag->Set("last_hard_state_change", m_LastHardStateChange);
+ bag->Set("last_state_ok", m_LastStateOK);
+ bag->Set("last_state_warning", m_LastStateWarning);
+ bag->Set("last_state_critical", m_LastStateCritical);
+ bag->Set("last_state_unknown", m_LastStateUnknown);
+ bag->Set("last_state_unreachable", m_LastStateUnreachable);
+ bag->Set("last_in_downtime", m_LastInDowntime);
+ bag->Set("enable_active_checks", m_EnableActiveChecks);
+ bag->Set("enable_passive_checks", m_EnablePassiveChecks);
+ bag->Set("force_next_check", m_ForceNextCheck);
+ bag->Set("acknowledgement", m_Acknowledgement);
+ bag->Set("acknowledgement_expiry", m_AcknowledgementExpiry);
+ bag->Set("comments", m_Comments);
+ bag->Set("downtimes", m_Downtimes);
+ bag->Set("enable_notifications", m_EnableNotifications);
+ bag->Set("force_next_notification", m_ForceNextNotification);
+ bag->Set("flapping_positive", m_FlappingPositive);
+ bag->Set("flapping_negative", m_FlappingNegative);
+ bag->Set("flapping_lastchange", m_FlappingLastChange);
+ bag->Set("enable_flapping", m_EnableFlapping);
+}
+
+void Service::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_DisplayName = bag->Get("display_name");
+ m_Macros = bag->Get("macros");
+ m_HostDependencies = bag->Get("hostdependencies");
+ m_ServiceDependencies = bag->Get("servicedependencies");
+ m_ServiceGroups = bag->Get("servicegroups");
+ m_CheckCommand = bag->Get("check_command");
+ m_MaxCheckAttempts = bag->Get("max_check_attempts");
+ m_CheckPeriod = bag->Get("check_period");
+ m_CheckInterval = bag->Get("check_interval");
+ m_RetryInterval = bag->Get("retry_interval");
+ m_Checkers = bag->Get("checkers");
+ m_EventCommand = bag->Get("event_command");
+ m_Volatile = bag->Get("volatile");
+ m_ShortName = bag->Get("short_name");
+ m_HostName = bag->Get("host_name");
+ m_FlappingThreshold = bag->Get("flapping_threshold");
+ m_NotificationDescriptions = bag->Get("notifications");
+ }
+
+ m_NextCheck = bag->Get("next_check");
+ m_CurrentChecker = bag->Get("current_checker");
+ m_CheckAttempt = bag->Get("check_attempt");
+ m_State = bag->Get("state");
+ m_StateType = bag->Get("state_type");
+ m_LastState = bag->Get("last_state");
+ m_LastHardState = bag->Get("last_hard_state");
+ m_LastStateType = bag->Get("last_state_type");
+ m_LastReachable = bag->Get("last_reachable");
+ m_LastResult = bag->Get("last_result");
+ m_LastStateChange = bag->Get("last_state_change");
+ m_LastHardStateChange = bag->Get("last_hard_state_change");
+ m_LastStateOK = bag->Get("last_state_ok");
+ m_LastStateWarning = bag->Get("last_state_warning");
+ m_LastStateCritical = bag->Get("last_state_critical");
+ m_LastStateUnknown = bag->Get("last_state_unknown");
+ m_LastStateUnreachable = bag->Get("last_state_unreachable");
+ m_LastInDowntime = bag->Get("last_in_downtime");
+ m_EnableActiveChecks = bag->Get("enable_active_checks");
+ m_EnablePassiveChecks = bag->Get("enable_passive_checks");
+ m_ForceNextCheck = bag->Get("force_next_check");
+ m_Acknowledgement = bag->Get("acknowledgement");
+ m_AcknowledgementExpiry = bag->Get("acknowledgement_expiry");
+ m_Comments = bag->Get("comments");
+ m_Downtimes = bag->Get("downtimes");
+ m_EnableNotifications = bag->Get("enable_notifications");
+ m_ForceNextNotification = bag->Get("force_next_notification");
+ m_FlappingPositive = bag->Get("flapping_positive");
+ m_FlappingNegative = bag->Get("flapping_negative");
+ m_FlappingLastChange = bag->Get("flapping_lastchange");
+ m_EnableFlapping = bag->Get("enable_flapping");
+}
{
FlappingStarted = 0,
FlappingDisabled = 1,
- FlappingStopped = 2
+ FlappingStopped = 2,
+ FlappingEnabled = 3
};
/**
{
public:
DECLARE_PTR_TYPEDEFS(Service);
-
- explicit Service(const Dictionary::Ptr& serializedUpdate);
- ~Service(void);
-
- static Service::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(Service);
static Service::Ptr GetByNamePair(const String& hostName, const String& serviceName);
static StateType StateTypeFromString(const String& state);
static String StateTypeToString(StateType state);
- static boost::signals2::signal<void (const Service::Ptr&)> OnCheckerChanged;
static boost::signals2::signal<void (const Service::Ptr&)> OnNextCheckChanged;
- static boost::signals2::signal<void (const Service::Ptr&, const String&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
+ static boost::signals2::signal<void (const Service::Ptr&, const Dictionary::Ptr&)> OnNewCheckResult;
+ static boost::signals2::signal<void (const Service::Ptr&, NotificationType, const Dictionary::Ptr&, const String&, const String&)> OnNotificationsRequested;
+ static boost::signals2::signal<void (const Service::Ptr&, const User::Ptr&, const NotificationType&, const Dictionary::Ptr&, const String&, const String&)> OnNotificationSentChanged;
static boost::signals2::signal<void (const Service::Ptr&, DowntimeState)> OnDowntimeChanged;
static boost::signals2::signal<void (const Service::Ptr&, FlappingState)> OnFlappingChanged;
static boost::signals2::signal<void (const Service::Ptr&, const String&, CommentChangedType)> OnCommentsChanged;
static bool IsDowntimeActive(const Dictionary::Ptr& downtime);
static bool IsDowntimeExpired(const Dictionary::Ptr& downtime);
- static void InvalidateDowntimesCache(void);
-
bool IsInDowntime(void) const;
bool IsAcknowledged(void);
static bool IsCommentExpired(const Dictionary::Ptr& comment);
- static void InvalidateCommentsCache(void);
-
/* Notifications */
+ Dictionary::Ptr GetNotificationDescriptions(void) const;
+
bool GetEnableNotifications(void) const;
void SetEnableNotifications(bool enabled);
- void RequestNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
void SendNotifications(NotificationType type, const Dictionary::Ptr& cr, const String& author = "", const String& text = "");
std::set<Notification::Ptr> GetNotifications(void) const;
+ void AddNotification(const Notification::Ptr& notification);
+ void RemoveNotification(const Notification::Ptr& notification);
void SetForceNextNotification(bool force);
bool GetForceNextNotification(void) const;
void ResetNotificationNumbers(void);
- static void InvalidateNotificationsCache(void);
-
void UpdateSlaveNotifications(void);
/* Event Handler */
void UpdateFlappingStatus(bool stateChange);
protected:
- virtual void OnRegistrationCompleted(void);
- virtual void OnAttributeChanged(const String& name);
+ virtual void Start(void);
+
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Dictionary::Ptr m_SlaveNotifications;
-
- Attribute<String> m_DisplayName;
- Attribute<Dictionary::Ptr> m_Macros;
- Attribute<Array::Ptr> m_HostDependencies;
- Attribute<Array::Ptr> m_ServiceDependencies;
- Attribute<Array::Ptr> m_ServiceGroups;
- Attribute<String> m_ShortName;
- Attribute<long> m_Acknowledgement;
- Attribute<double> m_AcknowledgementExpiry;
- Attribute<String> m_HostName;
- Attribute<bool> m_Volatile;
+ String m_DisplayName;
+ Dictionary::Ptr m_Macros;
+ Array::Ptr m_HostDependencies;
+ Array::Ptr m_ServiceDependencies;
+ Array::Ptr m_ServiceGroups;
+ String m_ShortName;
+ Value m_Acknowledgement;
+ Value m_AcknowledgementExpiry;
+ String m_HostName;
+ Value m_Volatile;
/* Checks */
- Attribute<String> m_CheckCommand;
- Attribute<long> m_MaxCheckAttempts;
- Attribute<String> m_CheckPeriod;
- Attribute<double> m_CheckInterval;
- Attribute<double> m_RetryInterval;
- Attribute<double> m_NextCheck;
- Attribute<Array::Ptr> m_Checkers;
- Attribute<String> m_CurrentChecker;
- Attribute<long> m_CheckAttempt;
- Attribute<long> m_State;
- Attribute<long> m_StateType;
- Attribute<long> m_LastState;
- Attribute<long> m_LastHardState;
- Attribute<long> m_LastStateType;
- Attribute<bool> m_LastReachable;
- Attribute<Dictionary::Ptr> m_LastResult;
- Attribute<double> m_LastStateChange;
- Attribute<double> m_LastHardStateChange;
- Attribute<double> m_LastStateOK;
- Attribute<double> m_LastStateWarning;
- Attribute<double> m_LastStateCritical;
- Attribute<double> m_LastStateUnknown;
- Attribute<double> m_LastStateUnreachable;
- Attribute<bool> m_LastInDowntime;
- Attribute<bool> m_EnableActiveChecks;
- Attribute<bool> m_EnablePassiveChecks;
- Attribute<bool> m_ForceNextCheck;
+ String m_CheckCommand;
+ Value m_MaxCheckAttempts;
+ String m_CheckPeriod;
+ Value m_CheckInterval;
+ Value m_RetryInterval;
+ double m_NextCheck;
+ Array::Ptr m_Checkers;
+ String m_CurrentChecker;
+ Value m_CheckAttempt;
+ Value m_State;
+ Value m_StateType;
+ Value m_LastState;
+ Value m_LastHardState;
+ Value m_LastStateType;
+ Value m_LastReachable;
+ Dictionary::Ptr m_LastResult;
+ Value m_LastStateChange;
+ Value m_LastHardStateChange;
+ Value m_LastStateOK;
+ Value m_LastStateWarning;
+ Value m_LastStateCritical;
+ Value m_LastStateUnknown;
+ Value m_LastStateUnreachable;
+ bool m_LastInDowntime;
+ Value m_EnableActiveChecks;
+ Value m_EnablePassiveChecks;
+ Value m_ForceNextCheck;
bool m_CheckRunning;
long m_SchedulingOffset;
- static boost::once_flag m_OnceFlag;
- static Endpoint::Ptr m_Endpoint;
-
- static void Initialize(void);
-
/* Downtimes */
- Attribute<Dictionary::Ptr> m_Downtimes;
+ Dictionary::Ptr m_Downtimes;
static void DowntimesExpireTimerHandler(void);
- static void DowntimeRequestHandler(const RequestMessage& request);
void RemoveExpiredDowntimes(void);
- static void RefreshDowntimesCache(void);
+ void AddDowntimesToCache(void);
/* Comments */
- Attribute<Dictionary::Ptr> m_Comments;
+ Dictionary::Ptr m_Comments;
static void CommentsExpireTimerHandler(void);
- void AddCommentsToCache(void);
void RemoveExpiredComments(void);
- static void RefreshCommentsCache(void);
+ void AddCommentsToCache(void);
/* Notifications */
- Attribute<bool> m_EnableNotifications;
- Attribute<bool> m_ForceNextNotification;
+ Dictionary::Ptr m_NotificationDescriptions;
- static void RefreshNotificationsCache(void);
+ Value m_EnableNotifications;
+ Value m_ForceNextNotification;
- static void NotificationSentRequestHandler(const RequestMessage& request);
+ std::set<Notification::Ptr> m_Notifications;
/* Event Handler */
- Attribute<String> m_EventCommand;
+ String m_EventCommand;
/* Flapping */
- Attribute<bool> m_EnableFlapping;
- Attribute<long> m_FlappingPositive;
- Attribute<long> m_FlappingNegative;
- Attribute<double> m_FlappingLastChange;
- Attribute<double> m_FlappingThreshold;
-
- static void FlappingRequestHandler(const RequestMessage& request);
+ Value m_EnableFlapping;
+ long m_FlappingPositive;
+ long m_FlappingNegative;
+ Value m_FlappingLastChange;
+ Value m_FlappingThreshold;
};
}
using namespace icinga;
-static boost::mutex l_Mutex;
-static std::map<String, std::vector<Service::WeakPtr> > l_MembersCache;
-static bool l_MembersCacheNeedsUpdate = false;
-static Timer::Ptr l_MembersCacheTimer;
-boost::signals2::signal<void (void)> ServiceGroup::OnMembersChanged;
-
REGISTER_TYPE(ServiceGroup);
-ServiceGroup::ServiceGroup(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-}
-
-ServiceGroup::~ServiceGroup(void)
-{
- InvalidateMembersCache();
-}
-
-void ServiceGroup::OnRegistrationCompleted(void)
-{
- ASSERT(!OwnsLock());
-
- InvalidateMembersCache();
-}
-
String ServiceGroup::GetDisplayName(void) const
{
- if (!m_DisplayName.Get().IsEmpty())
+ if (!m_DisplayName.IsEmpty())
return m_DisplayName;
else
return GetName();
}
-ServiceGroup::Ptr ServiceGroup::GetByName(const String& name)
+std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("ServiceGroup", name);
-
- if (!configObject)
- BOOST_THROW_EXCEPTION(std::invalid_argument("ServiceGroup '" + name + "' does not exist."));
-
- return dynamic_pointer_cast<ServiceGroup>(configObject);
+ return m_Members;
}
-std::set<Service::Ptr> ServiceGroup::GetMembers(void) const
+void ServiceGroup::AddMember(const Service::Ptr& service)
{
- std::set<Service::Ptr> services;
-
- {
- boost::mutex::scoped_lock lock(l_Mutex);
-
- BOOST_FOREACH(const Service::WeakPtr& wservice, l_MembersCache[GetName()]) {
- Service::Ptr service = wservice.lock();
-
- if (!service)
- continue;
-
- services.insert(service);
- }
- }
-
- return services;
+ m_Members.insert(service);
}
-void ServiceGroup::InvalidateMembersCache(void)
+void ServiceGroup::RemoveMember(const Service::Ptr& service)
{
- boost::mutex::scoped_lock lock(l_Mutex);
-
- if (l_MembersCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
-
- if (!l_MembersCacheTimer) {
- l_MembersCacheTimer = boost::make_shared<Timer>();
- l_MembersCacheTimer->SetInterval(0.5);
- l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&ServiceGroup::RefreshMembersCache));
- l_MembersCacheTimer->Start();
- }
-
- l_MembersCacheNeedsUpdate = true;
+ m_Members.erase(service);
}
-void ServiceGroup::RefreshMembersCache(void)
+void ServiceGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
- {
- boost::mutex::scoped_lock lock(l_Mutex);
-
- if (!l_MembersCacheNeedsUpdate)
- return;
+ DynamicObject::InternalSerialize(bag, attributeTypes);
- l_MembersCacheNeedsUpdate = false;
- }
-
- Log(LogDebug, "icinga", "Updating ServiceGroup members cache.");
-
- std::map<String, std::vector<Service::WeakPtr> > newMembersCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- const Service::Ptr& service = static_pointer_cast<Service>(object);
-
- Array::Ptr groups = service->GetGroups();
-
- if (groups) {
- ObjectLock mlock(groups);
- BOOST_FOREACH(const Value& group, groups) {
- newMembersCache[group].push_back(service);
- }
- }
- }
+ if (attributeTypes & Attribute_Config)
+ bag->Set("display_name", m_DisplayName);
+}
- {
- boost::mutex::scoped_lock lock(l_Mutex);
- l_MembersCache.swap(newMembersCache);
- }
+void ServiceGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
- OnMembersChanged();
+ if (attributeTypes & Attribute_Config)
+ m_DisplayName = bag->Get("display_name");
}
#include "icinga/i2-icinga.h"
#include "icinga/service.h"
#include "base/dynamictype.h"
-#include <set>
namespace icinga
{
{
public:
DECLARE_PTR_TYPEDEFS(ServiceGroup);
-
- explicit ServiceGroup(const Dictionary::Ptr& serializedUpdate);
- ~ServiceGroup(void);
-
- static ServiceGroup::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(ServiceGroup);
String GetDisplayName(void) const;
std::set<Service::Ptr> GetMembers(void) const;
-
- static void InvalidateMembersCache(void);
-
- static boost::signals2::signal<void (void)> OnMembersChanged;
+ void AddMember(const Service::Ptr& service);
+ void RemoveMember(const Service::Ptr& service);
protected:
- virtual void OnRegistrationCompleted(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_DisplayName;
-
- static void RefreshMembersCache(void);
+ String m_DisplayName;
+ std::set<Service::Ptr> m_Members;
};
}
static Timer::Ptr l_UpdateTimer;
-TimePeriod::TimePeriod(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
+void TimePeriod::Start(void)
{
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
- RegisterAttribute("valid_begin", Attribute_Replicated, &m_ValidBegin);
- RegisterAttribute("valid_end", Attribute_Replicated, &m_ValidEnd);
- RegisterAttribute("segments", Attribute_Replicated, &m_Segments);
+ DynamicObject::Start();
if (!l_UpdateTimer) {
l_UpdateTimer = boost::make_shared<Timer>();
l_UpdateTimer->OnTimerExpired.connect(boost::bind(&TimePeriod::UpdateTimerHandler));
l_UpdateTimer->Start();
}
-}
-void TimePeriod::Start(void)
-{
/* Pre-fill the time period for the next 24 hours. */
double now = Utility::GetTime();
UpdateRegion(now, now + 24 * 3600, true);
return GetName();
}
-TimePeriod::Ptr TimePeriod::GetByName(const String& name)
+Dictionary::Ptr TimePeriod::GetRanges(void) const
{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("TimePeriod", name);
-
- return dynamic_pointer_cast<TimePeriod>(configObject);
+ return m_Ranges;
}
void TimePeriod::AddSegment(double begin, double end)
{
ASSERT(OwnsLock());
- if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin) {
+ if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin)
m_ValidBegin = begin;
- Touch("valid_begin");
- }
- if (m_ValidEnd.IsEmpty() || end > m_ValidEnd) {
+ if (m_ValidEnd.IsEmpty() || end > m_ValidEnd)
m_ValidEnd = end;
- Touch("valid_end");
- }
Array::Ptr segments = m_Segments;
}
segments->Add(segment);
- Touch("segments");
}
void TimePeriod::AddSegment(const Dictionary::Ptr& segment)
{
ASSERT(OwnsLock());
- if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin) {
+ if (m_ValidBegin.IsEmpty() || begin < m_ValidBegin)
m_ValidBegin = begin;
- Touch("valid_begin");
- }
- if (m_ValidEnd.IsEmpty() || end > m_ValidEnd) {
+ if (m_ValidEnd.IsEmpty() || end > m_ValidEnd)
m_ValidEnd = end;
- Touch("valid_end");
- }
Array::Ptr segments = m_Segments;
}
m_Segments = newSegments;
- Touch("segments");
}
void TimePeriod::PurgeSegments(double end)
return;
m_ValidBegin = end;
- Touch("valid_begin");
Array::Ptr segments = m_Segments;
}
m_Segments = newSegments;
- Touch("segments");
}
void TimePeriod::UpdateRegion(double begin, double end, bool clearExisting)
{
double now = Utility::GetTime();
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("TimePeriod")) {
- TimePeriod::Ptr tp = static_pointer_cast<TimePeriod>(object);
-
+ BOOST_FOREACH(const TimePeriod::Ptr& tp, DynamicType::GetObjects<TimePeriod>()) {
/* Only update time periods that have been defined on this node. */
if (!ConfigItem::GetObject("TimePeriod", tp->GetName()))
continue;
Log(LogDebug, "icinga", "---");
}
+
+void TimePeriod::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("display_name", m_DisplayName);
+ bag->Set("ranges", m_Ranges);
+ }
+
+ bag->Set("valid_begin", m_ValidBegin);
+ bag->Set("valid_end", m_ValidEnd);
+ bag->Set("segments", m_Segments);
+}
+
+void TimePeriod::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_DisplayName = bag->Get("display_name");
+ m_Ranges = bag->Get("ranges");
+ }
+
+ m_ValidBegin = bag->Get("valid_begin");
+ m_ValidEnd = bag->Get("valid_end");
+ m_Segments = bag->Get("segments");
+}
{
public:
DECLARE_PTR_TYPEDEFS(TimePeriod);
-
- explicit TimePeriod(const Dictionary::Ptr& serializedUpdate);
-
- static TimePeriod::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(TimePeriod);
String GetDisplayName(void) const;
+ Dictionary::Ptr GetRanges(void) const;
virtual void Start(void);
static Array::Ptr EmptyTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
static Array::Ptr EvenMinutesTimePeriodUpdate(const TimePeriod::Ptr& tp, double begin, double end);
+protected:
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<String> m_DisplayName;
- Attribute<double> m_ValidBegin;
- Attribute<double> m_ValidEnd;
- Attribute<Array::Ptr> m_Segments;
+ String m_DisplayName;
+ Dictionary::Ptr m_Ranges;
+ Value m_ValidBegin;
+ Value m_ValidEnd;
+ Array::Ptr m_Segments;
void AddSegment(double s, double end);
void AddSegment(const Dictionary::Ptr& segment);
REGISTER_TYPE(User);
-User::User(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
+void User::Start(void)
{
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
- RegisterAttribute("macros", Attribute_Config, &m_Macros);
- RegisterAttribute("groups", Attribute_Config, &m_Groups);
- RegisterAttribute("enable_notifications", Attribute_Config, &m_EnableNotifications);
- RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
- RegisterAttribute("notification_type_filter", Attribute_Config, &m_NotificationTypeFilter);
- RegisterAttribute("notification_state_filter", Attribute_Config, &m_NotificationStateFilter);
- RegisterAttribute("last_notification", Attribute_Replicated, &m_LastNotification);
-}
+ DynamicObject::Start();
-User::~User(void)
-{
- UserGroup::InvalidateMembersCache();
-}
+ Array::Ptr groups = GetGroups();
-void User::OnAttributeChanged(const String& name)
-{
- ASSERT(!OwnsLock());
+ if (groups) {
+ BOOST_FOREACH(const String& name, groups) {
+ UserGroup::Ptr ug = UserGroup::GetByName(name);
- if (name == "groups")
- UserGroup::InvalidateMembersCache();
+ if (ug)
+ ug->AddMember(GetSelf());
+ }
+ }
}
-User::Ptr User::GetByName(const String& name)
+void User::Stop(void)
{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("User", name);
+ DynamicObject::Stop();
+
+ Array::Ptr groups = GetGroups();
+
+ if (groups) {
+ BOOST_FOREACH(const String& name, groups) {
+ UserGroup::Ptr ug = UserGroup::GetByName(name);
- return dynamic_pointer_cast<User>(configObject);
+ if (ug)
+ ug->RemoveMember(GetSelf());
+ }
+ }
}
String User::GetDisplayName(void) const
void User::SetEnableNotifications(bool enabled)
{
m_EnableNotifications = enabled;
- Touch("enable_notifications");
}
TimePeriod::Ptr User::GetNotificationPeriod(void) const
void User::SetLastNotification(double ts)
{
m_LastNotification = ts;
- Touch("last_notification");
}
double User::GetLastNotification(void) const
return m_LastNotification;
}
-bool User::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
+bool User::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *result) const
{
if (macro == "CONTACTNAME") {
*result = GetName();
}
}
+void User::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("display_name", m_DisplayName);
+ bag->Set("macros", m_Macros);
+ bag->Set("groups", m_Groups);
+ bag->Set("notification_period", m_NotificationPeriod);
+ bag->Set("notification_type_filter", m_NotificationTypeFilter);
+ bag->Set("notification_state_filter", m_NotificationStateFilter);
+ }
+
+ bag->Set("enable_notifications", m_EnableNotifications);
+ bag->Set("last_notification", m_LastNotification);
+}
+
+void User::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_DisplayName = bag->Get("display_name");
+ m_Macros = bag->Get("macros");
+ m_Groups = bag->Get("groups");
+ m_NotificationPeriod = bag->Get("notification_period");
+ m_NotificationTypeFilter = bag->Get("notification_type_filter");
+ m_NotificationStateFilter = bag->Get("notification_state_filter");
+ }
+
+ m_EnableNotifications = bag->Get("enable_notifications");
+ m_LastNotification = bag->Get("last_notification");
+}
{
public:
DECLARE_PTR_TYPEDEFS(User);
-
- explicit User(const Dictionary::Ptr& serializedUpdate);
- ~User(void);
-
- static User::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(User);
String GetDisplayName(void) const;
Array::Ptr GetGroups(void) const;
virtual bool ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const;
protected:
- virtual void OnAttributeChanged(const String& name);
+ virtual void Start(void);
+ virtual void Stop(void);
+
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_DisplayName;
- Attribute<Dictionary::Ptr> m_Macros;
- Attribute<Array::Ptr> m_Groups;
- Attribute<bool> m_EnableNotifications;
- Attribute<String> m_NotificationPeriod;
- Attribute<long> m_NotificationTypeFilter;
- Attribute<long> m_NotificationStateFilter;
- Attribute<double> m_LastNotification;
+ String m_DisplayName;
+ Dictionary::Ptr m_Macros;
+ Array::Ptr m_Groups;
+ Value m_EnableNotifications;
+ String m_NotificationPeriod;
+ Value m_NotificationTypeFilter;
+ Value m_NotificationStateFilter;
+ double m_LastNotification;
};
}
using namespace icinga;
-static boost::mutex l_Mutex;
-static std::map<String, std::vector<User::WeakPtr> > l_MembersCache;
-static bool l_MembersCacheNeedsUpdate = false;
-static Timer::Ptr l_MembersCacheTimer;
-boost::signals2::signal<void (void)> UserGroup::OnMembersChanged;
-
REGISTER_TYPE(UserGroup);
-UserGroup::UserGroup(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("display_name", Attribute_Config, &m_DisplayName);
-}
-
-UserGroup::~UserGroup(void)
-{
- InvalidateMembersCache();
-}
-
-void UserGroup::OnRegistrationCompleted(void)
-{
- ASSERT(!OwnsLock());
-
- InvalidateMembersCache();
-}
-
String UserGroup::GetDisplayName(void) const
{
if (!m_DisplayName.IsEmpty())
return GetName();
}
-UserGroup::Ptr UserGroup::GetByName(const String& name)
+std::set<User::Ptr> UserGroup::GetMembers(void) const
{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("UserGroup", name);
-
- if (!configObject)
- BOOST_THROW_EXCEPTION(std::invalid_argument("UserGroup '" + name + "' does not exist."));
-
- return dynamic_pointer_cast<UserGroup>(configObject);
+ return m_Members;
}
-std::set<User::Ptr> UserGroup::GetMembers(void) const
+void UserGroup::AddMember(const User::Ptr& user)
{
- std::set<User::Ptr> users;
-
- {
- boost::mutex::scoped_lock lock(l_Mutex);
-
- BOOST_FOREACH(const User::WeakPtr& wuser, l_MembersCache[GetName()]) {
- User::Ptr user = wuser.lock();
-
- if (!user)
- continue;
-
- users.insert(user);
- }
- }
-
- return users;
+ m_Members.insert(user);
}
-void UserGroup::InvalidateMembersCache(void)
+void UserGroup::RemoveMember(const User::Ptr& user)
{
- boost::mutex::scoped_lock lock(l_Mutex);
-
- if (l_MembersCacheNeedsUpdate)
- return; /* Someone else has already requested a refresh. */
-
- if (!l_MembersCacheTimer) {
- l_MembersCacheTimer = boost::make_shared<Timer>();
- l_MembersCacheTimer->SetInterval(0.5);
- l_MembersCacheTimer->OnTimerExpired.connect(boost::bind(&UserGroup::RefreshMembersCache));
- l_MembersCacheTimer->Start();
- }
-
- l_MembersCacheNeedsUpdate = true;
+ m_Members.erase(user);
}
-void UserGroup::RefreshMembersCache(void)
+void UserGroup::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
{
- {
- boost::mutex::scoped_lock lock(l_Mutex);
-
- if (!l_MembersCacheNeedsUpdate)
- return;
+ DynamicObject::InternalSerialize(bag, attributeTypes);
- l_MembersCacheNeedsUpdate = false;
- }
-
- Log(LogDebug, "icinga", "Updating UserGroup members cache.");
-
- std::map<String, std::vector<User::WeakPtr> > newMembersCache;
-
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
- const User::Ptr& user = static_pointer_cast<User>(object);
-
- Array::Ptr groups = user->GetGroups();
-
- if (groups) {
- ObjectLock mlock(groups);
- BOOST_FOREACH(const Value& group, groups) {
- newMembersCache[group].push_back(user);
- }
- }
- }
+ if (attributeTypes & Attribute_Config)
+ bag->Set("display_name", m_DisplayName);
+}
- {
- boost::mutex::scoped_lock lock(l_Mutex);
- l_MembersCache.swap(newMembersCache);
- }
+void UserGroup::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
- OnMembersChanged();
+ if (attributeTypes & Attribute_Config)
+ m_DisplayName = bag->Get("display_name");
}
{
public:
DECLARE_PTR_TYPEDEFS(UserGroup);
-
- explicit UserGroup(const Dictionary::Ptr& serializedUpdate);
- ~UserGroup(void);
-
- static UserGroup::Ptr GetByName(const String& name);
+ DECLARE_TYPENAME(UserGroup);
String GetDisplayName(void) const;
std::set<User::Ptr> GetMembers(void) const;
-
- static void InvalidateMembersCache(void);
-
- static boost::signals2::signal<void (void)> OnMembersChanged;
+ void AddMember(const User::Ptr& user);
+ void RemoveMember(const User::Ptr& user);
protected:
- virtual void OnRegistrationCompleted(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
private:
- Attribute<String> m_DisplayName;
-
- static void RefreshMembersCache(void);
+ String m_DisplayName;
+ std::set<User::Ptr> m_Members;
};
}
-#endif /* HOSTGROUP_H */
+#endif /* USERGROUP_H */
#include "ido/dbconnection.h"
#include "ido/dbvalue.h"
#include "icinga/icingaapplication.h"
+#include "icinga/host.h"
+#include "icinga/service.h"
#include "base/dynamictype.h"
#include "base/utility.h"
#include "base/initialize.h"
INITIALIZE_ONCE(DbConnection, &DbConnection::StaticInitialize);
-DbConnection::DbConnection(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("table_prefix", Attribute_Config, &m_TablePrefix);
-}
-
void DbConnection::Start(void)
{
+ DynamicObject::Start();
+
DbObject::OnRegistered.connect(boost::bind(&DbConnection::ActivateObject, this, _1));
DbObject::OnUnregistered.connect(boost::bind(&DbConnection::DeactivateObject, this, _1));
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
query3.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
DbObject::OnQuery(query3);
- InsertRuntimeVariable("total_services", DynamicType::GetObjects("Service").size());
- InsertRuntimeVariable("total_scheduled_services", DynamicType::GetObjects("Service").size());
- InsertRuntimeVariable("total_hosts", DynamicType::GetObjects("Host").size());
- InsertRuntimeVariable("total_scheduled_hosts", DynamicType::GetObjects("Host").size());
+ InsertRuntimeVariable("total_services", DynamicType::GetObjects<Service>().size());
+ InsertRuntimeVariable("total_scheduled_services", DynamicType::GetObjects<Service>().size());
+ InsertRuntimeVariable("total_hosts", DynamicType::GetObjects<Host>().size());
+ InsertRuntimeVariable("total_scheduled_hosts", DynamicType::GetObjects<Host>().size());
}
void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref)
}
}
}
+
+void DbConnection::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config)
+ bag->Set("table_prefix", m_TablePrefix);
+}
+
+void DbConnection::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config)
+ m_TablePrefix = bag->Get("table_prefix");
+}
\ No newline at end of file
public:
DECLARE_PTR_TYPEDEFS(DbConnection);
- DbConnection(const Dictionary::Ptr& serializedUpdate);
-
static void StaticInitialize(void);
void SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref);
protected:
virtual void Start(void);
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
virtual void ExecuteQuery(const DbQuery& query) = 0;
virtual void ActivateObject(const DbObject::Ptr& dbobj) = 0;
virtual void DeactivateObject(const DbObject::Ptr& dbobj) = 0;
void UpdateAllObjects(void);
private:
- Attribute<String> m_TablePrefix;
+ String m_TablePrefix;
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
std::map<DbObject::Ptr, DbReference> m_InsertIDs;
static void InsertRuntimeVariable(const String& key, const Value& value);
static void ProgramStatusHandler(void);
-
- friend class DbType;
};
}
void DbObject::StaticInitialize(void)
{
- DynamicObject::OnRegistered.connect(boost::bind(&DbObject::ObjectRegisteredHandler, _1));
- DynamicObject::OnUnregistered.connect(boost::bind(&DbObject::ObjectUnregisteredHandler, _1));
- DynamicObject::OnAttributesChanged.connect(boost::bind(&DbObject::AttributesChangedHandler, _1, _2));
+ DynamicObject::OnStarted.connect(boost::bind(&DbObject::ObjectStartedHandler, _1));
+ DynamicObject::OnStopped.connect(boost::bind(&DbObject::ObjectStoppedHandler, _1));
+
+ DynamicObject::OnStateChanged.connect(boost::bind(&DbObject::StateChangedHandler, _1));
}
void DbObject::SetObject(const DynamicObject::Ptr& object)
return m_LastStatusUpdate;
}
-bool DbObject::IsConfigAttribute(const String& attribute) const
-{
- DynamicObject::Ptr object = GetObject();
- ObjectLock olock(object);
- DynamicObject::AttributeConstIterator it;
-
- it = object->GetAttributes().find(attribute);
-
- if (it == object->GetAttributes().end())
- return false;
-
- return (it->second.GetType() == Attribute_Config);
-}
-
bool DbObject::IsStatusAttribute(const String&) const
{
return false;
return dbobj;
}
-void DbObject::ObjectRegisteredHandler(const DynamicObject::Ptr& object)
+void DbObject::ObjectStartedHandler(const DynamicObject::Ptr& object)
{
DbObject::Ptr dbobj = GetOrCreateByObject(object);
dbobj->SendStatusUpdate();
}
-void DbObject::ObjectUnregisteredHandler(const DynamicObject::Ptr& object)
+void DbObject::ObjectStoppedHandler(const DynamicObject::Ptr& object)
{
DbObject::Ptr dbobj = GetOrCreateByObject(object);
}
}
-void DbObject::AttributesChangedHandler(const DynamicObject::Ptr& object, const std::set<String, string_iless>& attributes)
+void DbObject::StateChangedHandler(const DynamicObject::Ptr& object)
{
DbObject::Ptr dbobj = GetOrCreateByObject(object);
if (!dbobj)
return;
- bool configUpdate = false, statusUpdate = false;
-
- BOOST_FOREACH(const String& attribute, attributes) {
- if (!configUpdate && dbobj->IsConfigAttribute(attribute))
- configUpdate = true;
-
- if (!statusUpdate && dbobj->IsStatusAttribute(attribute))
- statusUpdate = true;
- }
-
- if (configUpdate)
- dbobj->SendConfigUpdate();
-
- if (statusUpdate)
- dbobj->SendStatusUpdate();
+ dbobj->SendStatusUpdate();
}
#include "ido/dbquery.h"
#include "ido/dbtype.h"
#include "base/dynamicobject.h"
+#include <boost/smart_ptr.hpp>
namespace icinga
{
protected:
DbObject(const boost::shared_ptr<DbType>& type, const String& name1, const String& name2);
- virtual bool IsConfigAttribute(const String& attribute) const;
virtual bool IsStatusAttribute(const String& attribute) const;
virtual void OnConfigUpdate(void);
double m_LastConfigUpdate;
double m_LastStatusUpdate;
- friend boost::shared_ptr<DbObject> boost::make_shared<>(const icinga::String&, const icinga::String&);
-
- static void ObjectRegisteredHandler(const DynamicObject::Ptr& object);
- static void ObjectUnregisteredHandler(const DynamicObject::Ptr& object);
- static void AttributesChangedHandler(const DynamicObject::Ptr& object, const std::set<String, string_iless>& attributes);
- //static void TransactionClosingHandler(double tx, const std::set<DynamicObject::WeakPtr>& modifiedObjects);
- //static void FlushObjectHandler(double tx, const DynamicObject::Ptr& object);
+ static void ObjectStartedHandler(const DynamicObject::Ptr& object);
+ static void ObjectStoppedHandler(const DynamicObject::Ptr& object);
+ static void StateChangedHandler(const DynamicObject::Ptr& object);
friend class DbType;
};
protected:
DbValue(DbValueType type, const Value& value);
+ friend DbValue::Ptr boost::make_shared<DbValue, DbValueType, Value>(const icinga::DbValueType&, const icinga::Value&);
+
private:
DbValueType m_Type;
Value m_Value;
-
- friend boost::shared_ptr<DbValue> boost::make_shared<>(const icinga::DbValueType&, const double&);
- friend boost::shared_ptr<DbValue> boost::make_shared<>(const icinga::DbValueType&, const icinga::Value&);
};
}
using namespace icinga;
REGISTER_DBTYPE(HostGroup, "hostgroup", DbObjectTypeHostGroup, "hostgroup_object_id", HostGroupDbObject);
-INITIALIZE_ONCE(HostGroupDbObject, &HostGroupDbObject::StaticInitialize);
HostGroupDbObject::HostGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
: DbObject(type, name1, name2)
{ }
-void HostGroupDbObject::StaticInitialize(void)
-{
- HostGroup::OnMembersChanged.connect(boost::bind(&HostGroupDbObject::MembersChangedHandler, HostGroup::Ptr()));
-}
-
Dictionary::Ptr HostGroupDbObject::GetConfigFields(void) const
{
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
void HostGroupDbObject::OnConfigUpdate(void)
{
HostGroup::Ptr group = static_pointer_cast<HostGroup>(GetObject());
- MembersChangedHandler(group);
-}
-void HostGroupDbObject::MembersChangedHandler(const HostGroup::Ptr& hgfilter)
-{
DbQuery query1;
query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
query1.Type = DbQueryDelete;
query1.WhereCriteria = boost::make_shared<Dictionary>();
- query1.WhereCriteria->Set("instance_id", 0);
+ query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
OnQuery(query1);
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("HostGroup")) {
- HostGroup::Ptr hg = static_pointer_cast<HostGroup>(object);
-
- if (hgfilter && hg != hgfilter)
- continue;
-
- BOOST_FOREACH(const Host::Ptr& host, hg->GetMembers()) {
- DbQuery query2;
- query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
- query2.Type = DbQueryInsert;
- query2.Fields = boost::make_shared<Dictionary>();
- query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
- query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(hg));
- query2.Fields->Set("host_object_id", host);
- OnQuery(query2);
- }
+ BOOST_FOREACH(const Host::Ptr& host, group->GetMembers()) {
+ DbQuery query2;
+ query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
+ query2.Type = DbQueryInsert;
+ query2.Fields = boost::make_shared<Dictionary>();
+ query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+ query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
+ query2.Fields->Set("host_object_id", host);
+ OnQuery(query2);
}
}
HostGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
- static void StaticInitialize(void);
-
virtual Dictionary::Ptr GetConfigFields(void) const;
virtual Dictionary::Ptr GetStatusFields(void) const;
/* we cannot determine which comment id is deleted
* id cache may not be in sync
*/
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
if (svcfilter && svcfilter != service)
continue;
/* we cannot determine which downtime id is deleted
* id cache may not be in sync
*/
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Service")) {
- Service::Ptr service = static_pointer_cast<Service>(object);
-
+ BOOST_FOREACH(const Service::Ptr& service, DynamicType::GetObjects<Service>()) {
if (svcfilter && svcfilter != service)
continue;
void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const Dictionary::Ptr& downtime)
{
- unsigned long entry_time = static_cast<long>(downtime->Get("entry_time"));
- unsigned long entry_time_usec = (downtime->Get("entry_time") - entry_time) * 1000 * 1000;
-
Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
- fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
+ fields1->Set("entry_time", DbValue::FromTimestamp(downtime->Get("entry_time")));
fields1->Set("object_id", object);
if (object->GetType() == DynamicType::GetByName("Host")) {
using namespace icinga;
REGISTER_DBTYPE(ServiceGroup, "servicegroup", DbObjectTypeServiceGroup, "servicegroup_object_id", ServiceGroupDbObject);
-INITIALIZE_ONCE(ServiceGroupDbObject, &ServiceGroupDbObject::StaticInitialize);
ServiceGroupDbObject::ServiceGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
: DbObject(type, name1, name2)
{ }
-void ServiceGroupDbObject::StaticInitialize(void)
-{
- ServiceGroup::OnMembersChanged.connect(boost::bind(&ServiceGroupDbObject::MembersChangedHandler, ServiceGroup::Ptr()));
-}
-
Dictionary::Ptr ServiceGroupDbObject::GetConfigFields(void) const
{
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
{
ServiceGroup::Ptr group = static_pointer_cast<ServiceGroup>(GetObject());
- MembersChangedHandler(group);
-}
-
-void ServiceGroupDbObject::MembersChangedHandler(const ServiceGroup::Ptr& sgfilter)
-{
DbQuery query1;
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
query1.Type = DbQueryDelete;
query1.WhereCriteria = boost::make_shared<Dictionary>();
- query1.WhereCriteria->Set("instance_id", 0);
+ query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
OnQuery(query1);
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("ServiceGroup")) {
- ServiceGroup::Ptr sg = static_pointer_cast<ServiceGroup>(object);
-
- if (sgfilter && sgfilter != sg)
- continue;
-
- BOOST_FOREACH(const Service::Ptr& service, sg->GetMembers()) {
- DbQuery query2;
- query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
- query2.Type = DbQueryInsert;
- query2.Fields = boost::make_shared<Dictionary>();
- query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
- query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(sg));
- query2.Fields->Set("service_object_id", service);
- OnQuery(query2);
- }
+ BOOST_FOREACH(const Service::Ptr& service, group->GetMembers()) {
+ DbQuery query2;
+ query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
+ query2.Type = DbQueryInsert;
+ query2.Fields = boost::make_shared<Dictionary>();
+ query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+ query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
+ query2.Fields->Set("service_object_id", service);
+ OnQuery(query2);
}
}
ServiceGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
- static void StaticInitialize(void);
-
virtual Dictionary::Ptr GetConfigFields(void) const;
virtual Dictionary::Ptr GetStatusFields(void) const;
protected:
virtual void OnConfigUpdate(void);
-
-private:
- static void MembersChangedHandler(const ServiceGroup::Ptr& sgfilter);
};
}
query_del1.WhereCriteria->Set("timeperiod_id", DbValue::FromObjectInsertID(tp));
OnQuery(query_del1);
- Dictionary::Ptr ranges = tp->Get("ranges");
+ Dictionary::Ptr ranges = tp->GetRanges();
if (!ranges)
return;
using namespace icinga;
REGISTER_DBTYPE(UserGroup, "contactgroup", DbObjectTypeContactGroup, "contactgroup_object_id", UserGroupDbObject);
-INITIALIZE_ONCE(UserGroupDbObject, &UserGroupDbObject::StaticInitialize);
UserGroupDbObject::UserGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
: DbObject(type, name1, name2)
{ }
-void UserGroupDbObject::StaticInitialize(void)
-{
- UserGroup::OnMembersChanged.connect(boost::bind(&UserGroupDbObject::MembersChangedHandler, UserGroup::Ptr()));
-}
-
Dictionary::Ptr UserGroupDbObject::GetConfigFields(void) const
{
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
{
UserGroup::Ptr group = static_pointer_cast<UserGroup>(GetObject());
- MembersChangedHandler(group);
-}
-
-void UserGroupDbObject::MembersChangedHandler(const UserGroup::Ptr& ugfilter)
-{
DbQuery query1;
query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
query1.Type = DbQueryDelete;
query1.WhereCriteria = boost::make_shared<Dictionary>();
query1.WhereCriteria->Set("instance_id", 0);
+ query1.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
OnQuery(query1);
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
- UserGroup::Ptr ug = static_pointer_cast<UserGroup>(object);
-
- if (ugfilter && ugfilter != ug)
- continue;
-
- BOOST_FOREACH(const User::Ptr& user, ug->GetMembers()) {
- DbQuery query2;
- query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
- query2.Type = DbQueryInsert;
- query2.Fields = boost::make_shared<Dictionary>();
- query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
- query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(ug));
- query2.Fields->Set("contact_object_id", user);
- OnQuery(query2);
- }
+ BOOST_FOREACH(const User::Ptr& user, group->GetMembers()) {
+ DbQuery query2;
+ query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
+ query2.Type = DbQueryInsert;
+ query2.Fields = boost::make_shared<Dictionary>();
+ query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+ query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
+ query2.Fields->Set("contact_object_id", user);
+ OnQuery(query2);
}
}
UserGroupDbObject(const DbType::Ptr& type, const String& name1, const String& name2);
- static void StaticInitialize(void);
-
virtual Dictionary::Ptr GetConfigFields(void) const;
virtual Dictionary::Ptr GetStatusFields(void) const;
protected:
virtual void OnConfigUpdate(void);
-
-private:
- static void MembersChangedHandler(const UserGroup::Ptr& ugfilter);
};
}
String name = PyString_AsString(pname);
- DynamicObject::Ptr object = DynamicObject::GetObject(type, name);
+ DynamicType::Ptr dtype = DynamicType::GetByName(type);
+
+ if (!dtype)
+ BOOST_THROW_EXCEPTION(std::invalid_argument("Type '" + type + "' does not exist."));
+
+ DynamicObject::Ptr object = dtype->GetObject(name);
if (!object)
BOOST_THROW_EXCEPTION(std::invalid_argument("Object '" + name + "' of type '" + type + "' does not exist."));
boost::signals2::signal<void (const Endpoint::Ptr&)> Endpoint::OnConnected;
-/**
- * Constructor for the Endpoint class.
- *
- * @param properties A serialized dictionary containing attributes.
- */
-Endpoint::Endpoint(const Dictionary::Ptr& serializedUpdate)
- : DynamicObject(serializedUpdate)
-{
- RegisterAttribute("local", Attribute_Config, &m_Local);
-
- RegisterAttribute("node", Attribute_Replicated, &m_Node);
- RegisterAttribute("service", Attribute_Replicated, &m_Service);
- RegisterAttribute("subscriptions", Attribute_Replicated, &m_Subscriptions);
-}
-
-Endpoint::~Endpoint(void)
-{ }
-
-/**
- * Retrieves an endpoint by name.
- *
- * @param name The name of the endpoint.
- * @returns The endpoint.
- */
-Endpoint::Ptr Endpoint::GetByName(const String& name)
-{
- DynamicObject::Ptr configObject = DynamicObject::GetObject("Endpoint", name);
-
- return dynamic_pointer_cast<Endpoint>(configObject);
-}
-
/**
* Helper function for creating new endpoint objects.
*
ConfigItemBuilder::Ptr endpointConfig = boost::make_shared<ConfigItemBuilder>();
endpointConfig->SetType("Endpoint");
endpointConfig->SetName((!replicated && local) ? "local:" + name : name);
- endpointConfig->SetLocal(!replicated);
+ //TODO: endpointConfig->SetLocal(!replicated);
endpointConfig->AddExpression("local", OperatorSet, local);
ConfigItem::Ptr item = endpointConfig->Compile();
void Endpoint::ClearSubscriptions(void)
{
m_Subscriptions = Empty;
- Touch("subscriptions");
}
Dictionary::Ptr Endpoint::GetSubscriptions(void) const
{
subscriptions->Seal();
m_Subscriptions = subscriptions;
- Touch("subscriptions");
}
void Endpoint::RegisterTopicHandler(const String& topic, const boost::function<Endpoint::Callback>& callback)
return m_Service;
}
+
+void Endpoint::InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const
+{
+ DynamicObject::InternalSerialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ bag->Set("local", m_Local);
+ bag->Set("node", m_Node);
+ bag->Set("service", m_Service);
+ }
+
+ bag->Set("subscriptions", m_Subscriptions);
+}
+
+void Endpoint::InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes)
+{
+ DynamicObject::InternalDeserialize(bag, attributeTypes);
+
+ if (attributeTypes & Attribute_Config) {
+ m_Local = bag->Get("local");
+ m_Node = bag->Get("node");
+ m_Service = bag->Get("service");
+ }
+
+ bag->Set("subscriptions", m_Subscriptions);
+}
\ No newline at end of file
{
public:
DECLARE_PTR_TYPEDEFS(Endpoint);
+ DECLARE_TYPENAME(Endpoint);
typedef void (Callback)(const Endpoint::Ptr&, const Endpoint::Ptr&, const RequestMessage&);
- explicit Endpoint(const Dictionary::Ptr& serializedUpdate);
- ~Endpoint(void);
-
- static Endpoint::Ptr GetByName(const String& name);
-
Stream::Ptr GetClient(void) const;
void SetClient(const Stream::Ptr& client);
static boost::signals2::signal<void (const Endpoint::Ptr&)> OnConnected;
+protected:
+ virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
+ virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
+
private:
- Attribute<bool> m_Local;
- Attribute<Dictionary::Ptr> m_Subscriptions;
- Attribute<String> m_Node;
- Attribute<String> m_Service;
+ bool m_Local;
+ Dictionary::Ptr m_Subscriptions;
+ String m_Node;
+ String m_Service;
Stream::Ptr m_Client;
m_Identity = identity;
if (m_Endpoint)
- m_Endpoint->Unregister();
+ m_Endpoint->Stop();
- DynamicObject::Ptr object = DynamicObject::GetObject("Endpoint", identity);
+ Endpoint::Ptr endpoint = DynamicObject::GetObject<Endpoint>(identity);
- if (object)
- m_Endpoint = dynamic_pointer_cast<Endpoint>(object);
+ if (endpoint)
+ m_Endpoint = endpoint;
else
m_Endpoint = Endpoint::MakeEndpoint(identity, true, true);
}
{
/* don't forward messages between non-local endpoints, assume that
* anonymous senders (sender == null) are local */
- if ((sender && !sender->IsLocal()) && !recipient->IsLocal())
- return;
+// if ((sender && !sender->IsLocal()) && !recipient->IsLocal())
+// return;
if (ResponseMessage::IsResponseMessage(message))
recipient->ProcessResponse(sender, message);
std::vector<Endpoint::Ptr> candidates;
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
- Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
+ BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
/* don't forward messages between non-local endpoints */
- if ((sender && !sender->IsLocal()) && !endpoint->IsLocal())
- continue;
+// if ((sender && !sender->IsLocal()) && !endpoint->IsLocal())
+// continue;
if (endpoint->HasSubscription(method))
candidates.push_back(endpoint);
if (!message.GetMethod(&method))
BOOST_THROW_EXCEPTION(std::invalid_argument("Message is missing the 'method' property."));
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
- Endpoint::Ptr recipient = dynamic_pointer_cast<Endpoint>(object);
-
+ BOOST_FOREACH(const Endpoint::Ptr& recipient, DynamicType::GetObjects<Endpoint>()) {
/* don't forward messages back to the sender */
if (sender == recipient)
continue;
{
Dictionary::Ptr subscriptions = boost::make_shared<Dictionary>();
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
- Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-
+ BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
/* don't copy subscriptions from non-local endpoints or the identity endpoint */
- if (!endpoint->IsLocalEndpoint() || endpoint == m_Endpoint)
- continue;
+// if (!endpoint->IsLocalEndpoint() || endpoint == m_Endpoint)
+// continue;
Dictionary::Ptr endpointSubscriptions = endpoint->GetSubscriptions();
void EndpointManager::ReconnectTimerHandler(void)
{
- BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("Endpoint")) {
- Endpoint::Ptr endpoint = dynamic_pointer_cast<Endpoint>(object);
-
+ BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
if (endpoint->IsConnected() || endpoint == m_Endpoint)
continue;