mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Prefer boost::* over C++0x features.
This commit is contained in:
parent
d52afa080e
commit
0bd5323629
@ -11,11 +11,8 @@ libbase_la_SOURCES = \
|
|||||||
component.h \
|
component.h \
|
||||||
configobject.cpp \
|
configobject.cpp \
|
||||||
configobject.h \
|
configobject.h \
|
||||||
cxx11-compat.h \
|
|
||||||
delegate.h \
|
|
||||||
dictionary.cpp \
|
dictionary.cpp \
|
||||||
dictionary.h \
|
dictionary.h \
|
||||||
observable.h \
|
|
||||||
exception.cpp \
|
exception.cpp \
|
||||||
exception.h \
|
exception.h \
|
||||||
fifo.cpp \
|
fifo.cpp \
|
||||||
|
@ -23,6 +23,9 @@
|
|||||||
# include <ltdl.h>
|
# include <ltdl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
Application::Ptr I2_EXPORT Application::m_Instance;
|
Application::Ptr I2_EXPORT Application::m_Instance;
|
||||||
@ -210,7 +213,7 @@ Component::Ptr Application::LoadComponent(const string& path,
|
|||||||
Component::Ptr component;
|
Component::Ptr component;
|
||||||
Component *(*pCreateComponent)();
|
Component *(*pCreateComponent)();
|
||||||
|
|
||||||
Log("Loading component '" + path + "'");
|
Log(LogInformation, "base", "Loading component '" + path + "'");
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
HMODULE hModule = LoadLibrary(path.c_str());
|
HMODULE hModule = LoadLibrary(path.c_str());
|
||||||
@ -264,7 +267,7 @@ void Application::UnregisterComponent(Component::Ptr component)
|
|||||||
{
|
{
|
||||||
string name = component->GetName();
|
string name = component->GetName();
|
||||||
|
|
||||||
Log("Unloading component '" + name + "'");
|
Log(LogInformation, "base", "Unloading component '" + name + "'");
|
||||||
map<string, Component::Ptr>::iterator i = m_Components.find(name);
|
map<string, Component::Ptr>::iterator i = m_Components.find(name);
|
||||||
if (i != m_Components.end())
|
if (i != m_Components.end())
|
||||||
m_Components.erase(i);
|
m_Components.erase(i);
|
||||||
@ -291,19 +294,41 @@ Component::Ptr Application::GetComponent(const string& name) const
|
|||||||
/**
|
/**
|
||||||
* Writes a message to the application's log.
|
* Writes a message to the application's log.
|
||||||
*
|
*
|
||||||
|
* @param severity The message severity.
|
||||||
|
* @param facility The log facility.
|
||||||
* @param message The message.
|
* @param message The message.
|
||||||
*/
|
*/
|
||||||
void Application::Log(string message)
|
void Application::Log(LogSeverity severity, string facility, string message)
|
||||||
{
|
{
|
||||||
char timestamp[100];
|
char timestamp[100];
|
||||||
|
|
||||||
|
string severityStr;
|
||||||
|
switch (severity) {
|
||||||
|
case LogDebug:
|
||||||
|
severityStr = "debug";
|
||||||
|
break;
|
||||||
|
case LogInformation:
|
||||||
|
severityStr = "info";
|
||||||
|
break;
|
||||||
|
case LogWarning:
|
||||||
|
severityStr = "warning";
|
||||||
|
break;
|
||||||
|
case LogCritical:
|
||||||
|
severityStr = "critical";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(!"Invalid severity specified.");
|
||||||
|
}
|
||||||
|
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
tm tmnow = *localtime(&now);
|
tm tmnow = *localtime(&now);
|
||||||
|
|
||||||
strftime(timestamp, sizeof(timestamp), "%a %B %d %Y %H:%M:%S", &tmnow);
|
strftime(timestamp, sizeof(timestamp), "%Y/%m/%d %H:%M:%S", &tmnow);
|
||||||
|
|
||||||
cout << "[" << timestamp << "]: " << message << endl;
|
cout << "[" << timestamp << "] "
|
||||||
|
<< severityStr << "/" << facility << ": "
|
||||||
|
<< message << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -483,9 +508,9 @@ int Application::Run(int argc, char **argv)
|
|||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Application::m_Instance.reset();
|
Application::m_Instance.reset();
|
||||||
|
|
||||||
Application::Log("---");
|
Application::Log(LogCritical, "base", "---");
|
||||||
Application::Log("Exception: " + Utility::GetTypeName(ex));
|
Application::Log(LogCritical, "base", "Exception: " + Utility::GetTypeName(ex));
|
||||||
Application::Log("Message: " + string(ex.what()));
|
Application::Log(LogCritical, "base", "Message: " + string(ex.what()));
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,14 @@
|
|||||||
|
|
||||||
namespace icinga {
|
namespace icinga {
|
||||||
|
|
||||||
|
enum LogSeverity
|
||||||
|
{
|
||||||
|
LogDebug,
|
||||||
|
LogInformation,
|
||||||
|
LogWarning,
|
||||||
|
LogCritical
|
||||||
|
};
|
||||||
|
|
||||||
class Component;
|
class Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +53,7 @@ public:
|
|||||||
|
|
||||||
static void Shutdown(void);
|
static void Shutdown(void);
|
||||||
|
|
||||||
static void Log(string message);
|
static void Log(LogSeverity severity, string facility, string message);
|
||||||
|
|
||||||
shared_ptr<Component> LoadComponent(const string& path,
|
shared_ptr<Component> LoadComponent(const string& path,
|
||||||
const ConfigObject::Ptr& componentConfig);
|
const ConfigObject::Ptr& componentConfig);
|
||||||
|
@ -35,12 +35,10 @@
|
|||||||
<ClInclude Include="application.h" />
|
<ClInclude Include="application.h" />
|
||||||
<ClInclude Include="component.h" />
|
<ClInclude Include="component.h" />
|
||||||
<ClInclude Include="configobject.h" />
|
<ClInclude Include="configobject.h" />
|
||||||
<ClInclude Include="cxx11-compat.h" />
|
|
||||||
<ClInclude Include="delegate.h" />
|
|
||||||
<ClInclude Include="dictionary.h" />
|
<ClInclude Include="dictionary.h" />
|
||||||
|
<ClInclude Include="eventargs.h" />
|
||||||
<ClInclude Include="objectmap.h" />
|
<ClInclude Include="objectmap.h" />
|
||||||
<ClInclude Include="objectset.h" />
|
<ClInclude Include="objectset.h" />
|
||||||
<ClInclude Include="observable.h" />
|
|
||||||
<ClInclude Include="exception.h" />
|
<ClInclude Include="exception.h" />
|
||||||
<ClInclude Include="fifo.h" />
|
<ClInclude Include="fifo.h" />
|
||||||
<ClInclude Include="i2-base.h" />
|
<ClInclude Include="i2-base.h" />
|
||||||
|
@ -23,12 +23,12 @@ using namespace icinga;
|
|||||||
|
|
||||||
ConfigObject::ConfigObject(Dictionary::Ptr properties, const ConfigObject::Set::Ptr& container)
|
ConfigObject::ConfigObject(Dictionary::Ptr properties, const ConfigObject::Set::Ptr& container)
|
||||||
: m_Container(container ? container : GetAllObjects()),
|
: m_Container(container ? container : GetAllObjects()),
|
||||||
m_Properties(properties), m_Tags(make_shared<Dictionary>())
|
m_Properties(properties), m_Tags(boost::make_shared<Dictionary>())
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
ConfigObject::ConfigObject(string type, string name, const ConfigObject::Set::Ptr& container)
|
ConfigObject::ConfigObject(string type, string name, const ConfigObject::Set::Ptr& container)
|
||||||
: m_Container(container ? container : GetAllObjects()),
|
: m_Container(container ? container : GetAllObjects()),
|
||||||
m_Properties(make_shared<Dictionary>()), m_Tags(make_shared<Dictionary>())
|
m_Properties(boost::make_shared<Dictionary>()), m_Tags(boost::make_shared<Dictionary>())
|
||||||
{
|
{
|
||||||
SetProperty("__type", type);
|
SetProperty("__type", type);
|
||||||
SetProperty("__name", name);
|
SetProperty("__name", name);
|
||||||
@ -106,7 +106,7 @@ ObjectSet<ConfigObject::Ptr>::Ptr ConfigObject::GetAllObjects(void)
|
|||||||
static ObjectSet<ConfigObject::Ptr>::Ptr allObjects;
|
static ObjectSet<ConfigObject::Ptr>::Ptr allObjects;
|
||||||
|
|
||||||
if (!allObjects) {
|
if (!allObjects) {
|
||||||
allObjects = make_shared<ObjectSet<ConfigObject::Ptr> >();
|
allObjects = boost::make_shared<ObjectSet<ConfigObject::Ptr> >();
|
||||||
allObjects->Start();
|
allObjects->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +118,7 @@ ConfigObject::TNMap::Ptr ConfigObject::GetObjectsByTypeAndName(void)
|
|||||||
static ConfigObject::TNMap::Ptr tnmap;
|
static ConfigObject::TNMap::Ptr tnmap;
|
||||||
|
|
||||||
if (!tnmap) {
|
if (!tnmap) {
|
||||||
tnmap = make_shared<ConfigObject::TNMap>(GetAllObjects(), &ConfigObject::TypeAndNameGetter);
|
tnmap = boost::make_shared<ConfigObject::TNMap>(GetAllObjects(), &ConfigObject::TypeAndNameGetter);
|
||||||
tnmap->Start();
|
tnmap->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ bool ConfigObject::TypeAndNameGetter(const ConfigObject::Ptr& object, pair<strin
|
|||||||
|
|
||||||
function<bool (ConfigObject::Ptr)> ConfigObject::MakeTypePredicate(string type)
|
function<bool (ConfigObject::Ptr)> ConfigObject::MakeTypePredicate(string type)
|
||||||
{
|
{
|
||||||
return bind(&ConfigObject::TypePredicate, _1, type);
|
return boost::bind(&ConfigObject::TypePredicate, _1, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigObject::TypePredicate(const ConfigObject::Ptr& object, string type)
|
bool ConfigObject::TypePredicate(const ConfigObject::Ptr& object, string type)
|
||||||
@ -160,7 +160,7 @@ ConfigObject::TMap::Ptr ConfigObject::GetObjectsByType(void)
|
|||||||
static ObjectMap<string, ConfigObject::Ptr>::Ptr tmap;
|
static ObjectMap<string, ConfigObject::Ptr>::Ptr tmap;
|
||||||
|
|
||||||
if (!tmap) {
|
if (!tmap) {
|
||||||
tmap = make_shared<ConfigObject::TMap>(GetAllObjects(), &ConfigObject::TypeGetter);
|
tmap = boost::make_shared<ConfigObject::TMap>(GetAllObjects(), &ConfigObject::TypeGetter);
|
||||||
tmap->Start();
|
tmap->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Icinga 2 *
|
|
||||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License *
|
|
||||||
* as published by the Free Software Foundation; either version 2 *
|
|
||||||
* of the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the Free Software Foundation *
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef CXX11COMPAT_H
|
|
||||||
#define CXX11COMPAT_H
|
|
||||||
|
|
||||||
namespace icinga {
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
shared_ptr<T> make_shared(void)
|
|
||||||
{
|
|
||||||
return shared_ptr<T>(new T());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename TArg1>
|
|
||||||
shared_ptr<T> make_shared(const TArg1& arg1)
|
|
||||||
{
|
|
||||||
return shared_ptr<T>(new T(arg1));
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename TArg1, typename TArg2>
|
|
||||||
shared_ptr<T> make_shared(const TArg1& arg1, const TArg2& arg2)
|
|
||||||
{
|
|
||||||
return shared_ptr<T>(new T(arg1, arg2));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CXX11COMPAT_H */
|
|
@ -90,6 +90,9 @@ string Win32Exception::FormatErrorCode(int code)
|
|||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
result = string(message);
|
result = string(message);
|
||||||
LocalFree(message);
|
LocalFree(message);
|
||||||
|
|
||||||
|
/* remove trailing new-line characters */
|
||||||
|
boost::algorithm::trim_right(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "i2-base.h"
|
#include "i2-base.h"
|
||||||
|
|
||||||
|
using std::bad_alloc;
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# define HAVE_STDCXX_0X
|
|
||||||
# pragma warning(disable:4251)
|
# pragma warning(disable:4251)
|
||||||
# pragma warning(disable:4275)
|
# pragma warning(disable:4275)
|
||||||
# define _CRT_SECURE_NO_DEPRECATE
|
# define _CRT_SECURE_NO_DEPRECATE
|
||||||
@ -93,35 +92,35 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace std;
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::map;
|
||||||
|
using std::list;
|
||||||
|
using std::set;
|
||||||
|
using std::multimap;
|
||||||
|
using std::pair;
|
||||||
|
|
||||||
#ifdef HAVE_STDCXX_0X
|
using std::stringstream;
|
||||||
# include <memory>
|
|
||||||
# include <functional>
|
|
||||||
|
|
||||||
using namespace std::placeholders;
|
using std::runtime_error;
|
||||||
|
using std::logic_error;
|
||||||
#else /* HAVE_STDCXX_0X */
|
using std::invalid_argument;
|
||||||
# ifdef HAVE_BOOST
|
using std::domain_error;
|
||||||
# include <boost/smart_ptr.hpp>
|
|
||||||
# include <boost/make_shared.hpp>
|
|
||||||
# include <boost/bind.hpp>
|
|
||||||
# include <boost/function.hpp>
|
|
||||||
|
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
# else /* HAVE_BOOST */
|
|
||||||
# include <tr1/memory>
|
|
||||||
# include <tr1/functional>
|
|
||||||
# include "cxx11-compat.h"
|
|
||||||
|
|
||||||
using namespace std::tr1;
|
|
||||||
using namespace std::tr1::placeholders;
|
|
||||||
|
|
||||||
#endif /* HAVE_BOOST */
|
|
||||||
#endif /* HAVE_STDCXX_0X */
|
|
||||||
|
|
||||||
|
#include <boost/smart_ptr.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <boost/function.hpp>
|
||||||
#include <boost/signal.hpp>
|
#include <boost/signal.hpp>
|
||||||
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
|
|
||||||
|
using boost::shared_ptr;
|
||||||
|
using boost::weak_ptr;
|
||||||
|
using boost::enable_shared_from_this;
|
||||||
|
using boost::dynamic_pointer_cast;
|
||||||
|
using boost::static_pointer_cast;
|
||||||
|
using boost::function;
|
||||||
|
using boost::signal;
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
@ -43,9 +43,9 @@ public:
|
|||||||
|
|
||||||
void Start(void)
|
void Start(void)
|
||||||
{
|
{
|
||||||
m_Parent->OnObjectAdded.connect(bind(&ObjectMap::ObjectAddedHandler, this, _1));
|
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectMap::ObjectAddedHandler, this, _1));
|
||||||
m_Parent->OnObjectCommitted.connect(bind(&ObjectMap::ObjectCommittedHandler, this, _1));
|
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, this, _1));
|
||||||
m_Parent->OnObjectRemoved.connect(bind(&ObjectMap::ObjectRemovedHandler, this, _1));
|
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectMap::ObjectRemovedHandler, this, _1));
|
||||||
|
|
||||||
for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
for (typename ObjectSet<TValue>::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
||||||
AddObject(*it);
|
AddObject(*it);
|
||||||
@ -56,7 +56,7 @@ public:
|
|||||||
return m_Objects.equal_range(key);
|
return m_Objects.equal_range(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForeachObject(TKey key, function<int (const ObjectSetEventArgs<TValue>&)> callback)
|
void ForeachObject(TKey key, function<void (const ObjectSetEventArgs<TValue>&)> callback)
|
||||||
{
|
{
|
||||||
ObjectSetEventArgs<TValue> ea;
|
ObjectSetEventArgs<TValue> ea;
|
||||||
ea.Source = shared_from_this();
|
ea.Source = shared_from_this();
|
||||||
@ -105,25 +105,19 @@ private:
|
|||||||
AddObject(object);
|
AddObject(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectAddedHandler(const ObjectSetEventArgs<TValue>& ea)
|
void ObjectAddedHandler(const ObjectSetEventArgs<TValue>& ea)
|
||||||
{
|
{
|
||||||
AddObject(ea.Target);
|
AddObject(ea.Target);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
|
void ObjectCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
|
||||||
{
|
{
|
||||||
CheckObject(ea.Target);
|
CheckObject(ea.Target);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
|
void ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
|
||||||
{
|
{
|
||||||
RemoveObject(ea.Target);
|
RemoveObject(ea.Target);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,9 +49,9 @@ public:
|
|||||||
void Start(void)
|
void Start(void)
|
||||||
{
|
{
|
||||||
if (m_Parent) {
|
if (m_Parent) {
|
||||||
m_Parent->OnObjectAdded.connect(bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
|
m_Parent->OnObjectAdded.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
|
||||||
m_Parent->OnObjectCommitted.connect(bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
|
m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
|
||||||
m_Parent->OnObjectRemoved.connect(bind(&ObjectSet::ObjectRemovedHandler, this, _1));
|
m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _1));
|
||||||
|
|
||||||
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
|
||||||
CheckObject(*it);
|
CheckObject(*it);
|
||||||
@ -86,9 +86,7 @@ public:
|
|||||||
|
|
||||||
bool Contains(const TValue& object) const
|
bool Contains(const TValue& object) const
|
||||||
{
|
{
|
||||||
ObjectSet::Iterator it = m_Objects.find(object);
|
return !(m_Objects.find(object) == m_Objects.end());
|
||||||
|
|
||||||
return !(it == m_Objects.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckObject(const TValue& object)
|
void CheckObject(const TValue& object)
|
||||||
@ -121,7 +119,7 @@ public:
|
|||||||
return m_Objects.end();
|
return m_Objects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ForeachObject(function<int (const ObjectSetEventArgs<TValue>&)> callback)
|
void ForeachObject(function<void (const ObjectSetEventArgs<TValue>&)> callback)
|
||||||
{
|
{
|
||||||
ObjectSetEventArgs<TValue> ea;
|
ObjectSetEventArgs<TValue> ea;
|
||||||
ea.Source = shared_from_this();
|
ea.Source = shared_from_this();
|
||||||
@ -138,18 +136,14 @@ private:
|
|||||||
typename ObjectSet<TValue>::Ptr m_Parent;
|
typename ObjectSet<TValue>::Ptr m_Parent;
|
||||||
function<bool (const TValue&)> m_Predicate;
|
function<bool (const TValue&)> m_Predicate;
|
||||||
|
|
||||||
int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
|
void ObjectAddedOrCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
|
||||||
{
|
{
|
||||||
CheckObject(ea.Target);
|
CheckObject(ea.Target);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
|
void ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
|
||||||
{
|
{
|
||||||
RemoveObject(ea.Target);
|
RemoveObject(ea.Target);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ void Socket::Start(void)
|
|||||||
{
|
{
|
||||||
assert(m_FD != INVALID_SOCKET);
|
assert(m_FD != INVALID_SOCKET);
|
||||||
|
|
||||||
OnException.connect(bind(&Socket::ExceptionEventHandler, this, _1));
|
OnException.connect(boost::bind(&Socket::ExceptionEventHandler, this, _1));
|
||||||
|
|
||||||
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
|
Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
|
||||||
}
|
}
|
||||||
@ -171,29 +171,25 @@ int Socket::GetLastSocketError(void)
|
|||||||
*/
|
*/
|
||||||
void Socket::HandleSocketError(const std::exception& ex)
|
void Socket::HandleSocketError(const std::exception& ex)
|
||||||
{
|
{
|
||||||
// XXX, TODO: add SetErrorHandling() function
|
if (!OnError.empty()) {
|
||||||
/* if (OnError.HasObservers()) {*/
|
|
||||||
SocketErrorEventArgs sea(ex);
|
SocketErrorEventArgs sea(ex);
|
||||||
OnError(sea);
|
OnError(sea);
|
||||||
|
|
||||||
Close();
|
Close();
|
||||||
/* } else {
|
} else {
|
||||||
throw ex;
|
throw ex;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes errors that have occured for the socket.
|
* Processes errors that have occured for the socket.
|
||||||
*
|
*
|
||||||
* @param - Event arguments for the socket error.
|
* @param - Event arguments for the socket error.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int Socket::ExceptionEventHandler(const EventArgs&)
|
void Socket::ExceptionEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
HandleSocketError(SocketException(
|
HandleSocketError(SocketException(
|
||||||
"select() returned fd in except fdset", GetError()));
|
"select() returned fd in except fdset", GetError()));
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +85,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
SOCKET m_FD; /**< The socket descriptor. */
|
SOCKET m_FD; /**< The socket descriptor. */
|
||||||
|
|
||||||
int ExceptionEventHandler(const EventArgs& ea);
|
void ExceptionEventHandler(const EventArgs& ea);
|
||||||
|
|
||||||
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
|
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
|
||||||
};
|
};
|
||||||
|
@ -30,8 +30,8 @@ TcpClient::TcpClient(TcpClientRole role)
|
|||||||
{
|
{
|
||||||
m_Role = role;
|
m_Role = role;
|
||||||
|
|
||||||
m_SendQueue = make_shared<FIFO>();
|
m_SendQueue = boost::make_shared<FIFO>();
|
||||||
m_RecvQueue = make_shared<FIFO>();
|
m_RecvQueue = boost::make_shared<FIFO>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,8 +51,8 @@ void TcpClient::Start(void)
|
|||||||
{
|
{
|
||||||
TcpSocket::Start();
|
TcpSocket::Start();
|
||||||
|
|
||||||
OnReadable.connect(bind(&TcpClient::ReadableEventHandler, this, _1));
|
OnReadable.connect(boost::bind(&TcpClient::ReadableEventHandler, this, _1));
|
||||||
OnWritable.connect(bind(&TcpClient::WritableEventHandler, this, _1));
|
OnWritable.connect(boost::bind(&TcpClient::WritableEventHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,9 +138,8 @@ FIFO::Ptr TcpClient::GetRecvQueue(void)
|
|||||||
* Processes data that is available for this socket.
|
* Processes data that is available for this socket.
|
||||||
*
|
*
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int TcpClient::ReadableEventHandler(const EventArgs&)
|
void TcpClient::ReadableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -153,11 +152,11 @@ int TcpClient::ReadableEventHandler(const EventArgs&)
|
|||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
if (rc < 0 && errno == EAGAIN)
|
if (rc < 0 && errno == EAGAIN)
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
HandleSocketError(SocketException("recv() failed", GetError()));
|
HandleSocketError(SocketException("recv() failed", GetError()));
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_RecvQueue->Write(NULL, rc);
|
m_RecvQueue->Write(NULL, rc);
|
||||||
@ -165,17 +164,14 @@ int TcpClient::ReadableEventHandler(const EventArgs&)
|
|||||||
EventArgs dea;
|
EventArgs dea;
|
||||||
dea.Source = shared_from_this();
|
dea.Source = shared_from_this();
|
||||||
OnDataAvailable(dea);
|
OnDataAvailable(dea);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data that can be written for this socket.
|
* Processes data that can be written for this socket.
|
||||||
*
|
*
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int TcpClient::WritableEventHandler(const EventArgs&)
|
void TcpClient::WritableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -183,12 +179,10 @@ int TcpClient::WritableEventHandler(const EventArgs&)
|
|||||||
|
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
HandleSocketError(SocketException("send() failed", GetError()));
|
HandleSocketError(SocketException("send() failed", GetError()));
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_SendQueue->Read(NULL, rc);
|
m_SendQueue->Read(NULL, rc);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,5 +213,5 @@ bool TcpClient::WantsToWrite(void) const
|
|||||||
*/
|
*/
|
||||||
TcpClient::Ptr icinga::TcpClientFactory(TcpClientRole role)
|
TcpClient::Ptr icinga::TcpClientFactory(TcpClientRole role)
|
||||||
{
|
{
|
||||||
return make_shared<TcpClient>(role);
|
return boost::make_shared<TcpClient>(role);
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ private:
|
|||||||
FIFO::Ptr m_SendQueue;
|
FIFO::Ptr m_SendQueue;
|
||||||
FIFO::Ptr m_RecvQueue;
|
FIFO::Ptr m_RecvQueue;
|
||||||
|
|
||||||
virtual int ReadableEventHandler(const EventArgs& ea);
|
virtual void ReadableEventHandler(const EventArgs& ea);
|
||||||
virtual int WritableEventHandler(const EventArgs& ea);
|
virtual void WritableEventHandler(const EventArgs& ea);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@ using namespace icinga;
|
|||||||
*/
|
*/
|
||||||
TcpServer::TcpServer(void)
|
TcpServer::TcpServer(void)
|
||||||
{
|
{
|
||||||
m_ClientFactory = bind(&TcpClientFactory, RoleInbound);
|
m_ClientFactory = boost::bind(&TcpClientFactory, RoleInbound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +56,7 @@ void TcpServer::Start(void)
|
|||||||
{
|
{
|
||||||
TcpSocket::Start();
|
TcpSocket::Start();
|
||||||
|
|
||||||
OnReadable.connect(bind(&TcpServer::ReadableEventHandler, this, _1));
|
OnReadable.connect(boost::bind(&TcpServer::ReadableEventHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +97,7 @@ void TcpSocket::Bind(string node, string service, int family)
|
|||||||
setsockopt(GetFD(), SOL_SOCKET, SO_REUSEADDR, (char *)&optTrue, sizeof(optTrue));
|
setsockopt(GetFD(), SOL_SOCKET, SO_REUSEADDR, (char *)&optTrue, sizeof(optTrue));
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
int rc = ::bind(fd, info->ai_addr, info->ai_addrlen);
|
int rc = bind(fd, info->ai_addr, info->ai_addrlen);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (rc < 0 && WSAGetLastError() != WSAEWOULDBLOCK) {
|
if (rc < 0 && WSAGetLastError() != WSAEWOULDBLOCK) {
|
||||||
|
@ -100,9 +100,8 @@ void Timer::CallExpiredTimers(void)
|
|||||||
*/
|
*/
|
||||||
void Timer::Call(void)
|
void Timer::Call(void)
|
||||||
{
|
{
|
||||||
TimerEventArgs tea;
|
EventArgs tea;
|
||||||
tea.Source = shared_from_this();
|
tea.Source = shared_from_this();
|
||||||
tea.UserArgs = m_UserArgs;
|
|
||||||
OnTimerExpired(tea);
|
OnTimerExpired(tea);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +110,7 @@ void Timer::Call(void)
|
|||||||
*
|
*
|
||||||
* @param interval The new interval.
|
* @param interval The new interval.
|
||||||
*/
|
*/
|
||||||
void Timer::SetInterval(unsigned int interval)
|
void Timer::SetInterval(time_t interval)
|
||||||
{
|
{
|
||||||
m_Interval = interval;
|
m_Interval = interval;
|
||||||
}
|
}
|
||||||
@ -121,31 +120,11 @@ void Timer::SetInterval(unsigned int interval)
|
|||||||
*
|
*
|
||||||
* @returns The interval.
|
* @returns The interval.
|
||||||
*/
|
*/
|
||||||
unsigned int Timer::GetInterval(void) const
|
time_t Timer::GetInterval(void) const
|
||||||
{
|
{
|
||||||
return m_Interval;
|
return m_Interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets user arguments for the timer callback.
|
|
||||||
*
|
|
||||||
* @param userArgs The user arguments.
|
|
||||||
*/
|
|
||||||
void Timer::SetUserArgs(const EventArgs& userArgs)
|
|
||||||
{
|
|
||||||
m_UserArgs = userArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the user arguments for the timer callback.
|
|
||||||
*
|
|
||||||
* @returns The user arguments.
|
|
||||||
*/
|
|
||||||
EventArgs Timer::GetUserArgs(void) const
|
|
||||||
{
|
|
||||||
return m_UserArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the timer and starts processing events for it.
|
* Registers the timer and starts processing events for it.
|
||||||
*/
|
*/
|
||||||
|
22
base/timer.h
22
base/timer.h
@ -24,16 +24,6 @@
|
|||||||
|
|
||||||
namespace icinga {
|
namespace icinga {
|
||||||
|
|
||||||
/**
|
|
||||||
* Event arguments for the "timer expired" event.
|
|
||||||
*
|
|
||||||
* @ingroup base
|
|
||||||
*/
|
|
||||||
struct I2_BASE_API TimerEventArgs : public EventArgs
|
|
||||||
{
|
|
||||||
EventArgs UserArgs; /**< User-specified event arguments. */
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A timer that periodically triggers an event.
|
* A timer that periodically triggers an event.
|
||||||
*
|
*
|
||||||
@ -51,11 +41,8 @@ public:
|
|||||||
|
|
||||||
Timer(void);
|
Timer(void);
|
||||||
|
|
||||||
void SetInterval(unsigned int interval);
|
void SetInterval(time_t interval);
|
||||||
unsigned int GetInterval(void) const;
|
time_t GetInterval(void) const;
|
||||||
|
|
||||||
void SetUserArgs(const EventArgs& userArgs);
|
|
||||||
EventArgs GetUserArgs(void) const;
|
|
||||||
|
|
||||||
static time_t GetNextCall(void);
|
static time_t GetNextCall(void);
|
||||||
static void CallExpiredTimers(void);
|
static void CallExpiredTimers(void);
|
||||||
@ -65,11 +52,10 @@ public:
|
|||||||
|
|
||||||
void Reschedule(time_t next);
|
void Reschedule(time_t next);
|
||||||
|
|
||||||
boost::signal<void (const TimerEventArgs&)> OnTimerExpired;
|
boost::signal<void(const EventArgs&)> OnTimerExpired;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventArgs m_UserArgs; /**< User-specified event arguments. */
|
time_t m_Interval; /**< The interval of the timer. */
|
||||||
unsigned int m_Interval; /**< The interval of the timer. */
|
|
||||||
time_t m_Next; /**< When the next event should happen. */
|
time_t m_Next; /**< When the next event should happen. */
|
||||||
|
|
||||||
static time_t NextCall; /**< When the next event should happen (for all timers). */
|
static time_t NextCall; /**< When the next event should happen (for all timers). */
|
||||||
|
@ -107,9 +107,8 @@ void TlsClient::Start(void)
|
|||||||
* Processes data that is available for this socket.
|
* Processes data that is available for this socket.
|
||||||
*
|
*
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int TlsClient::ReadableEventHandler(const EventArgs&)
|
void TlsClient::ReadableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -126,16 +125,14 @@ int TlsClient::ReadableEventHandler(const EventArgs&)
|
|||||||
m_BlockRead = true;
|
m_BlockRead = true;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case SSL_ERROR_WANT_READ:
|
case SSL_ERROR_WANT_READ:
|
||||||
return 0;
|
return;
|
||||||
case SSL_ERROR_ZERO_RETURN:
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
Close();
|
Close();
|
||||||
|
return;
|
||||||
return 0;
|
|
||||||
default:
|
default:
|
||||||
HandleSocketError(OpenSSLException(
|
HandleSocketError(OpenSSLException(
|
||||||
"SSL_read failed", ERR_get_error()));
|
"SSL_read failed", ERR_get_error()));
|
||||||
|
return;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,17 +141,14 @@ int TlsClient::ReadableEventHandler(const EventArgs&)
|
|||||||
EventArgs dea;
|
EventArgs dea;
|
||||||
dea.Source = shared_from_this();
|
dea.Source = shared_from_this();
|
||||||
OnDataAvailable(dea);
|
OnDataAvailable(dea);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes data that can be written for this socket.
|
* Processes data that can be written for this socket.
|
||||||
*
|
*
|
||||||
* @param - Event arguments.
|
* @param - Event arguments.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int TlsClient::WritableEventHandler(const EventArgs&)
|
void TlsClient::WritableEventHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -169,22 +163,18 @@ int TlsClient::WritableEventHandler(const EventArgs&)
|
|||||||
m_BlockWrite = true;
|
m_BlockWrite = true;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case SSL_ERROR_WANT_WRITE:
|
case SSL_ERROR_WANT_WRITE:
|
||||||
return 0;
|
return;
|
||||||
case SSL_ERROR_ZERO_RETURN:
|
case SSL_ERROR_ZERO_RETURN:
|
||||||
Close();
|
Close();
|
||||||
|
return;
|
||||||
return 0;
|
|
||||||
default:
|
default:
|
||||||
HandleSocketError(OpenSSLException(
|
HandleSocketError(OpenSSLException(
|
||||||
"SSL_write failed", ERR_get_error()));
|
"SSL_write failed", ERR_get_error()));
|
||||||
|
return;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GetSendQueue()->Read(NULL, rc);
|
GetSendQueue()->Read(NULL, rc);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,7 +230,7 @@ void TlsClient::CloseInternal(bool from_dtor)
|
|||||||
*/
|
*/
|
||||||
TcpClient::Ptr icinga::TlsClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
TcpClient::Ptr icinga::TlsClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
return make_shared<TlsClient>(role, sslContext);
|
return boost::make_shared<TlsClient>(role, sslContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,8 +70,8 @@ private:
|
|||||||
static int m_SSLIndex;
|
static int m_SSLIndex;
|
||||||
static bool m_SSLIndexInitialized;
|
static bool m_SSLIndexInitialized;
|
||||||
|
|
||||||
virtual int ReadableEventHandler(const EventArgs& ea);
|
virtual void ReadableEventHandler(const EventArgs& ea);
|
||||||
virtual int WritableEventHandler(const EventArgs& ea);
|
virtual void WritableEventHandler(const EventArgs& ea);
|
||||||
|
|
||||||
virtual void CloseInternal(bool from_dtor);
|
virtual void CloseInternal(bool from_dtor);
|
||||||
|
|
||||||
|
@ -28,17 +28,19 @@ string CheckerComponent::GetName(void) const
|
|||||||
|
|
||||||
void CheckerComponent::Start(void)
|
void CheckerComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_CheckerEndpoint = make_shared<VirtualEndpoint>();
|
m_CheckerEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
|
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
|
||||||
bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
|
boost::bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
|
||||||
m_CheckerEndpoint->RegisterTopicHandler("checker::RevokeService",
|
m_CheckerEndpoint->RegisterTopicHandler("checker::RevokeService",
|
||||||
bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
|
boost::bind(&CheckerComponent::RevokeServiceRequestHandler, this, _1));
|
||||||
|
m_CheckerEndpoint->RegisterTopicHandler("checker::ClearServices",
|
||||||
|
boost::bind(&CheckerComponent::ClearServicesRequestHandler, this, _1));
|
||||||
m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
|
m_CheckerEndpoint->RegisterPublication("checker::CheckResult");
|
||||||
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
|
||||||
|
|
||||||
m_CheckTimer = make_shared<Timer>();
|
m_CheckTimer = boost::make_shared<Timer>();
|
||||||
m_CheckTimer->SetInterval(10);
|
m_CheckTimer->SetInterval(10);
|
||||||
m_CheckTimer->OnTimerExpired.connect(bind(&CheckerComponent::CheckTimerHandler, this, _1));
|
m_CheckTimer->OnTimerExpired.connect(boost::bind(&CheckerComponent::CheckTimerHandler, this));
|
||||||
m_CheckTimer->Start();
|
m_CheckTimer->Start();
|
||||||
|
|
||||||
CheckTask::RegisterType("nagios", NagiosCheckTask::CreateTask);
|
CheckTask::RegisterType("nagios", NagiosCheckTask::CreateTask);
|
||||||
@ -60,13 +62,13 @@ void CheckerComponent::Stop(void)
|
|||||||
mgr->UnregisterEndpoint(m_CheckerEndpoint);
|
mgr->UnregisterEndpoint(m_CheckerEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CheckerComponent::CheckTimerHandler(const TimerEventArgs& ea)
|
void CheckerComponent::CheckTimerHandler(void)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
time(&now);
|
time(&now);
|
||||||
|
|
||||||
if (m_Services.size() == 0)
|
if (m_Services.size() == 0)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
Service service = m_Services.top();
|
Service service = m_Services.top();
|
||||||
@ -75,7 +77,7 @@ int CheckerComponent::CheckTimerHandler(const TimerEventArgs& ea)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
CheckTask::Ptr ct = CheckTask::CreateTask(service);
|
CheckTask::Ptr ct = CheckTask::CreateTask(service);
|
||||||
Application::Log("Executing service check for '" + service.GetName() + "'");
|
Application::Log(LogInformation, "checker", "Executing service check for '" + service.GetName() + "'");
|
||||||
CheckResult cr = ct->Execute();
|
CheckResult cr = ct->Execute();
|
||||||
|
|
||||||
m_Services.pop();
|
m_Services.pop();
|
||||||
@ -85,47 +87,91 @@ int CheckerComponent::CheckTimerHandler(const TimerEventArgs& ea)
|
|||||||
|
|
||||||
/* adjust next call time for the check timer */
|
/* adjust next call time for the check timer */
|
||||||
Service service = m_Services.top();
|
Service service = m_Services.top();
|
||||||
static_pointer_cast<Timer>(ea.Source)->SetInterval(service.GetNextCheck() - now);
|
m_CheckTimer->SetInterval(service.GetNextCheck() - now);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
|
void CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
string id;
|
|
||||||
if (!nrea.Request.GetID(&id))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
if (!nrea.Request.GetParams(¶ms))
|
if (!nrea.Request.GetParams(¶ms))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
MessagePart serviceMsg;
|
MessagePart serviceMsg;
|
||||||
if (!params.GetProperty("service", &serviceMsg))
|
if (!params.GetProperty("service", &serviceMsg))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
ConfigObject::Ptr object = make_shared<ConfigObject>(serviceMsg.GetDictionary());
|
ConfigObject::Ptr object = boost::make_shared<ConfigObject>(serviceMsg.GetDictionary());
|
||||||
Service service(object);
|
Service service(object);
|
||||||
m_Services.push(service);
|
m_Services.push(service);
|
||||||
|
|
||||||
Application::Log("Accepted service '" + service.GetName() + "'");
|
Application::Log(LogInformation, "checker", "Accepted delegation for service '" + service.GetName() + "'");
|
||||||
|
|
||||||
/* force a service check */
|
/* force a service check */
|
||||||
m_CheckTimer->Reschedule(0);
|
m_CheckTimer->Reschedule(0);
|
||||||
|
|
||||||
ResponseMessage rm;
|
string id;
|
||||||
rm.SetID(id);
|
if (nrea.Request.GetID(&id)) {
|
||||||
|
ResponseMessage rm;
|
||||||
|
rm.SetID(id);
|
||||||
|
|
||||||
MessagePart result;
|
MessagePart result;
|
||||||
rm.SetResult(result);
|
rm.SetResult(result);
|
||||||
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
|
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
|
||||||
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nrea)
|
void CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
return 0;
|
MessagePart params;
|
||||||
|
if (!nrea.Request.GetParams(¶ms))
|
||||||
|
return;
|
||||||
|
|
||||||
|
string name;
|
||||||
|
if (!params.GetProperty("service", &name))
|
||||||
|
return;
|
||||||
|
|
||||||
|
vector<Service> services;
|
||||||
|
|
||||||
|
while (!m_Services.empty()) {
|
||||||
|
Service service = m_Services.top();
|
||||||
|
|
||||||
|
if (service.GetName() == name)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
services.push_back(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<Service>::const_iterator it;
|
||||||
|
for (it = services.begin(); it != services.end(); it++)
|
||||||
|
m_Services.push(*it);
|
||||||
|
|
||||||
|
Application::Log(LogInformation, "checker", "Revoked delegation for service '" + name + "'");
|
||||||
|
|
||||||
|
string id;
|
||||||
|
if (nrea.Request.GetID(&id)) {
|
||||||
|
ResponseMessage rm;
|
||||||
|
rm.SetID(id);
|
||||||
|
|
||||||
|
MessagePart result;
|
||||||
|
rm.SetResult(result);
|
||||||
|
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckerComponent::ClearServicesRequestHandler(const NewRequestEventArgs& nrea)
|
||||||
|
{
|
||||||
|
Application::Log(LogInformation, "checker", "Clearing service delegations.");
|
||||||
|
m_Services = ServiceQueue();
|
||||||
|
|
||||||
|
string id;
|
||||||
|
if (nrea.Request.GetID(&id)) {
|
||||||
|
ResponseMessage rm;
|
||||||
|
rm.SetID(id);
|
||||||
|
|
||||||
|
MessagePart result;
|
||||||
|
rm.SetResult(result);
|
||||||
|
GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(checker, CheckerComponent);
|
EXPORT_COMPONENT(checker, CheckerComponent);
|
||||||
|
@ -38,19 +38,25 @@ public:
|
|||||||
class CheckerComponent : public IcingaComponent
|
class CheckerComponent : public IcingaComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef shared_ptr<CheckerComponent> Ptr;
|
||||||
|
typedef weak_ptr<CheckerComponent> WeakPtr;
|
||||||
|
|
||||||
|
typedef priority_queue<Service, vector<Service>, ServiceNextCheckLessComparer> ServiceQueue;
|
||||||
|
|
||||||
virtual string GetName(void) const;
|
virtual string GetName(void) const;
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
virtual void Stop(void);
|
virtual void Stop(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
priority_queue<Service, vector<Service>, ServiceNextCheckLessComparer> m_Services;
|
ServiceQueue m_Services;
|
||||||
Timer::Ptr m_CheckTimer;
|
Timer::Ptr m_CheckTimer;
|
||||||
VirtualEndpoint::Ptr m_CheckerEndpoint;
|
VirtualEndpoint::Ptr m_CheckerEndpoint;
|
||||||
|
|
||||||
int CheckTimerHandler(const TimerEventArgs& ea);
|
void CheckTimerHandler(void);
|
||||||
|
|
||||||
int AssignServiceRequestHandler(const NewRequestEventArgs& nrea);
|
void AssignServiceRequestHandler(const NewRequestEventArgs& nrea);
|
||||||
int RevokeServiceRequestHandler(const NewRequestEventArgs& nrea);
|
void RevokeServiceRequestHandler(const NewRequestEventArgs& nrea);
|
||||||
|
void ClearServicesRequestHandler(const NewRequestEventArgs& nrea);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
using std::priority_queue;
|
||||||
|
|
||||||
#include "checkercomponent.h"
|
#include "checkercomponent.h"
|
||||||
|
|
||||||
#endif /* I2CHECKER_H */
|
#endif /* I2CHECKER_H */
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "i2-configfile.h"
|
#include "i2-configfile.h"
|
||||||
|
|
||||||
|
using std::ifstream;
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
string ConfigFileComponent::GetName(void) const
|
string ConfigFileComponent::GetName(void) const
|
||||||
@ -29,17 +31,17 @@ string ConfigFileComponent::GetName(void) const
|
|||||||
void ConfigFileComponent::Start(void)
|
void ConfigFileComponent::Start(void)
|
||||||
{
|
{
|
||||||
ifstream fp;
|
ifstream fp;
|
||||||
FIFO::Ptr fifo = make_shared<FIFO>();
|
FIFO::Ptr fifo = boost::make_shared<FIFO>();
|
||||||
|
|
||||||
string filename;
|
string filename;
|
||||||
if (!GetConfig()->GetProperty("configFilename", &filename))
|
if (!GetConfig()->GetProperty("configFilename", &filename))
|
||||||
throw logic_error("Missing 'configFilename' property");
|
throw logic_error("Missing 'configFilename' property");
|
||||||
|
|
||||||
Application::Log("Compiling config file: " + filename);
|
Application::Log(LogInformation, "configfile", "Compiling config file: " + filename);
|
||||||
|
|
||||||
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(filename);
|
vector<ConfigItem::Ptr> configItems = ConfigCompiler::CompileFile(filename);
|
||||||
|
|
||||||
Application::Log("Executing config items...");
|
Application::Log(LogInformation, "configfile", "Executing config items...");
|
||||||
|
|
||||||
ConfigVM::ExecuteItems(configItems);
|
ConfigVM::ExecuteItems(configItems);
|
||||||
}
|
}
|
||||||
|
@ -30,28 +30,28 @@ void ConfigRpcComponent::Start(void)
|
|||||||
{
|
{
|
||||||
EndpointManager::Ptr endpointManager = GetEndpointManager();
|
EndpointManager::Ptr endpointManager = GetEndpointManager();
|
||||||
|
|
||||||
m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
|
m_ConfigRpcEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
|
|
||||||
long configSource;
|
long configSource;
|
||||||
if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
|
if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
|
||||||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
|
m_ConfigRpcEndpoint->RegisterTopicHandler("config::FetchObjects",
|
||||||
bind(&ConfigRpcComponent::FetchObjectsHandler, this, _1));
|
boost::bind(&ConfigRpcComponent::FetchObjectsHandler, this, _1));
|
||||||
|
|
||||||
ConfigObject::GetAllObjects()->OnObjectAdded.connect(bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
|
ConfigObject::GetAllObjects()->OnObjectAdded.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
|
||||||
ConfigObject::GetAllObjects()->OnObjectCommitted.connect(bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
|
ConfigObject::GetAllObjects()->OnObjectCommitted.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
|
||||||
ConfigObject::GetAllObjects()->OnObjectRemoved.connect(bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _1));
|
ConfigObject::GetAllObjects()->OnObjectRemoved.connect(boost::bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _1));
|
||||||
|
|
||||||
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
|
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
|
||||||
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
|
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectRemoved");
|
||||||
}
|
}
|
||||||
|
|
||||||
endpointManager->OnNewEndpoint.connect(bind(&ConfigRpcComponent::NewEndpointHandler, this, _1));
|
endpointManager->OnNewEndpoint.connect(boost::bind(&ConfigRpcComponent::NewEndpointHandler, this, _1));
|
||||||
|
|
||||||
m_ConfigRpcEndpoint->RegisterPublication("config::FetchObjects");
|
m_ConfigRpcEndpoint->RegisterPublication("config::FetchObjects");
|
||||||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectCommitted",
|
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectCommitted",
|
||||||
bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _1));
|
boost::bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _1));
|
||||||
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
|
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
|
||||||
bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _1));
|
boost::bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _1));
|
||||||
|
|
||||||
endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
|
endpointManager->RegisterEndpoint(m_ConfigRpcEndpoint);
|
||||||
}
|
}
|
||||||
@ -64,22 +64,18 @@ void ConfigRpcComponent::Stop(void)
|
|||||||
mgr->UnregisterEndpoint(m_ConfigRpcEndpoint);
|
mgr->UnregisterEndpoint(m_ConfigRpcEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
|
void ConfigRpcComponent::NewEndpointHandler(const NewEndpointEventArgs& ea)
|
||||||
{
|
{
|
||||||
ea.Endpoint->OnSessionEstablished.connect(bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1));
|
ea.Endpoint->OnSessionEstablished.connect(boost::bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1));
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
|
void ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
RequestMessage request;
|
RequestMessage request;
|
||||||
request.SetMethod("config::FetchObjects");
|
request.SetMethod("config::FetchObjects");
|
||||||
|
|
||||||
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
|
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
|
||||||
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
|
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestMessage ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
|
RequestMessage ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
|
||||||
@ -104,7 +100,7 @@ bool ConfigRpcComponent::ShouldReplicateObject(const ConfigObject::Ptr& object)
|
|||||||
return (!object->IsLocal());
|
return (!object->IsLocal());
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
|
void ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
|
||||||
{
|
{
|
||||||
Endpoint::Ptr client = ea.Sender;
|
Endpoint::Ptr client = ea.Sender;
|
||||||
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
|
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
|
||||||
@ -119,93 +115,83 @@ int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
|
|||||||
|
|
||||||
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
|
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, client, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
void ConfigRpcComponent::LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = ea.Target;
|
ConfigObject::Ptr object = ea.Target;
|
||||||
|
|
||||||
if (!ShouldReplicateObject(object))
|
if (!ShouldReplicateObject(object))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
|
GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
|
||||||
MakeObjectMessage(object, "config::ObjectCreated", true));
|
MakeObjectMessage(object, "config::ObjectCreated", true));
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
void ConfigRpcComponent::LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = ea.Target;
|
ConfigObject::Ptr object = ea.Target;
|
||||||
|
|
||||||
if (!ShouldReplicateObject(object))
|
if (!ShouldReplicateObject(object))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
|
GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
|
||||||
MakeObjectMessage(object, "config::ObjectRemoved", false));
|
MakeObjectMessage(object, "config::ObjectRemoved", false));
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
|
void ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
|
||||||
{
|
{
|
||||||
RequestMessage message = ea.Request;
|
RequestMessage message = ea.Request;
|
||||||
|
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
if (!message.GetParams(¶ms))
|
if (!message.GetParams(¶ms))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
if (!params.GetProperty("name", &name))
|
if (!params.GetProperty("name", &name))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
string type;
|
string type;
|
||||||
if (!params.GetProperty("type", &type))
|
if (!params.GetProperty("type", &type))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
MessagePart properties;
|
MessagePart properties;
|
||||||
if (!params.GetProperty("properties", &properties))
|
if (!params.GetProperty("properties", &properties))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
|
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
|
||||||
|
|
||||||
if (!object)
|
if (!object)
|
||||||
object = make_shared<ConfigObject>(properties.GetDictionary());
|
object = boost::make_shared<ConfigObject>(properties.GetDictionary());
|
||||||
else
|
else
|
||||||
object->SetProperties(properties.GetDictionary());
|
object->SetProperties(properties.GetDictionary());
|
||||||
|
|
||||||
object->Commit();
|
object->Commit();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
|
void ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
|
||||||
{
|
{
|
||||||
RequestMessage message = ea.Request;
|
RequestMessage message = ea.Request;
|
||||||
|
|
||||||
MessagePart params;
|
MessagePart params;
|
||||||
if (!message.GetParams(¶ms))
|
if (!message.GetParams(¶ms))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
string name;
|
string name;
|
||||||
if (!params.GetProperty("name", &name))
|
if (!params.GetProperty("name", &name))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
string type;
|
string type;
|
||||||
if (!params.GetProperty("type", &type))
|
if (!params.GetProperty("type", &type))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
|
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
|
||||||
|
|
||||||
if (!object)
|
if (!object)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (!object->IsLocal())
|
if (!object->IsLocal())
|
||||||
object->Unregister();
|
object->Unregister();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(configrpc, ConfigRpcComponent);
|
EXPORT_COMPONENT(configrpc, ConfigRpcComponent);
|
||||||
|
@ -36,15 +36,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
|
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
|
||||||
|
|
||||||
int NewEndpointHandler(const NewEndpointEventArgs& ea);
|
void NewEndpointHandler(const NewEndpointEventArgs& ea);
|
||||||
int SessionEstablishedHandler(const EventArgs& ea);
|
void SessionEstablishedHandler(const EventArgs& ea);
|
||||||
|
|
||||||
int LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||||
int LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||||
|
|
||||||
int FetchObjectsHandler(const NewRequestEventArgs& ea);
|
void FetchObjectsHandler(const NewRequestEventArgs& ea);
|
||||||
int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
|
void RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
|
||||||
int RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
|
void RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
|
||||||
|
|
||||||
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
|
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
|
||||||
string method, bool includeProperties);
|
string method, bool includeProperties);
|
||||||
|
@ -28,18 +28,18 @@ string DelegationComponent::GetName(void) const
|
|||||||
|
|
||||||
void DelegationComponent::Start(void)
|
void DelegationComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_AllServices = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
|
m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
|
||||||
m_AllServices->OnObjectAdded.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
|
m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
|
||||||
m_AllServices->OnObjectCommitted.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
|
m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
|
||||||
m_AllServices->OnObjectRemoved.connect(bind(&DelegationComponent::RemovedServiceHandler, this, _1));
|
m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _1));
|
||||||
m_AllServices->Start();
|
m_AllServices->Start();
|
||||||
|
|
||||||
m_DelegationTimer = make_shared<Timer>();
|
m_DelegationTimer = boost::make_shared<Timer>();
|
||||||
m_DelegationTimer->SetInterval(30);
|
m_DelegationTimer->SetInterval(30);
|
||||||
m_DelegationTimer->OnTimerExpired.connect(bind(&DelegationComponent::DelegationTimerHandler, this, _1));
|
m_DelegationTimer->OnTimerExpired.connect(boost::bind(&DelegationComponent::DelegationTimerHandler, this));
|
||||||
m_DelegationTimer->Start();
|
m_DelegationTimer->Start();
|
||||||
|
|
||||||
m_DelegationEndpoint = make_shared<VirtualEndpoint>();
|
m_DelegationEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
m_DelegationEndpoint->RegisterPublication("checker::AssignService");
|
m_DelegationEndpoint->RegisterPublication("checker::AssignService");
|
||||||
m_DelegationEndpoint->RegisterPublication("checker::RevokeService");
|
m_DelegationEndpoint->RegisterPublication("checker::RevokeService");
|
||||||
GetEndpointManager()->RegisterEndpoint(m_DelegationEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_DelegationEndpoint);
|
||||||
@ -53,16 +53,14 @@ void DelegationComponent::Stop(void)
|
|||||||
mgr->UnregisterEndpoint(m_DelegationEndpoint);
|
mgr->UnregisterEndpoint(m_DelegationEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
int DelegationComponent::NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
void DelegationComponent::NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||||
{
|
{
|
||||||
AssignService(ea.Target);
|
AssignService(ea.Target);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
void DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||||
{
|
{
|
||||||
RevokeService(ea.Target);
|
RevokeService(ea.Target);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
|
void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
|
||||||
@ -74,22 +72,20 @@ void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
|
|||||||
params.SetProperty("service", service->GetProperties());
|
params.SetProperty("service", service->GetProperties());
|
||||||
request.SetParams(params);
|
request.SetParams(params);
|
||||||
|
|
||||||
Application::Log("Trying to delegate service '" + service->GetName() + "'");
|
Application::Log(LogInformation, "delegation", "Trying to delegate service '" + service->GetName() + "'");
|
||||||
|
|
||||||
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
|
GetEndpointManager()->SendAPIMessage(m_DelegationEndpoint, request,
|
||||||
bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _1));
|
boost::bind(&DelegationComponent::AssignServiceResponseHandler, this, service, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea)
|
void DelegationComponent::AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea)
|
||||||
{
|
{
|
||||||
if (nrea.TimedOut) {
|
if (nrea.TimedOut) {
|
||||||
Application::Log("Service delegation for service '" + service->GetName() + "' timed out.");
|
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' timed out.");
|
||||||
} else {
|
} else {
|
||||||
service->SetTag("checker", nrea.Sender->GetIdentity());
|
service->SetTag("checker", nrea.Sender->GetIdentity());
|
||||||
Application::Log("Service delegation for service '" + service->GetName() + "' was successful.");
|
Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' was successful.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DelegationComponent::RevokeService(const ConfigObject::Ptr& service)
|
void DelegationComponent::RevokeService(const ConfigObject::Ptr& service)
|
||||||
@ -97,12 +93,11 @@ void DelegationComponent::RevokeService(const ConfigObject::Ptr& service)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DelegationComponent::RevokeServiceResponseHandler(const NewResponseEventArgs& nrea)
|
void DelegationComponent::RevokeServiceResponseHandler(const NewResponseEventArgs& nrea)
|
||||||
{
|
{
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DelegationComponent::DelegationTimerHandler(const TimerEventArgs& ea)
|
void DelegationComponent::DelegationTimerHandler(void)
|
||||||
{
|
{
|
||||||
ConfigObject::Set::Iterator it;
|
ConfigObject::Set::Iterator it;
|
||||||
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
|
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
|
||||||
@ -114,15 +109,6 @@ int DelegationComponent::DelegationTimerHandler(const TimerEventArgs& ea)
|
|||||||
|
|
||||||
AssignService(object);
|
AssignService(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int DelegationComponent::TestResponseHandler(const NewResponseEventArgs& ea)
|
|
||||||
{
|
|
||||||
Application::Log("Response handler called.");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(delegation, DelegationComponent);
|
EXPORT_COMPONENT(delegation, DelegationComponent);
|
||||||
|
@ -38,18 +38,16 @@ private:
|
|||||||
ConfigObject::Set::Ptr m_AllServices;
|
ConfigObject::Set::Ptr m_AllServices;
|
||||||
Timer::Ptr m_DelegationTimer;
|
Timer::Ptr m_DelegationTimer;
|
||||||
|
|
||||||
int NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||||
int RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||||
|
|
||||||
int AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
|
void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
|
||||||
int RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
|
void RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
|
||||||
|
|
||||||
int DelegationTimerHandler(const TimerEventArgs& ea);
|
void DelegationTimerHandler(void);
|
||||||
|
|
||||||
void AssignService(const ConfigObject::Ptr& service);
|
void AssignService(const ConfigObject::Ptr& service);
|
||||||
void RevokeService(const ConfigObject::Ptr& service);
|
void RevokeService(const ConfigObject::Ptr& service);
|
||||||
|
|
||||||
int TestResponseHandler(const NewResponseEventArgs& ea);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,15 +36,15 @@ string DemoComponent::GetName(void) const
|
|||||||
*/
|
*/
|
||||||
void DemoComponent::Start(void)
|
void DemoComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_DemoEndpoint = make_shared<VirtualEndpoint>();
|
m_DemoEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
|
m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
|
||||||
bind(&DemoComponent::HelloWorldRequestHandler, this, _1));
|
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _1));
|
||||||
m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
|
m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
|
||||||
GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
|
||||||
|
|
||||||
m_DemoTimer = make_shared<Timer>();
|
m_DemoTimer = boost::make_shared<Timer>();
|
||||||
m_DemoTimer->SetInterval(5);
|
m_DemoTimer->SetInterval(5);
|
||||||
m_DemoTimer->OnTimerExpired.connect(bind(&DemoComponent::DemoTimerHandler, this, _1));
|
m_DemoTimer->OnTimerExpired.connect(boost::bind(&DemoComponent::DemoTimerHandler, this));
|
||||||
m_DemoTimer->Start();
|
m_DemoTimer->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,29 +65,24 @@ void DemoComponent::Stop(void)
|
|||||||
* Periodically sends a demo::HelloWorld message.
|
* Periodically sends a demo::HelloWorld message.
|
||||||
*
|
*
|
||||||
* @param - Event arguments for the timer.
|
* @param - Event arguments for the timer.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int DemoComponent::DemoTimerHandler(const TimerEventArgs&)
|
void DemoComponent::DemoTimerHandler(void)
|
||||||
{
|
{
|
||||||
Application::Log("Sending multicast 'hello world' message.");
|
Application::Log(LogInformation, "demo", "Sending multicast 'hello world' message.");
|
||||||
|
|
||||||
RequestMessage request;
|
RequestMessage request;
|
||||||
request.SetMethod("demo::HelloWorld");
|
request.SetMethod("demo::HelloWorld");
|
||||||
|
|
||||||
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
|
||||||
endpointManager->SendMulticastMessage(m_DemoEndpoint, request);
|
endpointManager->SendMulticastMessage(m_DemoEndpoint, request);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes demo::HelloWorld messages.
|
* Processes demo::HelloWorld messages.
|
||||||
*/
|
*/
|
||||||
int DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
|
void DemoComponent::HelloWorldRequestHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
Application::Log("Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
|
Application::Log(LogInformation, "demo", "Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(demo, DemoComponent);
|
EXPORT_COMPONENT(demo, DemoComponent);
|
||||||
|
@ -37,8 +37,8 @@ private:
|
|||||||
Timer::Ptr m_DemoTimer;
|
Timer::Ptr m_DemoTimer;
|
||||||
VirtualEndpoint::Ptr m_DemoEndpoint;
|
VirtualEndpoint::Ptr m_DemoEndpoint;
|
||||||
|
|
||||||
int DemoTimerHandler(const TimerEventArgs& tea);
|
void DemoTimerHandler(void);
|
||||||
int HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
|
void HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,28 +36,28 @@ string DiscoveryComponent::GetName(void) const
|
|||||||
*/
|
*/
|
||||||
void DiscoveryComponent::Start(void)
|
void DiscoveryComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_DiscoveryEndpoint = make_shared<VirtualEndpoint>();
|
m_DiscoveryEndpoint = boost::make_shared<VirtualEndpoint>();
|
||||||
|
|
||||||
m_DiscoveryEndpoint->RegisterPublication("discovery::RegisterComponent");
|
m_DiscoveryEndpoint->RegisterPublication("discovery::RegisterComponent");
|
||||||
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::RegisterComponent",
|
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::RegisterComponent",
|
||||||
bind(&DiscoveryComponent::RegisterComponentMessageHandler, this, _1));
|
boost::bind(&DiscoveryComponent::RegisterComponentMessageHandler, this, _1));
|
||||||
|
|
||||||
m_DiscoveryEndpoint->RegisterPublication("discovery::NewComponent");
|
m_DiscoveryEndpoint->RegisterPublication("discovery::NewComponent");
|
||||||
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::NewComponent",
|
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::NewComponent",
|
||||||
bind(&DiscoveryComponent::NewComponentMessageHandler, this, _1));
|
boost::bind(&DiscoveryComponent::NewComponentMessageHandler, this, _1));
|
||||||
|
|
||||||
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::Welcome",
|
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::Welcome",
|
||||||
bind(&DiscoveryComponent::WelcomeMessageHandler, this, _1));
|
boost::bind(&DiscoveryComponent::WelcomeMessageHandler, this, _1));
|
||||||
|
|
||||||
GetEndpointManager()->ForEachEndpoint(bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
|
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
|
||||||
GetEndpointManager()->OnNewEndpoint.connect(bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
|
GetEndpointManager()->OnNewEndpoint.connect(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
|
||||||
|
|
||||||
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
|
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
|
||||||
|
|
||||||
/* create the reconnect timer */
|
/* create the reconnect timer */
|
||||||
m_DiscoveryTimer = make_shared<Timer>();
|
m_DiscoveryTimer = boost::make_shared<Timer>();
|
||||||
m_DiscoveryTimer->SetInterval(30);
|
m_DiscoveryTimer->SetInterval(30);
|
||||||
m_DiscoveryTimer->OnTimerExpired.connect(bind(&DiscoveryComponent::DiscoveryTimerHandler, this, _1));
|
m_DiscoveryTimer->OnTimerExpired.connect(boost::bind(&DiscoveryComponent::DiscoveryTimerHandler, this));
|
||||||
m_DiscoveryTimer->Start();
|
m_DiscoveryTimer->Start();
|
||||||
|
|
||||||
/* call the timer as soon as possible */
|
/* call the timer as soon as possible */
|
||||||
@ -81,24 +81,21 @@ void DiscoveryComponent::Stop(void)
|
|||||||
*
|
*
|
||||||
* @param endpoint The endpoint that is to be checked.
|
* @param endpoint The endpoint that is to be checked.
|
||||||
* @param neea Event arguments for another endpoint.
|
* @param neea Event arguments for another endpoint.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea)
|
void DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea)
|
||||||
{
|
{
|
||||||
if (endpoint == neea.Endpoint)
|
if (endpoint == neea.Endpoint)
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (!neea.Endpoint->IsConnected())
|
if (!neea.Endpoint->IsConnected())
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
|
||||||
Application::Log("Detected duplicate identity:" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
|
Application::Log(LogWarning, "discovery", "Detected duplicate identity:" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
|
||||||
|
|
||||||
neea.Endpoint->Stop();
|
neea.Endpoint->Stop();
|
||||||
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
|
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,17 +104,15 @@ int DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewE
|
|||||||
* @param neea Event arguments for the new endpoint.
|
* @param neea Event arguments for the new endpoint.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
|
void DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
|
||||||
{
|
{
|
||||||
neea.Endpoint->OnIdentityChanged.connect(bind(&DiscoveryComponent::NewIdentityHandler, this, _1));
|
neea.Endpoint->OnIdentityChanged.connect(boost::bind(&DiscoveryComponent::NewIdentityHandler, this, _1));
|
||||||
|
|
||||||
/* accept discovery::RegisterComponent messages from any endpoint */
|
/* accept discovery::RegisterComponent messages from any endpoint */
|
||||||
neea.Endpoint->RegisterPublication("discovery::RegisterComponent");
|
neea.Endpoint->RegisterPublication("discovery::RegisterComponent");
|
||||||
|
|
||||||
/* accept discovery::Welcome messages from any endpoint */
|
/* accept discovery::Welcome messages from any endpoint */
|
||||||
neea.Endpoint->RegisterPublication("discovery::Welcome");
|
neea.Endpoint->RegisterPublication("discovery::Welcome");
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,7 +122,7 @@ int DiscoveryComponent::NewEndpointHandler(const NewEndpointEventArgs& neea)
|
|||||||
* @param info Component information object.
|
* @param info Component information object.
|
||||||
* @return 0
|
* @return 0
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const
|
void DiscoveryComponent::DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const
|
||||||
{
|
{
|
||||||
Endpoint::ConstTopicIterator i;
|
Endpoint::ConstTopicIterator i;
|
||||||
|
|
||||||
@ -138,8 +133,6 @@ int DiscoveryComponent::DiscoveryEndpointHandler(const NewEndpointEventArgs& nee
|
|||||||
for (i = neea.Endpoint->BeginPublications(); i != neea.Endpoint->EndPublications(); i++) {
|
for (i = neea.Endpoint->BeginPublications(); i != neea.Endpoint->EndPublications(); i++) {
|
||||||
info->Publications.insert(*i);
|
info->Publications.insert(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,8 +146,8 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
|
|||||||
{
|
{
|
||||||
if (component == GetEndpointManager()->GetIdentity()) {
|
if (component == GetEndpointManager()->GetIdentity()) {
|
||||||
/* Build fake discovery info for ourselves */
|
/* Build fake discovery info for ourselves */
|
||||||
*info = make_shared<ComponentDiscoveryInfo>();
|
*info = boost::make_shared<ComponentDiscoveryInfo>();
|
||||||
GetEndpointManager()->ForEachEndpoint(bind(&DiscoveryComponent::DiscoveryEndpointHandler, this, _1, *info));
|
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::DiscoveryEndpointHandler, this, _1, *info));
|
||||||
|
|
||||||
(*info)->LastSeen = 0;
|
(*info)->LastSeen = 0;
|
||||||
(*info)->Node = GetIcingaApplication()->GetNode();
|
(*info)->Node = GetIcingaApplication()->GetNode();
|
||||||
@ -180,21 +173,21 @@ bool DiscoveryComponent::GetComponentDiscoveryInfo(string component, ComponentDi
|
|||||||
* @param ea Event arguments for the component.
|
* @param ea Event arguments for the component.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
||||||
{
|
{
|
||||||
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
|
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
|
||||||
string identity = endpoint->GetIdentity();
|
string identity = endpoint->GetIdentity();
|
||||||
|
|
||||||
if (identity == GetEndpointManager()->GetIdentity()) {
|
if (identity == GetEndpointManager()->GetIdentity()) {
|
||||||
Application::Log("Detected loop-back connection - Disconnecting endpoint.");
|
Application::Log(LogWarning, "discovery", "Detected loop-back connection - Disconnecting endpoint.");
|
||||||
|
|
||||||
endpoint->Stop();
|
endpoint->Stop();
|
||||||
GetEndpointManager()->UnregisterEndpoint(endpoint);
|
GetEndpointManager()->UnregisterEndpoint(endpoint);
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetEndpointManager()->ForEachEndpoint(bind(&DiscoveryComponent::CheckExistingEndpoint, this, endpoint, _1));
|
GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::CheckExistingEndpoint, this, endpoint, _1));
|
||||||
|
|
||||||
// we assume the other component _always_ wants
|
// we assume the other component _always_ wants
|
||||||
// discovery::RegisterComponent messages from us
|
// discovery::RegisterComponent messages from us
|
||||||
@ -227,7 +220,7 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
|||||||
// we don't know the other component yet, so
|
// we don't know the other component yet, so
|
||||||
// wait until we get a discovery::NewComponent message
|
// wait until we get a discovery::NewComponent message
|
||||||
// from a broker
|
// from a broker
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// register published/subscribed topics for this endpoint
|
// register published/subscribed topics for this endpoint
|
||||||
@ -240,8 +233,6 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
|||||||
endpoint->RegisterSubscription(*it);
|
endpoint->RegisterSubscription(*it);
|
||||||
|
|
||||||
FinishDiscoverySetup(endpoint);
|
FinishDiscoverySetup(endpoint);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -250,12 +241,12 @@ int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
|
|||||||
* @param nrea Event arguments for the request.
|
* @param nrea Event arguments for the request.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
|
void DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
Endpoint::Ptr endpoint = nrea.Sender;
|
Endpoint::Ptr endpoint = nrea.Sender;
|
||||||
|
|
||||||
if (endpoint->HasReceivedWelcome())
|
if (endpoint->HasReceivedWelcome())
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
endpoint->SetReceivedWelcome(true);
|
endpoint->SetReceivedWelcome(true);
|
||||||
|
|
||||||
@ -264,8 +255,6 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
|
|||||||
ea.Source = endpoint;
|
ea.Source = endpoint;
|
||||||
endpoint->OnSessionEstablished(ea);
|
endpoint->OnSessionEstablished(ea);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -384,7 +373,7 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
|
|||||||
if (identity == GetEndpointManager()->GetIdentity())
|
if (identity == GetEndpointManager()->GetIdentity())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ComponentDiscoveryInfo::Ptr info = make_shared<ComponentDiscoveryInfo>();
|
ComponentDiscoveryInfo::Ptr info = boost::make_shared<ComponentDiscoveryInfo>();
|
||||||
|
|
||||||
time(&(info->LastSeen));
|
time(&(info->LastSeen));
|
||||||
|
|
||||||
@ -448,44 +437,36 @@ void DiscoveryComponent::ProcessDiscoveryMessage(string identity, DiscoveryMessa
|
|||||||
* Processes "discovery::NewComponent" messages.
|
* Processes "discovery::NewComponent" messages.
|
||||||
*
|
*
|
||||||
* @param nrea Event arguments for the request.
|
* @param nrea Event arguments for the request.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& nrea)
|
void DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
DiscoveryMessage message;
|
DiscoveryMessage message;
|
||||||
nrea.Request.GetParams(&message);
|
nrea.Request.GetParams(&message);
|
||||||
|
|
||||||
string identity;
|
string identity;
|
||||||
if (!message.GetIdentity(&identity))
|
if (!message.GetIdentity(&identity))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
ProcessDiscoveryMessage(identity, message, true);
|
ProcessDiscoveryMessage(identity, message, true);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes "discovery::RegisterComponent" messages.
|
* Processes "discovery::RegisterComponent" messages.
|
||||||
*
|
*
|
||||||
* @param nrea Event arguments for the request.
|
* @param nrea Event arguments for the request.
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArgs& nrea)
|
void DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArgs& nrea)
|
||||||
{
|
{
|
||||||
DiscoveryMessage message;
|
DiscoveryMessage message;
|
||||||
nrea.Request.GetParams(&message);
|
nrea.Request.GetParams(&message);
|
||||||
ProcessDiscoveryMessage(nrea.Sender->GetIdentity(), message, false);
|
ProcessDiscoveryMessage(nrea.Sender->GetIdentity(), message, false);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether we have to reconnect to other components and removes stale
|
* Checks whether we have to reconnect to other components and removes stale
|
||||||
* components from the registry.
|
* components from the registry.
|
||||||
*
|
|
||||||
* @param tea Event arguments for the timer.
|
|
||||||
* @returns 0
|
|
||||||
*/
|
*/
|
||||||
int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea)
|
void DiscoveryComponent::DiscoveryTimerHandler(void)
|
||||||
{
|
{
|
||||||
EndpointManager::Ptr endpointManager = GetEndpointManager();
|
EndpointManager::Ptr endpointManager = GetEndpointManager();
|
||||||
|
|
||||||
@ -537,8 +518,6 @@ int DiscoveryComponent::DiscoveryTimerHandler(const TimerEventArgs& tea)
|
|||||||
endpointManager->AddConnection(info->Node, info->Service);
|
endpointManager->AddConnection(info->Node, info->Service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(discovery, DiscoveryComponent);
|
EXPORT_COMPONENT(discovery, DiscoveryComponent);
|
||||||
|
@ -56,23 +56,23 @@ private:
|
|||||||
map<string, ComponentDiscoveryInfo::Ptr> m_Components;
|
map<string, ComponentDiscoveryInfo::Ptr> m_Components;
|
||||||
Timer::Ptr m_DiscoveryTimer;
|
Timer::Ptr m_DiscoveryTimer;
|
||||||
|
|
||||||
int NewEndpointHandler(const NewEndpointEventArgs& neea);
|
void NewEndpointHandler(const NewEndpointEventArgs& neea);
|
||||||
int NewIdentityHandler(const EventArgs& ea);
|
void NewIdentityHandler(const EventArgs& ea);
|
||||||
|
|
||||||
int NewComponentMessageHandler(const NewRequestEventArgs& nrea);
|
void NewComponentMessageHandler(const NewRequestEventArgs& nrea);
|
||||||
int RegisterComponentMessageHandler(const NewRequestEventArgs& nrea);
|
void RegisterComponentMessageHandler(const NewRequestEventArgs& nrea);
|
||||||
|
|
||||||
int WelcomeMessageHandler(const NewRequestEventArgs& nrea);
|
void WelcomeMessageHandler(const NewRequestEventArgs& nrea);
|
||||||
|
|
||||||
void SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient);
|
void SendDiscoveryMessage(string method, string identity, Endpoint::Ptr recipient);
|
||||||
void ProcessDiscoveryMessage(string identity, DiscoveryMessage message, bool trusted);
|
void ProcessDiscoveryMessage(string identity, DiscoveryMessage message, bool trusted);
|
||||||
|
|
||||||
bool GetComponentDiscoveryInfo(string component, ComponentDiscoveryInfo::Ptr *info) const;
|
bool GetComponentDiscoveryInfo(string component, ComponentDiscoveryInfo::Ptr *info) const;
|
||||||
|
|
||||||
int CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
|
void CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
|
||||||
int DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
|
void DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
|
||||||
|
|
||||||
int DiscoveryTimerHandler(const TimerEventArgs& tea);
|
void DiscoveryTimerHandler(void);
|
||||||
|
|
||||||
void FinishDiscoverySetup(Endpoint::Ptr endpoint);
|
void FinishDiscoverySetup(Endpoint::Ptr endpoint);
|
||||||
|
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
# ============================================================================
|
|
||||||
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_0x.html
|
|
||||||
# ============================================================================
|
|
||||||
#
|
|
||||||
# SYNOPSIS
|
|
||||||
#
|
|
||||||
# AX_CXX_COMPILE_STDCXX_0X
|
|
||||||
#
|
|
||||||
# DESCRIPTION
|
|
||||||
#
|
|
||||||
# Check for baseline language coverage in the compiler for the C++0x
|
|
||||||
# standard.
|
|
||||||
#
|
|
||||||
# LICENSE
|
|
||||||
#
|
|
||||||
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
|
|
||||||
#
|
|
||||||
# Copying and distribution of this file, with or without modification, are
|
|
||||||
# permitted in any medium without royalty provided the copyright notice
|
|
||||||
# and this notice are preserved. This file is offered as-is, without any
|
|
||||||
# warranty.
|
|
||||||
|
|
||||||
#serial 7
|
|
||||||
|
|
||||||
AU_ALIAS([AC_CXX_COMPILE_STDCXX_0X], [AX_CXX_COMPILE_STDCXX_0X])
|
|
||||||
AC_DEFUN([AX_CXX_COMPILE_STDCXX_0X], [
|
|
||||||
AC_CACHE_CHECK(if g++ supports C++0x features without additional flags,
|
|
||||||
ax_cv_cxx_compile_cxx0x_native,
|
|
||||||
[AC_LANG_SAVE
|
|
||||||
AC_LANG_CPLUSPLUS
|
|
||||||
AC_TRY_COMPILE([
|
|
||||||
template <typename T>
|
|
||||||
struct check
|
|
||||||
{
|
|
||||||
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef check<check<bool>> right_angle_brackets;
|
|
||||||
|
|
||||||
int a;
|
|
||||||
decltype(a) b;
|
|
||||||
|
|
||||||
typedef check<int> check_type;
|
|
||||||
check_type c;
|
|
||||||
check_type&& cr = static_cast<check_type&&>(c);],,
|
|
||||||
ax_cv_cxx_compile_cxx0x_native=yes, ax_cv_cxx_compile_cxx0x_native=no)
|
|
||||||
AC_LANG_RESTORE
|
|
||||||
])
|
|
||||||
|
|
||||||
AC_CACHE_CHECK(if g++ supports C++0x features with -std=c++0x,
|
|
||||||
ax_cv_cxx_compile_cxx0x_cxx,
|
|
||||||
[AC_LANG_SAVE
|
|
||||||
AC_LANG_CPLUSPLUS
|
|
||||||
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
||||||
CXXFLAGS="$CXXFLAGS -std=c++0x"
|
|
||||||
AC_TRY_COMPILE([
|
|
||||||
template <typename T>
|
|
||||||
struct check
|
|
||||||
{
|
|
||||||
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef check<check<bool>> right_angle_brackets;
|
|
||||||
|
|
||||||
int a;
|
|
||||||
decltype(a) b;
|
|
||||||
|
|
||||||
typedef check<int> check_type;
|
|
||||||
check_type c;
|
|
||||||
check_type&& cr = static_cast<check_type&&>(c);],,
|
|
||||||
ax_cv_cxx_compile_cxx0x_cxx=yes, ax_cv_cxx_compile_cxx0x_cxx=no)
|
|
||||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
||||||
AC_LANG_RESTORE
|
|
||||||
])
|
|
||||||
|
|
||||||
AC_CACHE_CHECK(if g++ supports C++0x features with -std=gnu++0x,
|
|
||||||
ax_cv_cxx_compile_cxx0x_gxx,
|
|
||||||
[AC_LANG_SAVE
|
|
||||||
AC_LANG_CPLUSPLUS
|
|
||||||
ac_save_CXXFLAGS="$CXXFLAGS"
|
|
||||||
CXXFLAGS="$CXXFLAGS -std=gnu++0x"
|
|
||||||
AC_TRY_COMPILE([
|
|
||||||
template <typename T>
|
|
||||||
struct check
|
|
||||||
{
|
|
||||||
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef check<check<bool>> right_angle_brackets;
|
|
||||||
|
|
||||||
int a;
|
|
||||||
decltype(a) b;
|
|
||||||
|
|
||||||
typedef check<int> check_type;
|
|
||||||
check_type c;
|
|
||||||
check_type&& cr = static_cast<check_type&&>(c);],,
|
|
||||||
ax_cv_cxx_compile_cxx0x_gxx=yes, ax_cv_cxx_compile_cxx0x_gxx=no)
|
|
||||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
|
||||||
AC_LANG_RESTORE
|
|
||||||
])
|
|
||||||
|
|
||||||
if test "$ax_cv_cxx_compile_cxx0x_native" = yes ||
|
|
||||||
test "$ax_cv_cxx_compile_cxx0x_cxx" = yes ||
|
|
||||||
test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then
|
|
||||||
AC_DEFINE(HAVE_STDCXX_0X,,[Define if g++ supports C++0x features. ])
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "$ax_cv_cxx_compile_cxx0x_gxx" = yes; then
|
|
||||||
CXXFLAGS="$CXXFLAGS -std=gnu++0x"
|
|
||||||
elif test "$ax_cv_cxx_compile_cxx0x_cxx" = yes; then
|
|
||||||
CXXFLAGS="$CXXFLAGS -std=c++0x"
|
|
||||||
fi
|
|
||||||
])
|
|
@ -49,7 +49,6 @@ AC_PROG_INSTALL
|
|||||||
AM_PROG_LEX
|
AM_PROG_LEX
|
||||||
AC_PROG_YACC
|
AC_PROG_YACC
|
||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
AX_CXX_COMPILE_STDCXX_0X
|
|
||||||
AX_CXX_GCC_ABI_DEMANGLE
|
AX_CXX_GCC_ABI_DEMANGLE
|
||||||
AX_PTHREAD
|
AX_PTHREAD
|
||||||
AX_BOOST_BASE
|
AX_BOOST_BASE
|
||||||
|
@ -1578,7 +1578,7 @@ yyreduce:
|
|||||||
/* Line 1806 of yacc.c */
|
/* Line 1806 of yacc.c */
|
||||||
#line 120 "config_parser.yy"
|
#line 120 "config_parser.yy"
|
||||||
{
|
{
|
||||||
m_Object = make_shared<ConfigItem>((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc);
|
m_Object = boost::make_shared<ConfigItem>((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc);
|
||||||
free((yyvsp[(4) - (5)].text));
|
free((yyvsp[(4) - (5)].text));
|
||||||
free((yyvsp[(5) - (5)].text));
|
free((yyvsp[(5) - (5)].text));
|
||||||
}
|
}
|
||||||
@ -1645,7 +1645,7 @@ yyreduce:
|
|||||||
/* Line 1806 of yacc.c */
|
/* Line 1806 of yacc.c */
|
||||||
#line 180 "config_parser.yy"
|
#line 180 "config_parser.yy"
|
||||||
{
|
{
|
||||||
m_ExpressionLists.push(make_shared<ExpressionList>());
|
m_ExpressionLists.push(boost::make_shared<ExpressionList>());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1681,7 +1681,7 @@ yyreduce:
|
|||||||
free((yyvsp[(3) - (6)].text));
|
free((yyvsp[(3) - (6)].text));
|
||||||
delete (yyvsp[(6) - (6)].variant);
|
delete (yyvsp[(6) - (6)].variant);
|
||||||
|
|
||||||
ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
|
ExpressionList::Ptr subexprl = boost::make_shared<ExpressionList>();
|
||||||
subexprl->AddExpression(subexpr);
|
subexprl->AddExpression(subexpr);
|
||||||
|
|
||||||
Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl, yylloc);
|
Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl, yylloc);
|
||||||
@ -1754,7 +1754,7 @@ yyreduce:
|
|||||||
/* Line 1806 of yacc.c */
|
/* Line 1806 of yacc.c */
|
||||||
#line 261 "config_parser.yy"
|
#line 261 "config_parser.yy"
|
||||||
{
|
{
|
||||||
m_Array = make_shared<Dictionary>();
|
m_Array = boost::make_shared<Dictionary>();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ object:
|
|||||||
}
|
}
|
||||||
attributes T_OBJECT T_IDENTIFIER T_STRING
|
attributes T_OBJECT T_IDENTIFIER T_STRING
|
||||||
{
|
{
|
||||||
m_Object = make_shared<ConfigItem>($4, $5, yylloc);
|
m_Object = boost::make_shared<ConfigItem>($4, $5, yylloc);
|
||||||
free($4);
|
free($4);
|
||||||
free($5);
|
free($5);
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ inherits_specifier: /* empty */
|
|||||||
|
|
||||||
expressionlist: '{'
|
expressionlist: '{'
|
||||||
{
|
{
|
||||||
m_ExpressionLists.push(make_shared<ExpressionList>());
|
m_ExpressionLists.push(boost::make_shared<ExpressionList>());
|
||||||
}
|
}
|
||||||
expressions
|
expressions
|
||||||
'}'
|
'}'
|
||||||
@ -207,7 +207,7 @@ expression: T_IDENTIFIER operator value
|
|||||||
free($3);
|
free($3);
|
||||||
delete $6;
|
delete $6;
|
||||||
|
|
||||||
ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
|
ExpressionList::Ptr subexprl = boost::make_shared<ExpressionList>();
|
||||||
subexprl->AddExpression(subexpr);
|
subexprl->AddExpression(subexpr);
|
||||||
|
|
||||||
Expression expr($1, OperatorPlus, subexprl, yylloc);
|
Expression expr($1, OperatorPlus, subexprl, yylloc);
|
||||||
@ -259,7 +259,7 @@ value: simplevalue
|
|||||||
|
|
||||||
tuple: '('
|
tuple: '('
|
||||||
{
|
{
|
||||||
m_Array = make_shared<Dictionary>();
|
m_Array = boost::make_shared<Dictionary>();
|
||||||
}
|
}
|
||||||
tupleitems
|
tupleitems
|
||||||
')'
|
')'
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "i2-dyn.h"
|
#include "i2-dyn.h"
|
||||||
|
|
||||||
|
using std::ifstream;
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
ConfigCompiler::ConfigCompiler(istream *input)
|
ConfigCompiler::ConfigCompiler(istream *input)
|
||||||
@ -35,7 +37,7 @@ ConfigCompiler::~ConfigCompiler(void)
|
|||||||
size_t ConfigCompiler::ReadInput(char *buffer, size_t max_size)
|
size_t ConfigCompiler::ReadInput(char *buffer, size_t max_size)
|
||||||
{
|
{
|
||||||
m_Input->read(buffer, max_size);
|
m_Input->read(buffer, max_size);
|
||||||
return m_Input->gcount();
|
return static_cast<size_t>(m_Input->gcount());
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ConfigCompiler::GetScanner(void) const
|
void *ConfigCompiler::GetScanner(void) const
|
||||||
|
@ -79,7 +79,7 @@ ObjectSet<ConfigItem::Ptr>::Ptr ConfigItem::GetAllObjects(void)
|
|||||||
static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
|
static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
|
||||||
|
|
||||||
if (!allObjects) {
|
if (!allObjects) {
|
||||||
allObjects = make_shared<ObjectSet<ConfigItem::Ptr> >();
|
allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
|
||||||
allObjects->Start();
|
allObjects->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ ConfigItem::TNMap::Ptr ConfigItem::GetObjectsByTypeAndName(void)
|
|||||||
static ConfigItem::TNMap::Ptr tnmap;
|
static ConfigItem::TNMap::Ptr tnmap;
|
||||||
|
|
||||||
if (!tnmap) {
|
if (!tnmap) {
|
||||||
tnmap = make_shared<ConfigItem::TNMap>(GetAllObjects(), &ConfigItem::GetTypeAndName);
|
tnmap = boost::make_shared<ConfigItem::TNMap>(GetAllObjects(), &ConfigItem::GetTypeAndName);
|
||||||
tnmap->Start();
|
tnmap->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,14 +109,14 @@ void ConfigItem::Commit(void)
|
|||||||
{
|
{
|
||||||
ConfigObject::Ptr dobj = m_ConfigObject.lock();
|
ConfigObject::Ptr dobj = m_ConfigObject.lock();
|
||||||
|
|
||||||
Dictionary::Ptr properties = make_shared<Dictionary>();
|
Dictionary::Ptr properties = boost::make_shared<Dictionary>();
|
||||||
CalculateProperties(properties);
|
CalculateProperties(properties);
|
||||||
|
|
||||||
if (!dobj)
|
if (!dobj)
|
||||||
dobj = ConfigObject::GetObject(GetType(), GetName());
|
dobj = ConfigObject::GetObject(GetType(), GetName());
|
||||||
|
|
||||||
if (!dobj)
|
if (!dobj)
|
||||||
dobj = make_shared<ConfigObject>(properties);
|
dobj = boost::make_shared<ConfigObject>(properties);
|
||||||
else
|
else
|
||||||
dobj->SetProperties(properties);
|
dobj->SetProperties(properties);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
|||||||
switch (m_Operator) {
|
switch (m_Operator) {
|
||||||
case OperatorSet:
|
case OperatorSet:
|
||||||
if (exprl) {
|
if (exprl) {
|
||||||
Dictionary::Ptr dict = make_shared<Dictionary>();
|
Dictionary::Ptr dict = boost::make_shared<Dictionary>();
|
||||||
exprl->Execute(dict);
|
exprl->Execute(dict);
|
||||||
newValue = dict;
|
newValue = dict;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
|||||||
throw domain_error(message.str());
|
throw domain_error(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
dict = make_shared<Dictionary>();
|
dict = boost::make_shared<Dictionary>();
|
||||||
}
|
}
|
||||||
|
|
||||||
exprl->Execute(dict);
|
exprl->Execute(dict);
|
||||||
|
@ -32,6 +32,12 @@
|
|||||||
#include <stack>
|
#include <stack>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
using std::stack;
|
||||||
|
using std::istream;
|
||||||
|
using std::ostream;
|
||||||
|
using std::cin;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
#ifdef I2_DYN_BUILD
|
#ifdef I2_DYN_BUILD
|
||||||
# define I2_DYN_API I2_EXPORT
|
# define I2_DYN_API I2_EXPORT
|
||||||
#else /* I2_DYN_BUILD */
|
#else /* I2_DYN_BUILD */
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#include <i2-dyn.h>
|
#include <i2-dyn.h>
|
||||||
//#include <i2-jsonrpc.h>
|
//#include <i2-jsonrpc.h>
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -38,6 +38,6 @@ int main(int argc, char **argv)
|
|||||||
LTDL_SET_PRELOADED_SYMBOLS();
|
LTDL_SET_PRELOADED_SYMBOLS();
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
IcingaApplication::Ptr instance = make_shared<IcingaApplication>();
|
IcingaApplication::Ptr instance = boost::make_shared<IcingaApplication>();
|
||||||
return instance->Run(argc, argv);
|
return instance->Run(argc, argv);
|
||||||
}
|
}
|
||||||
|
@ -74,9 +74,9 @@ void EndpointManager::AddListener(string service)
|
|||||||
|
|
||||||
stringstream s;
|
stringstream s;
|
||||||
s << "Adding new listener: port " << service;
|
s << "Adding new listener: port " << service;
|
||||||
Application::Log(s.str());
|
Application::Log(LogInformation, "icinga", s.str());
|
||||||
|
|
||||||
JsonRpcServer::Ptr server = make_shared<JsonRpcServer>(m_SSLContext);
|
JsonRpcServer::Ptr server = boost::make_shared<JsonRpcServer>(m_SSLContext);
|
||||||
RegisterServer(server);
|
RegisterServer(server);
|
||||||
|
|
||||||
server->Bind(service, AF_INET6);
|
server->Bind(service, AF_INET6);
|
||||||
@ -94,9 +94,9 @@ void EndpointManager::AddConnection(string node, string service)
|
|||||||
{
|
{
|
||||||
stringstream s;
|
stringstream s;
|
||||||
s << "Adding new endpoint: [" << node << "]:" << service;
|
s << "Adding new endpoint: [" << node << "]:" << service;
|
||||||
Application::Log(s.str());
|
Application::Log(LogInformation, "icinga", s.str());
|
||||||
|
|
||||||
JsonRpcEndpoint::Ptr endpoint = make_shared<JsonRpcEndpoint>();
|
JsonRpcEndpoint::Ptr endpoint = boost::make_shared<JsonRpcEndpoint>();
|
||||||
RegisterEndpoint(endpoint);
|
RegisterEndpoint(endpoint);
|
||||||
endpoint->Connect(node, service, m_SSLContext);
|
endpoint->Connect(node, service, m_SSLContext);
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ void EndpointManager::AddConnection(string node, string service)
|
|||||||
void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
|
void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
|
||||||
{
|
{
|
||||||
m_Servers.push_back(server);
|
m_Servers.push_back(server);
|
||||||
server->OnNewClient.connect(bind(&EndpointManager::NewClientHandler,
|
server->OnNewClient.connect(boost::bind(&EndpointManager::NewClientHandler,
|
||||||
this, _1));
|
this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,16 +118,14 @@ void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
|
|||||||
*
|
*
|
||||||
* @param ncea Event arguments.
|
* @param ncea Event arguments.
|
||||||
*/
|
*/
|
||||||
int EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
|
void EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
|
||||||
{
|
{
|
||||||
string address = ncea.Client->GetPeerAddress();
|
string address = ncea.Client->GetPeerAddress();
|
||||||
Application::Log("Accepted new client from " + address);
|
Application::Log(LogInformation, "icinga", "Accepted new client from " + address);
|
||||||
|
|
||||||
JsonRpcEndpoint::Ptr endpoint = make_shared<JsonRpcEndpoint>();
|
JsonRpcEndpoint::Ptr endpoint = boost::make_shared<JsonRpcEndpoint>();
|
||||||
endpoint->SetClient(static_pointer_cast<JsonRpcClient>(ncea.Client));
|
endpoint->SetClient(static_pointer_cast<JsonRpcClient>(ncea.Client));
|
||||||
RegisterEndpoint(endpoint);
|
RegisterEndpoint(endpoint);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,7 +257,7 @@ void EndpointManager::SendMulticastMessage(Endpoint::Ptr sender,
|
|||||||
*
|
*
|
||||||
* @param callback The callback function.
|
* @param callback The callback function.
|
||||||
*/
|
*/
|
||||||
void EndpointManager::ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback)
|
void EndpointManager::ForEachEndpoint(function<void (const NewEndpointEventArgs&)> callback)
|
||||||
{
|
{
|
||||||
NewEndpointEventArgs neea;
|
NewEndpointEventArgs neea;
|
||||||
neea.Source = shared_from_this();
|
neea.Source = shared_from_this();
|
||||||
@ -292,7 +290,7 @@ Endpoint::Ptr EndpointManager::GetEndpointByIdentity(string identity) const
|
|||||||
|
|
||||||
void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
|
void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
|
||||||
RequestMessage& message,
|
RequestMessage& message,
|
||||||
function<int(const NewResponseEventArgs&)> callback, time_t timeout)
|
function<void(const NewResponseEventArgs&)> callback, time_t timeout)
|
||||||
{
|
{
|
||||||
m_NextMessageID++;
|
m_NextMessageID++;
|
||||||
|
|
||||||
@ -326,8 +324,8 @@ void EndpointManager::RescheduleRequestTimer(void)
|
|||||||
&EndpointManager::RequestTimeoutLessComparer);
|
&EndpointManager::RequestTimeoutLessComparer);
|
||||||
|
|
||||||
if (!m_RequestTimer) {
|
if (!m_RequestTimer) {
|
||||||
m_RequestTimer = make_shared<Timer>();
|
m_RequestTimer = boost::make_shared<Timer>();
|
||||||
m_RequestTimer->OnTimerExpired.connect(bind(&EndpointManager::RequestTimerHandler, this, _1));
|
m_RequestTimer->OnTimerExpired.connect(boost::bind(&EndpointManager::RequestTimerHandler, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it != m_Requests.end()) {
|
if (it != m_Requests.end()) {
|
||||||
@ -342,7 +340,7 @@ void EndpointManager::RescheduleRequestTimer(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int EndpointManager::RequestTimerHandler(const TimerEventArgs& ea)
|
void EndpointManager::RequestTimerHandler(void)
|
||||||
{
|
{
|
||||||
map<string, PendingRequest>::iterator it;
|
map<string, PendingRequest>::iterator it;
|
||||||
for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
|
for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
|
||||||
@ -361,8 +359,6 @@ int EndpointManager::RequestTimerHandler(const TimerEventArgs& ea)
|
|||||||
}
|
}
|
||||||
|
|
||||||
RescheduleRequestTimer();
|
RescheduleRequestTimer();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message)
|
void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message)
|
||||||
|
@ -44,7 +44,7 @@ struct I2_ICINGA_API PendingRequest
|
|||||||
{
|
{
|
||||||
time_t Timeout;
|
time_t Timeout;
|
||||||
RequestMessage Request;
|
RequestMessage Request;
|
||||||
function<int(const NewResponseEventArgs&)> Callback;
|
function<void(const NewResponseEventArgs&)> Callback;
|
||||||
|
|
||||||
bool HasTimedOut(void) const
|
bool HasTimedOut(void) const
|
||||||
{
|
{
|
||||||
@ -97,11 +97,11 @@ public:
|
|||||||
void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
|
void SendMulticastMessage(Endpoint::Ptr sender, const RequestMessage& message);
|
||||||
|
|
||||||
void SendAPIMessage(Endpoint::Ptr sender, RequestMessage& message,
|
void SendAPIMessage(Endpoint::Ptr sender, RequestMessage& message,
|
||||||
function<int(const NewResponseEventArgs&)> callback, time_t timeout = 10);
|
function<void(const NewResponseEventArgs&)> callback, time_t timeout = 10);
|
||||||
|
|
||||||
void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
|
void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
|
||||||
|
|
||||||
void ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback);
|
void ForEachEndpoint(function<void (const NewEndpointEventArgs&)> callback);
|
||||||
|
|
||||||
Endpoint::Ptr GetEndpointByIdentity(string identity) const;
|
Endpoint::Ptr GetEndpointByIdentity(string identity) const;
|
||||||
|
|
||||||
@ -123,9 +123,9 @@ private:
|
|||||||
|
|
||||||
static bool RequestTimeoutLessComparer(const pair<string, PendingRequest>& a, const pair<string, PendingRequest>& b);
|
static bool RequestTimeoutLessComparer(const pair<string, PendingRequest>& a, const pair<string, PendingRequest>& b);
|
||||||
void RescheduleRequestTimer(void);
|
void RescheduleRequestTimer(void);
|
||||||
int RequestTimerHandler(const TimerEventArgs& ea);
|
void RequestTimerHandler(void);
|
||||||
|
|
||||||
int NewClientHandler(const NewClientEventArgs& ncea);
|
void NewClientHandler(const NewClientEventArgs& ncea);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,31 +37,33 @@ using namespace icinga;
|
|||||||
int IcingaApplication::Main(const vector<string>& args)
|
int IcingaApplication::Main(const vector<string>& args)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Application::Log("Icinga component loader");
|
Application::Log(LogInformation, "icinga", "Icinga component loader");
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
Application::Log("Icinga component loader (version: " ICINGA_VERSION ")");
|
Application::Log(LogInformation, "icinga", "Icinga component loader (version: " ICINGA_VERSION ")");
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
cout << "Syntax: " << args[0] << " <config-file>" << endl;
|
stringstream msgbuf;
|
||||||
|
msgbuf << "Syntax: " << args[0] << " <config-file>";
|
||||||
|
Application::Log(LogInformation, "icinga", msgbuf.str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_EndpointManager = make_shared<EndpointManager>();
|
m_EndpointManager = boost::make_shared<EndpointManager>();
|
||||||
|
|
||||||
string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
|
string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
|
||||||
AddComponentSearchDir(componentDirectory);
|
AddComponentSearchDir(componentDirectory);
|
||||||
|
|
||||||
/* register handler for 'component' config objects */
|
/* register handler for 'component' config objects */
|
||||||
static ConfigObject::Set::Ptr componentObjects = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
|
static ConfigObject::Set::Ptr componentObjects = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
|
||||||
function<int (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = bind(&IcingaApplication::NewComponentHandler, this, _1);
|
function<void (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = boost::bind(&IcingaApplication::NewComponentHandler, this, _1);
|
||||||
componentObjects->OnObjectAdded.connect(NewComponentHandler);
|
componentObjects->OnObjectAdded.connect(NewComponentHandler);
|
||||||
componentObjects->OnObjectCommitted.connect(NewComponentHandler);
|
componentObjects->OnObjectCommitted.connect(NewComponentHandler);
|
||||||
componentObjects->OnObjectRemoved.connect(bind(&IcingaApplication::DeletedComponentHandler, this, _1));
|
componentObjects->OnObjectRemoved.connect(boost::bind(&IcingaApplication::DeletedComponentHandler, this, _1));
|
||||||
componentObjects->Start();
|
componentObjects->Start();
|
||||||
|
|
||||||
/* load config file */
|
/* load config file */
|
||||||
ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
|
ConfigObject::Ptr fileComponentConfig = boost::make_shared<ConfigObject>("component", "configfile");
|
||||||
fileComponentConfig->SetLocal(true);
|
fileComponentConfig->SetLocal(true);
|
||||||
fileComponentConfig->SetProperty("configFilename", args[1]);
|
fileComponentConfig->SetProperty("configFilename", args[1]);
|
||||||
fileComponentConfig->Commit();
|
fileComponentConfig->Commit();
|
||||||
@ -84,7 +86,7 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||||||
/* set up SSL context */
|
/* set up SSL context */
|
||||||
shared_ptr<X509> cert = Utility::GetX509Certificate(GetPublicKeyFile());
|
shared_ptr<X509> cert = Utility::GetX509Certificate(GetPublicKeyFile());
|
||||||
string identity = Utility::GetCertificateCN(cert);
|
string identity = Utility::GetCertificateCN(cert);
|
||||||
Application::Log("My identity: " + identity);
|
Application::Log(LogInformation, "icinga", "My identity: " + identity);
|
||||||
m_EndpointManager->SetIdentity(identity);
|
m_EndpointManager->SetIdentity(identity);
|
||||||
|
|
||||||
shared_ptr<SSL_CTX> sslContext = Utility::MakeSSLContext(GetPublicKeyFile(), GetPrivateKeyFile(), GetCAKeyFile());
|
shared_ptr<SSL_CTX> sslContext = Utility::MakeSSLContext(GetPublicKeyFile(), GetPrivateKeyFile(), GetCAKeyFile());
|
||||||
@ -111,7 +113,7 @@ EndpointManager::Ptr IcingaApplication::GetEndpointManager(void)
|
|||||||
return m_EndpointManager;
|
return m_EndpointManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
void IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = ea.Target;
|
ConfigObject::Ptr object = ea.Target;
|
||||||
|
|
||||||
@ -129,18 +131,14 @@ int IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
LoadComponent(path, object);
|
LoadComponent(path, object);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int IcingaApplication::DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
void IcingaApplication::DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
|
||||||
{
|
{
|
||||||
ConfigObject::Ptr object = ea.Target;
|
ConfigObject::Ptr object = ea.Target;
|
||||||
|
|
||||||
Component::Ptr component = GetComponent(object->GetName());
|
Component::Ptr component = GetComponent(object->GetName());
|
||||||
UnregisterComponent(component);
|
UnregisterComponent(component);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string IcingaApplication::GetPrivateKeyFile(void) const
|
string IcingaApplication::GetPrivateKeyFile(void) const
|
||||||
|
@ -53,14 +53,8 @@ private:
|
|||||||
string m_Node;
|
string m_Node;
|
||||||
string m_Service;
|
string m_Service;
|
||||||
|
|
||||||
int NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||||
int DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
void DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
|
||||||
|
|
||||||
int NewRpcListenerHandler(const EventArgs& ea);
|
|
||||||
int DeletedRpcListenerHandler(const EventArgs& ea);
|
|
||||||
|
|
||||||
int NewRpcConnectionHandler(const EventArgs& ea);
|
|
||||||
int DeletedRpcConnectionHandler(const EventArgs& ea);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ JsonRpcClient::Ptr JsonRpcEndpoint::GetClient(void)
|
|||||||
|
|
||||||
void JsonRpcEndpoint::Connect(string node, string service, shared_ptr<SSL_CTX> sslContext)
|
void JsonRpcEndpoint::Connect(string node, string service, shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
JsonRpcClient::Ptr client = make_shared<JsonRpcClient>(RoleOutbound, sslContext);
|
JsonRpcClient::Ptr client = boost::make_shared<JsonRpcClient>(RoleOutbound, sslContext);
|
||||||
SetClient(client);
|
SetClient(client);
|
||||||
client->Connect(node, service);
|
client->Connect(node, service);
|
||||||
client->Start();
|
client->Start();
|
||||||
@ -45,10 +45,10 @@ void JsonRpcEndpoint::Connect(string node, string service, shared_ptr<SSL_CTX> s
|
|||||||
void JsonRpcEndpoint::SetClient(JsonRpcClient::Ptr client)
|
void JsonRpcEndpoint::SetClient(JsonRpcClient::Ptr client)
|
||||||
{
|
{
|
||||||
m_Client = client;
|
m_Client = client;
|
||||||
client->OnNewMessage.connect(bind(&JsonRpcEndpoint::NewMessageHandler, this, _1));
|
client->OnNewMessage.connect(boost::bind(&JsonRpcEndpoint::NewMessageHandler, this, _1));
|
||||||
client->OnClosed.connect(bind(&JsonRpcEndpoint::ClientClosedHandler, this, _1));
|
client->OnClosed.connect(boost::bind(&JsonRpcEndpoint::ClientClosedHandler, this, _1));
|
||||||
client->OnError.connect(bind(&JsonRpcEndpoint::ClientErrorHandler, this, _1));
|
client->OnError.connect(boost::bind(&JsonRpcEndpoint::ClientErrorHandler, this, _1));
|
||||||
client->OnVerifyCertificate.connect(bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _1));
|
client->OnVerifyCertificate.connect(boost::bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonRpcEndpoint::IsLocal(void) const
|
bool JsonRpcEndpoint::IsLocal(void) const
|
||||||
@ -80,7 +80,7 @@ void JsonRpcEndpoint::ProcessResponse(Endpoint::Ptr sender, const ResponseMessag
|
|||||||
m_Client->SendMessage(message);
|
m_Client->SendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
|
void JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
|
||||||
{
|
{
|
||||||
const MessagePart& message = nmea.Message;
|
const MessagePart& message = nmea.Message;
|
||||||
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
|
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
|
||||||
@ -89,15 +89,15 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
|
|||||||
/* rather than routing the message to the right virtual
|
/* rather than routing the message to the right virtual
|
||||||
* endpoint we just process it here right away. */
|
* endpoint we just process it here right away. */
|
||||||
GetEndpointManager()->ProcessResponseMessage(sender, message);
|
GetEndpointManager()->ProcessResponseMessage(sender, message);
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string method;
|
string method;
|
||||||
if (!message.GetProperty("method", &method))
|
if (!message.GetProperty("method", &method))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
if (!HasPublication(method))
|
if (!HasPublication(method))
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
RequestMessage request = message;
|
RequestMessage request = message;
|
||||||
|
|
||||||
@ -106,13 +106,11 @@ int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
|
|||||||
GetEndpointManager()->SendAnycastMessage(sender, request);
|
GetEndpointManager()->SendAnycastMessage(sender, request);
|
||||||
else
|
else
|
||||||
GetEndpointManager()->SendMulticastMessage(sender, request);
|
GetEndpointManager()->SendMulticastMessage(sender, request);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
|
void JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
Application::Log("Lost connection to endpoint: identity=" + GetIdentity());
|
Application::Log(LogWarning, "jsonrpc", "Lost connection to endpoint: identity=" + GetIdentity());
|
||||||
|
|
||||||
m_PendingCalls.clear();
|
m_PendingCalls.clear();
|
||||||
|
|
||||||
@ -130,18 +128,17 @@ int JsonRpcEndpoint::ClientClosedHandler(const EventArgs&)
|
|||||||
m_Client.reset();
|
m_Client.reset();
|
||||||
|
|
||||||
// TODO: persist events, etc., for now we just disable the endpoint
|
// TODO: persist events, etc., for now we just disable the endpoint
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int JsonRpcEndpoint::ClientErrorHandler(const SocketErrorEventArgs& ea)
|
void JsonRpcEndpoint::ClientErrorHandler(const SocketErrorEventArgs& ea)
|
||||||
{
|
{
|
||||||
cerr << "Error occured for JSON-RPC socket: Message=" << ea.Exception.what() << endl;
|
stringstream message;
|
||||||
|
message << "Error occured for JSON-RPC socket: Message=" << ea.Exception.what();
|
||||||
|
|
||||||
return 0;
|
Application::Log(LogWarning, "jsonrpc", message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs& ea)
|
void JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs& ea)
|
||||||
{
|
{
|
||||||
if (ea.Certificate && ea.ValidCertificate) {
|
if (ea.Certificate && ea.ValidCertificate) {
|
||||||
string identity = Utility::GetCertificateCN(ea.Certificate);
|
string identity = Utility::GetCertificateCN(ea.Certificate);
|
||||||
@ -149,8 +146,6 @@ int JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs&
|
|||||||
if (GetIdentity().empty() && !identity.empty())
|
if (GetIdentity().empty() && !identity.empty())
|
||||||
SetIdentity(identity);
|
SetIdentity(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRpcEndpoint::Stop(void)
|
void JsonRpcEndpoint::Stop(void)
|
||||||
|
@ -58,10 +58,10 @@ private:
|
|||||||
JsonRpcClient::Ptr m_Client;
|
JsonRpcClient::Ptr m_Client;
|
||||||
map<string, Endpoint::Ptr> m_PendingCalls;
|
map<string, Endpoint::Ptr> m_PendingCalls;
|
||||||
|
|
||||||
int NewMessageHandler(const NewMessageEventArgs& nmea);
|
void NewMessageHandler(const NewMessageEventArgs& nmea);
|
||||||
int ClientClosedHandler(const EventArgs& ea);
|
void ClientClosedHandler(const EventArgs& ea);
|
||||||
int ClientErrorHandler(const SocketErrorEventArgs& ea);
|
void ClientErrorHandler(const SocketErrorEventArgs& ea);
|
||||||
int VerifyCertificateHandler(const VerifyCertificateEventArgs& ea);
|
void VerifyCertificateHandler(const VerifyCertificateEventArgs& ea);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ CheckResult NagiosCheckTask::Execute(void) const
|
|||||||
|
|
||||||
string command = m_Command + " 2>&1";
|
string command = m_Command + " 2>&1";
|
||||||
|
|
||||||
Application::Log("Nagios check command: " + command);
|
Application::Log(LogDebug, "icinga", "Nagios check command: " + command);
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
fp = _popen(command.c_str(), "r");
|
fp = _popen(command.c_str(), "r");
|
||||||
@ -39,7 +39,7 @@ CheckResult NagiosCheckTask::Execute(void) const
|
|||||||
|
|
||||||
cr.Output = output.str();
|
cr.Output = output.str();
|
||||||
|
|
||||||
Application::Log("Nagios plugin output: " + cr.Output);
|
Application::Log(LogDebug, "icinga", "Nagios plugin output: " + cr.Output);
|
||||||
|
|
||||||
int status, exitcode;
|
int status, exitcode;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@ -85,5 +85,5 @@ CheckTask::Ptr NagiosCheckTask::CreateTask(const Service& service)
|
|||||||
{
|
{
|
||||||
assert(service.GetCheckType() == "nagios");
|
assert(service.GetCheckType() == "nagios");
|
||||||
|
|
||||||
return make_shared<NagiosCheckTask>(service);
|
return boost::make_shared<NagiosCheckTask>(service);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ bool VirtualEndpoint::IsConnected(void) const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualEndpoint::RegisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback)
|
void VirtualEndpoint::RegisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback)
|
||||||
{
|
{
|
||||||
map<string, shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > >::iterator it;
|
map<string, shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > >::iterator it;
|
||||||
it = m_TopicHandlers.find(topic);
|
it = m_TopicHandlers.find(topic);
|
||||||
@ -46,7 +46,7 @@ void VirtualEndpoint::RegisterTopicHandler(string topic, function<int (const New
|
|||||||
shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > sig;
|
shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > sig;
|
||||||
|
|
||||||
if (it == m_TopicHandlers.end()) {
|
if (it == m_TopicHandlers.end()) {
|
||||||
sig = make_shared<boost::signal<void (const NewRequestEventArgs&)> >();
|
sig = boost::make_shared<boost::signal<void (const NewRequestEventArgs&)> >();
|
||||||
m_TopicHandlers.insert(make_pair(topic, sig));
|
m_TopicHandlers.insert(make_pair(topic, sig));
|
||||||
} else {
|
} else {
|
||||||
sig = it->second;
|
sig = it->second;
|
||||||
@ -57,7 +57,7 @@ void VirtualEndpoint::RegisterTopicHandler(string topic, function<int (const New
|
|||||||
RegisterSubscription(topic);
|
RegisterSubscription(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualEndpoint::UnregisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback)
|
void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback)
|
||||||
{
|
{
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
//m_TopicHandlers[method] -= callback;
|
//m_TopicHandlers[method] -= callback;
|
||||||
|
@ -45,8 +45,8 @@ public:
|
|||||||
typedef shared_ptr<VirtualEndpoint> Ptr;
|
typedef shared_ptr<VirtualEndpoint> Ptr;
|
||||||
typedef weak_ptr<VirtualEndpoint> WeakPtr;
|
typedef weak_ptr<VirtualEndpoint> WeakPtr;
|
||||||
|
|
||||||
void RegisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback);
|
void RegisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback);
|
||||||
void UnregisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback);
|
void UnregisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback);
|
||||||
|
|
||||||
virtual string GetAddress(void) const;
|
virtual string GetAddress(void) const;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ void JsonRpcClient::Start(void)
|
|||||||
{
|
{
|
||||||
TlsClient::Start();
|
TlsClient::Start();
|
||||||
|
|
||||||
OnDataAvailable.connect(bind(&JsonRpcClient::DataAvailableHandler, this, _1));
|
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
|
|||||||
* @param - Event arguments for the event.
|
* @param - Event arguments for the event.
|
||||||
* @returns 0
|
* @returns 0
|
||||||
*/
|
*/
|
||||||
int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
void JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
try {
|
try {
|
||||||
@ -61,7 +61,7 @@ int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
|||||||
MessagePart message;
|
MessagePart message;
|
||||||
|
|
||||||
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
|
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
|
||||||
break;
|
return;
|
||||||
|
|
||||||
message = MessagePart(jsonString);
|
message = MessagePart(jsonString);
|
||||||
|
|
||||||
@ -70,14 +70,12 @@ int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
|||||||
nea.Message = message;
|
nea.Message = message;
|
||||||
OnNewMessage(nea);
|
OnNewMessage(nea);
|
||||||
} catch (const Exception& ex) {
|
} catch (const Exception& ex) {
|
||||||
Application::Log("Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
|
Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.GetMessage()));
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,5 +87,5 @@ int JsonRpcClient::DataAvailableHandler(const EventArgs&)
|
|||||||
*/
|
*/
|
||||||
JsonRpcClient::Ptr icinga::JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
JsonRpcClient::Ptr icinga::JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
return make_shared<JsonRpcClient>(role, sslContext);
|
return boost::make_shared<JsonRpcClient>(role, sslContext);
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
boost::signal<void (const NewMessageEventArgs&)> OnNewMessage;
|
boost::signal<void (const NewMessageEventArgs&)> OnNewMessage;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int DataAvailableHandler(const EventArgs&);
|
void DataAvailableHandler(const EventArgs&);
|
||||||
};
|
};
|
||||||
|
|
||||||
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
|
||||||
|
@ -28,5 +28,5 @@ using namespace icinga;
|
|||||||
*/
|
*/
|
||||||
JsonRpcServer::JsonRpcServer(shared_ptr<SSL_CTX> sslContext)
|
JsonRpcServer::JsonRpcServer(shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
SetClientFactory(bind(&JsonRpcClientFactory, RoleInbound, sslContext));
|
SetClientFactory(boost::bind(&JsonRpcClientFactory, RoleInbound, sslContext));
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ using namespace icinga;
|
|||||||
*/
|
*/
|
||||||
MessagePart::MessagePart(void)
|
MessagePart::MessagePart(void)
|
||||||
{
|
{
|
||||||
m_Dictionary = make_shared<Dictionary>();
|
m_Dictionary = boost::make_shared<Dictionary>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,7 +76,7 @@ MessagePart::MessagePart(const MessagePart& message)
|
|||||||
*/
|
*/
|
||||||
Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
|
Dictionary::Ptr MessagePart::GetDictionaryFromJson(json_t *json)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr dictionary = make_shared<Dictionary>();
|
Dictionary::Ptr dictionary = boost::make_shared<Dictionary>();
|
||||||
|
|
||||||
for (cJSON *i = json->child; i != NULL; i = i->next) {
|
for (cJSON *i = json->child; i != NULL; i = i->next) {
|
||||||
switch (i->type) {
|
switch (i->type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user