component.h \
configobject.cpp \
configobject.h \
- cxx11-compat.h \
- delegate.h \
dictionary.cpp \
dictionary.h \
- observable.h \
exception.cpp \
exception.h \
fifo.cpp \
# include <ltdl.h>
#endif
+using std::cout;
+using std::endl;
+
using namespace icinga;
Application::Ptr I2_EXPORT Application::m_Instance;
Component::Ptr component;
Component *(*pCreateComponent)();
- Log("Loading component '" + path + "'");
+ Log(LogInformation, "base", "Loading component '" + path + "'");
#ifdef _WIN32
HMODULE hModule = LoadLibrary(path.c_str());
{
string name = component->GetName();
- Log("Unloading component '" + name + "'");
+ Log(LogInformation, "base", "Unloading component '" + name + "'");
map<string, Component::Ptr>::iterator i = m_Components.find(name);
if (i != m_Components.end())
m_Components.erase(i);
/**
* Writes a message to the application's log.
*
+ * @param severity The message severity.
+ * @param facility The log facility.
* @param message The message.
*/
-void Application::Log(string message)
+void Application::Log(LogSeverity severity, string facility, string message)
{
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(&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;
}
/**
} catch (const std::exception& ex) {
Application::m_Instance.reset();
- Application::Log("---");
- Application::Log("Exception: " + Utility::GetTypeName(ex));
- Application::Log("Message: " + string(ex.what()));
+ Application::Log(LogCritical, "base", "---");
+ Application::Log(LogCritical, "base", "Exception: " + Utility::GetTypeName(ex));
+ Application::Log(LogCritical, "base", "Message: " + string(ex.what()));
return EXIT_FAILURE;
}
namespace icinga {
+enum LogSeverity
+{
+ LogDebug,
+ LogInformation,
+ LogWarning,
+ LogCritical
+};
+
class Component;
/**
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,
const ConfigObject::Ptr& componentConfig);
<ClInclude Include="application.h" />
<ClInclude Include="component.h" />
<ClInclude Include="configobject.h" />
- <ClInclude Include="cxx11-compat.h" />
- <ClInclude Include="delegate.h" />
<ClInclude Include="dictionary.h" />
+ <ClInclude Include="eventargs.h" />
<ClInclude Include="objectmap.h" />
<ClInclude Include="objectset.h" />
- <ClInclude Include="observable.h" />
<ClInclude Include="exception.h" />
<ClInclude Include="fifo.h" />
<ClInclude Include="i2-base.h" />
ConfigObject::ConfigObject(Dictionary::Ptr properties, const ConfigObject::Set::Ptr& container)
: 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)
: 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("__name", name);
static ObjectSet<ConfigObject::Ptr>::Ptr allObjects;
if (!allObjects) {
- allObjects = make_shared<ObjectSet<ConfigObject::Ptr> >();
+ allObjects = boost::make_shared<ObjectSet<ConfigObject::Ptr> >();
allObjects->Start();
}
static ConfigObject::TNMap::Ptr tnmap;
if (!tnmap) {
- tnmap = make_shared<ConfigObject::TNMap>(GetAllObjects(), &ConfigObject::TypeAndNameGetter);
+ tnmap = boost::make_shared<ConfigObject::TNMap>(GetAllObjects(), &ConfigObject::TypeAndNameGetter);
tnmap->Start();
}
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)
static ObjectMap<string, ConfigObject::Ptr>::Ptr tmap;
if (!tmap) {
- tmap = make_shared<ConfigObject::TMap>(GetAllObjects(), &ConfigObject::TypeGetter);
+ tmap = boost::make_shared<ConfigObject::TMap>(GetAllObjects(), &ConfigObject::TypeGetter);
tmap->Start();
}
+++ /dev/null
-/******************************************************************************
- * Icinga 2 *
- * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License *
- * as published by the Free Software Foundation; either version 2 *
- * of the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software Foundation *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
- ******************************************************************************/
-
-#ifndef 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 */
if (rc != 0) {
result = string(message);
LocalFree(message);
+
+ /* remove trailing new-line characters */
+ boost::algorithm::trim_right(result);
}
return result;
#include "i2-base.h"
+using std::bad_alloc;
+
using namespace icinga;
/**
*/
#ifdef _MSC_VER
-# define HAVE_STDCXX_0X
# pragma warning(disable:4251)
# pragma warning(disable:4275)
# define _CRT_SECURE_NO_DEPRECATE
#include <list>
#include <algorithm>
-using namespace std;
-
-#ifdef HAVE_STDCXX_0X
-# include <memory>
-# include <functional>
-
-using namespace std::placeholders;
-
-#else /* HAVE_STDCXX_0X */
-# ifdef HAVE_BOOST
-# 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 */
-
+using std::string;
+using std::vector;
+using std::map;
+using std::list;
+using std::set;
+using std::multimap;
+using std::pair;
+
+using std::stringstream;
+
+using std::runtime_error;
+using std::logic_error;
+using std::invalid_argument;
+using std::domain_error;
+
+#include <boost/smart_ptr.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.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__)
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
void Start(void)
{
- m_Parent->OnObjectAdded.connect(bind(&ObjectMap::ObjectAddedHandler, this, _1));
- m_Parent->OnObjectCommitted.connect(bind(&ObjectMap::ObjectCommittedHandler, this, _1));
- m_Parent->OnObjectRemoved.connect(bind(&ObjectMap::ObjectRemovedHandler, this, _1));
+ m_Parent->OnObjectAdded.connect(boost::bind(&ObjectMap::ObjectAddedHandler, this, _1));
+ m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectMap::ObjectCommittedHandler, 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++)
AddObject(*it);
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;
ea.Source = shared_from_this();
AddObject(object);
}
- int ObjectAddedHandler(const ObjectSetEventArgs<TValue>& ea)
+ void ObjectAddedHandler(const ObjectSetEventArgs<TValue>& ea)
{
AddObject(ea.Target);
-
- return 0;
}
- int ObjectCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
+ void ObjectCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
{
CheckObject(ea.Target);
-
- return 0;
}
- int ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
+ void ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
{
RemoveObject(ea.Target);
-
- return 0;
}
};
void Start(void)
{
if (m_Parent) {
- m_Parent->OnObjectAdded.connect(bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
- m_Parent->OnObjectCommitted.connect(bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
- m_Parent->OnObjectRemoved.connect(bind(&ObjectSet::ObjectRemovedHandler, this, _1));
+ m_Parent->OnObjectAdded.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
+ m_Parent->OnObjectCommitted.connect(boost::bind(&ObjectSet::ObjectAddedOrCommittedHandler, this, _1));
+ m_Parent->OnObjectRemoved.connect(boost::bind(&ObjectSet::ObjectRemovedHandler, this, _1));
for (ObjectSet::Iterator it = m_Parent->Begin(); it != m_Parent->End(); it++)
CheckObject(*it);
bool Contains(const TValue& object) const
{
- ObjectSet::Iterator it = m_Objects.find(object);
-
- return !(it == m_Objects.end());
+ return !(m_Objects.find(object) == m_Objects.end());
}
void CheckObject(const TValue& object)
return m_Objects.end();
}
- void ForeachObject(function<int (const ObjectSetEventArgs<TValue>&)> callback)
+ void ForeachObject(function<void (const ObjectSetEventArgs<TValue>&)> callback)
{
ObjectSetEventArgs<TValue> ea;
ea.Source = shared_from_this();
typename ObjectSet<TValue>::Ptr m_Parent;
function<bool (const TValue&)> m_Predicate;
- int ObjectAddedOrCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
+ void ObjectAddedOrCommittedHandler(const ObjectSetEventArgs<TValue>& ea)
{
CheckObject(ea.Target);
-
- return 0;
}
- int ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
+ void ObjectRemovedHandler(const ObjectSetEventArgs<TValue>& ea)
{
RemoveObject(ea.Target);
-
- return 0;
}
};
{
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()));
}
*/
void Socket::HandleSocketError(const std::exception& ex)
{
- // XXX, TODO: add SetErrorHandling() function
-/* if (OnError.HasObservers()) {*/
+ if (!OnError.empty()) {
SocketErrorEventArgs sea(ex);
OnError(sea);
Close();
-/* } else {
+ } else {
throw ex;
- }*/
+ }
}
/**
* Processes errors that have occured for the socket.
*
* @param - Event arguments for the socket error.
- * @returns 0
*/
-int Socket::ExceptionEventHandler(const EventArgs&)
+void Socket::ExceptionEventHandler(const EventArgs&)
{
HandleSocketError(SocketException(
"select() returned fd in except fdset", GetError()));
-
- return 0;
}
/**
private:
SOCKET m_FD; /**< The socket descriptor. */
- int ExceptionEventHandler(const EventArgs& ea);
+ void ExceptionEventHandler(const EventArgs& ea);
static string GetAddressFromSockaddr(sockaddr *address, socklen_t len);
};
{
m_Role = role;
- m_SendQueue = make_shared<FIFO>();
- m_RecvQueue = make_shared<FIFO>();
+ m_SendQueue = boost::make_shared<FIFO>();
+ m_RecvQueue = boost::make_shared<FIFO>();
}
/**
{
TcpSocket::Start();
- OnReadable.connect(bind(&TcpClient::ReadableEventHandler, this, _1));
- OnWritable.connect(bind(&TcpClient::WritableEventHandler, this, _1));
+ OnReadable.connect(boost::bind(&TcpClient::ReadableEventHandler, this, _1));
+ OnWritable.connect(boost::bind(&TcpClient::WritableEventHandler, this, _1));
}
/**
* Processes data that is available for this socket.
*
* @param - Event arguments.
- * @returns 0
*/
-int TcpClient::ReadableEventHandler(const EventArgs&)
+void TcpClient::ReadableEventHandler(const EventArgs&)
{
int rc;
#else /* _WIN32 */
if (rc < 0 && errno == EAGAIN)
#endif /* _WIN32 */
- return 0;
+ return;
if (rc <= 0) {
HandleSocketError(SocketException("recv() failed", GetError()));
- return 0;
+ return;
}
m_RecvQueue->Write(NULL, rc);
EventArgs dea;
dea.Source = shared_from_this();
OnDataAvailable(dea);
-
- return 0;
}
/**
* Processes data that can be written for this socket.
*
* @param - Event arguments.
- * @returns 0
*/
-int TcpClient::WritableEventHandler(const EventArgs&)
+void TcpClient::WritableEventHandler(const EventArgs&)
{
int rc;
if (rc <= 0) {
HandleSocketError(SocketException("send() failed", GetError()));
- return 0;
+ return;
}
m_SendQueue->Read(NULL, rc);
-
- return 0;
}
/**
*/
TcpClient::Ptr icinga::TcpClientFactory(TcpClientRole role)
{
- return make_shared<TcpClient>(role);
+ return boost::make_shared<TcpClient>(role);
}
FIFO::Ptr m_SendQueue;
FIFO::Ptr m_RecvQueue;
- virtual int ReadableEventHandler(const EventArgs& ea);
- virtual int WritableEventHandler(const EventArgs& ea);
+ virtual void ReadableEventHandler(const EventArgs& ea);
+ virtual void WritableEventHandler(const EventArgs& ea);
};
/**
*/
TcpServer::TcpServer(void)
{
- m_ClientFactory = bind(&TcpClientFactory, RoleInbound);
+ m_ClientFactory = boost::bind(&TcpClientFactory, RoleInbound);
}
/**
{
TcpSocket::Start();
- OnReadable.connect(bind(&TcpServer::ReadableEventHandler, this, _1));
+ OnReadable.connect(boost::bind(&TcpServer::ReadableEventHandler, this, _1));
}
/**
setsockopt(GetFD(), SOL_SOCKET, SO_REUSEADDR, (char *)&optTrue, sizeof(optTrue));
#endif /* _WIN32 */
- int rc = ::bind(fd, info->ai_addr, info->ai_addrlen);
+ int rc = bind(fd, info->ai_addr, info->ai_addrlen);
#ifdef _WIN32
if (rc < 0 && WSAGetLastError() != WSAEWOULDBLOCK) {
*/
void Timer::Call(void)
{
- TimerEventArgs tea;
+ EventArgs tea;
tea.Source = shared_from_this();
- tea.UserArgs = m_UserArgs;
OnTimerExpired(tea);
}
*
* @param interval The new interval.
*/
-void Timer::SetInterval(unsigned int interval)
+void Timer::SetInterval(time_t interval)
{
m_Interval = interval;
}
*
* @returns The interval.
*/
-unsigned int Timer::GetInterval(void) const
+time_t Timer::GetInterval(void) const
{
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.
*/
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.
*
Timer(void);
- void SetInterval(unsigned int interval);
- unsigned int GetInterval(void) const;
-
- void SetUserArgs(const EventArgs& userArgs);
- EventArgs GetUserArgs(void) const;
+ void SetInterval(time_t interval);
+ time_t GetInterval(void) const;
static time_t GetNextCall(void);
static void CallExpiredTimers(void);
void Reschedule(time_t next);
- boost::signal<void (const TimerEventArgs&)> OnTimerExpired;
+ boost::signal<void(const EventArgs&)> OnTimerExpired;
private:
- EventArgs m_UserArgs; /**< User-specified event arguments. */
- unsigned int m_Interval; /**< The interval of the timer. */
+ time_t m_Interval; /**< The interval of the timer. */
time_t m_Next; /**< When the next event should happen. */
static time_t NextCall; /**< When the next event should happen (for all timers). */
* Processes data that is available for this socket.
*
* @param - Event arguments.
- * @returns 0
*/
-int TlsClient::ReadableEventHandler(const EventArgs&)
+void TlsClient::ReadableEventHandler(const EventArgs&)
{
int rc;
m_BlockRead = true;
/* fall through */
case SSL_ERROR_WANT_READ:
- return 0;
+ return;
case SSL_ERROR_ZERO_RETURN:
Close();
-
- return 0;
+ return;
default:
HandleSocketError(OpenSSLException(
"SSL_read failed", ERR_get_error()));
-
- return 0;
+ return;
}
}
EventArgs dea;
dea.Source = shared_from_this();
OnDataAvailable(dea);
-
- return 0;
}
/**
* Processes data that can be written for this socket.
*
* @param - Event arguments.
- * @returns 0
*/
-int TlsClient::WritableEventHandler(const EventArgs&)
+void TlsClient::WritableEventHandler(const EventArgs&)
{
int rc;
m_BlockWrite = true;
/* fall through */
case SSL_ERROR_WANT_WRITE:
- return 0;
+ return;
case SSL_ERROR_ZERO_RETURN:
Close();
-
- return 0;
+ return;
default:
HandleSocketError(OpenSSLException(
"SSL_write failed", ERR_get_error()));
-
- return 0;
+ return;
}
}
GetSendQueue()->Read(NULL, rc);
-
- return 0;
}
/**
*/
TcpClient::Ptr icinga::TlsClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
{
- return make_shared<TlsClient>(role, sslContext);
+ return boost::make_shared<TlsClient>(role, sslContext);
}
/**
static int m_SSLIndex;
static bool m_SSLIndexInitialized;
- virtual int ReadableEventHandler(const EventArgs& ea);
- virtual int WritableEventHandler(const EventArgs& ea);
+ virtual void ReadableEventHandler(const EventArgs& ea);
+ virtual void WritableEventHandler(const EventArgs& ea);
virtual void CloseInternal(bool from_dtor);
void CheckerComponent::Start(void)
{
- m_CheckerEndpoint = make_shared<VirtualEndpoint>();
+ m_CheckerEndpoint = boost::make_shared<VirtualEndpoint>();
m_CheckerEndpoint->RegisterTopicHandler("checker::AssignService",
- bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
+ boost::bind(&CheckerComponent::AssignServiceRequestHandler, this, _1));
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");
GetEndpointManager()->RegisterEndpoint(m_CheckerEndpoint);
- m_CheckTimer = make_shared<Timer>();
+ m_CheckTimer = boost::make_shared<Timer>();
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();
CheckTask::RegisterType("nagios", NagiosCheckTask::CreateTask);
mgr->UnregisterEndpoint(m_CheckerEndpoint);
}
-int CheckerComponent::CheckTimerHandler(const TimerEventArgs& ea)
+void CheckerComponent::CheckTimerHandler(void)
{
time_t now;
time(&now);
if (m_Services.size() == 0)
- return 0;
+ return;
for (;;) {
Service service = m_Services.top();
break;
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();
m_Services.pop();
/* adjust next call time for the check timer */
Service service = m_Services.top();
- static_pointer_cast<Timer>(ea.Source)->SetInterval(service.GetNextCheck() - now);
-
- return 0;
+ m_CheckTimer->SetInterval(service.GetNextCheck() - now);
}
-int CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
+void CheckerComponent::AssignServiceRequestHandler(const NewRequestEventArgs& nrea)
{
- string id;
- if (!nrea.Request.GetID(&id))
- return 0;
-
MessagePart params;
if (!nrea.Request.GetParams(¶ms))
- return 0;
+ return;
MessagePart 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);
m_Services.push(service);
- Application::Log("Accepted service '" + service.GetName() + "'");
+ Application::Log(LogInformation, "checker", "Accepted delegation for service '" + service.GetName() + "'");
/* force a service check */
m_CheckTimer->Reschedule(0);
- ResponseMessage rm;
- rm.SetID(id);
+ 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::RevokeServiceRequestHandler(const NewRequestEventArgs& nrea)
+{
+ MessagePart params;
+ if (!nrea.Request.GetParams(¶ms))
+ return;
+
+ string name;
+ if (!params.GetProperty("service", &name))
+ return;
+
+ vector<Service> services;
- MessagePart result;
- rm.SetResult(result);
- GetEndpointManager()->SendUnicastMessage(m_CheckerEndpoint, nrea.Sender, rm);
+ while (!m_Services.empty()) {
+ Service service = m_Services.top();
+
+ if (service.GetName() == name)
+ continue;
+
+ services.push_back(service);
+ }
- return 0;
+ 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);
+ }
}
-int CheckerComponent::RevokeServiceRequestHandler(const NewRequestEventArgs& nrea)
+void CheckerComponent::ClearServicesRequestHandler(const NewRequestEventArgs& nrea)
{
- return 0;
+ 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);
class CheckerComponent : public IcingaComponent
{
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 void Start(void);
virtual void Stop(void);
private:
- priority_queue<Service, vector<Service>, ServiceNextCheckLessComparer> m_Services;
+ ServiceQueue m_Services;
Timer::Ptr m_CheckTimer;
VirtualEndpoint::Ptr m_CheckerEndpoint;
- int CheckTimerHandler(const TimerEventArgs& ea);
+ void CheckTimerHandler(void);
- int AssignServiceRequestHandler(const NewRequestEventArgs& nrea);
- int RevokeServiceRequestHandler(const NewRequestEventArgs& nrea);
+ void AssignServiceRequestHandler(const NewRequestEventArgs& nrea);
+ void RevokeServiceRequestHandler(const NewRequestEventArgs& nrea);
+ void ClearServicesRequestHandler(const NewRequestEventArgs& nrea);
};
}
#include <queue>
+using std::priority_queue;
+
#include "checkercomponent.h"
#endif /* I2CHECKER_H */
#include "i2-configfile.h"
+using std::ifstream;
+
using namespace icinga;
string ConfigFileComponent::GetName(void) const
void ConfigFileComponent::Start(void)
{
ifstream fp;
- FIFO::Ptr fifo = make_shared<FIFO>();
+ FIFO::Ptr fifo = boost::make_shared<FIFO>();
string filename;
if (!GetConfig()->GetProperty("configFilename", &filename))
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);
- Application::Log("Executing config items...");
+ Application::Log(LogInformation, "configfile", "Executing config items...");
ConfigVM::ExecuteItems(configItems);
}
{
EndpointManager::Ptr endpointManager = GetEndpointManager();
- m_ConfigRpcEndpoint = make_shared<VirtualEndpoint>();
+ m_ConfigRpcEndpoint = boost::make_shared<VirtualEndpoint>();
long configSource;
if (GetConfig()->GetProperty("configSource", &configSource) && configSource != 0) {
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()->OnObjectCommitted.connect(bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
- ConfigObject::GetAllObjects()->OnObjectRemoved.connect(bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _1));
+ ConfigObject::GetAllObjects()->OnObjectAdded.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
+ ConfigObject::GetAllObjects()->OnObjectCommitted.connect(boost::bind(&ConfigRpcComponent::LocalObjectCommittedHandler, this, _1));
+ ConfigObject::GetAllObjects()->OnObjectRemoved.connect(boost::bind(&ConfigRpcComponent::LocalObjectRemovedHandler, this, _1));
m_ConfigRpcEndpoint->RegisterPublication("config::ObjectCommitted");
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->RegisterTopicHandler("config::ObjectCommitted",
- bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _1));
+ boost::bind(&ConfigRpcComponent::RemoteObjectCommittedHandler, this, _1));
m_ConfigRpcEndpoint->RegisterTopicHandler("config::ObjectRemoved",
- bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _1));
+ boost::bind(&ConfigRpcComponent::RemoteObjectRemovedHandler, this, _1));
endpointManager->RegisterEndpoint(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));
-
- return 0;
+ ea.Endpoint->OnSessionEstablished.connect(boost::bind(&ConfigRpcComponent::SessionEstablishedHandler, this, _1));
}
-int ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
+void ConfigRpcComponent::SessionEstablishedHandler(const EventArgs& ea)
{
RequestMessage request;
request.SetMethod("config::FetchObjects");
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
GetEndpointManager()->SendUnicastMessage(m_ConfigRpcEndpoint, endpoint, request);
-
- return 0;
}
RequestMessage ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
return (!object->IsLocal());
}
-int ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
+void ConfigRpcComponent::FetchObjectsHandler(const NewRequestEventArgs& ea)
{
Endpoint::Ptr client = ea.Sender;
ConfigObject::Set::Ptr allObjects = ConfigObject::GetAllObjects();
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;
if (!ShouldReplicateObject(object))
- return 0;
+ return;
GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
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;
if (!ShouldReplicateObject(object))
- return 0;
+ return;
GetEndpointManager()->SendMulticastMessage(m_ConfigRpcEndpoint,
MakeObjectMessage(object, "config::ObjectRemoved", false));
-
- return 0;
}
-int ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
+void ConfigRpcComponent::RemoteObjectCommittedHandler(const NewRequestEventArgs& ea)
{
RequestMessage message = ea.Request;
MessagePart params;
if (!message.GetParams(¶ms))
- return 0;
+ return;
string name;
if (!params.GetProperty("name", &name))
- return 0;
+ return;
string type;
if (!params.GetProperty("type", &type))
- return 0;
+ return;
MessagePart properties;
if (!params.GetProperty("properties", &properties))
- return 0;
+ return;
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
if (!object)
- object = make_shared<ConfigObject>(properties.GetDictionary());
+ object = boost::make_shared<ConfigObject>(properties.GetDictionary());
else
object->SetProperties(properties.GetDictionary());
object->Commit();
-
- return 0;
}
-int ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
+void ConfigRpcComponent::RemoteObjectRemovedHandler(const NewRequestEventArgs& ea)
{
RequestMessage message = ea.Request;
MessagePart params;
if (!message.GetParams(¶ms))
- return 0;
+ return;
string name;
if (!params.GetProperty("name", &name))
- return 0;
+ return;
string type;
if (!params.GetProperty("type", &type))
- return 0;
+ return;
ConfigObject::Ptr object = ConfigObject::GetObject(type, name);
if (!object)
- return 0;
+ return;
if (!object->IsLocal())
object->Unregister();
-
- return 0;
}
EXPORT_COMPONENT(configrpc, ConfigRpcComponent);
private:
VirtualEndpoint::Ptr m_ConfigRpcEndpoint;
- int NewEndpointHandler(const NewEndpointEventArgs& ea);
- int SessionEstablishedHandler(const EventArgs& ea);
+ void NewEndpointHandler(const NewEndpointEventArgs& ea);
+ void SessionEstablishedHandler(const EventArgs& ea);
- int LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
- int LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+ void LocalObjectCommittedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+ void LocalObjectRemovedHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
- int FetchObjectsHandler(const NewRequestEventArgs& ea);
- int RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
- int RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
+ void FetchObjectsHandler(const NewRequestEventArgs& ea);
+ void RemoteObjectCommittedHandler(const NewRequestEventArgs& ea);
+ void RemoteObjectRemovedHandler(const NewRequestEventArgs& ea);
static RequestMessage MakeObjectMessage(const ConfigObject::Ptr& object,
string method, bool includeProperties);
void DelegationComponent::Start(void)
{
- m_AllServices = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
- m_AllServices->OnObjectAdded.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
- m_AllServices->OnObjectCommitted.connect(bind(&DelegationComponent::NewServiceHandler, this, _1));
- m_AllServices->OnObjectRemoved.connect(bind(&DelegationComponent::RemovedServiceHandler, this, _1));
+ m_AllServices = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("service"));
+ m_AllServices->OnObjectAdded.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
+ m_AllServices->OnObjectCommitted.connect(boost::bind(&DelegationComponent::NewServiceHandler, this, _1));
+ m_AllServices->OnObjectRemoved.connect(boost::bind(&DelegationComponent::RemovedServiceHandler, this, _1));
m_AllServices->Start();
- m_DelegationTimer = make_shared<Timer>();
+ m_DelegationTimer = boost::make_shared<Timer>();
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_DelegationEndpoint = make_shared<VirtualEndpoint>();
+ m_DelegationEndpoint = boost::make_shared<VirtualEndpoint>();
m_DelegationEndpoint->RegisterPublication("checker::AssignService");
m_DelegationEndpoint->RegisterPublication("checker::RevokeService");
GetEndpointManager()->RegisterEndpoint(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);
- return 0;
}
-int DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
+void DelegationComponent::RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
{
RevokeService(ea.Target);
- return 0;
}
void DelegationComponent::AssignService(const ConfigObject::Ptr& service)
params.SetProperty("service", service->GetProperties());
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,
- 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) {
- Application::Log("Service delegation for service '" + service->GetName() + "' timed out.");
+ Application::Log(LogInformation, "delegation", "Service delegation for service '" + service->GetName() + "' timed out.");
} else {
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)
}
-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;
for (it = m_AllServices->Begin(); it != m_AllServices->End(); it++) {
AssignService(object);
}
-
- return 0;
-}
-
-int DelegationComponent::TestResponseHandler(const NewResponseEventArgs& ea)
-{
- Application::Log("Response handler called.");
-
- return 0;
}
EXPORT_COMPONENT(delegation, DelegationComponent);
ConfigObject::Set::Ptr m_AllServices;
Timer::Ptr m_DelegationTimer;
- int NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
- int RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+ void NewServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+ void RemovedServiceHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
- int AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
- int RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
+ void AssignServiceResponseHandler(const ConfigObject::Ptr& service, const NewResponseEventArgs& nrea);
+ void RevokeServiceResponseHandler(const NewResponseEventArgs& nrea);
- int DelegationTimerHandler(const TimerEventArgs& ea);
+ void DelegationTimerHandler(void);
void AssignService(const ConfigObject::Ptr& service);
void RevokeService(const ConfigObject::Ptr& service);
-
- int TestResponseHandler(const NewResponseEventArgs& ea);
};
}
*/
void DemoComponent::Start(void)
{
- m_DemoEndpoint = make_shared<VirtualEndpoint>();
+ m_DemoEndpoint = boost::make_shared<VirtualEndpoint>();
m_DemoEndpoint->RegisterTopicHandler("demo::HelloWorld",
- bind(&DemoComponent::HelloWorldRequestHandler, this, _1));
+ boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _1));
m_DemoEndpoint->RegisterPublication("demo::HelloWorld");
GetEndpointManager()->RegisterEndpoint(m_DemoEndpoint);
- m_DemoTimer = make_shared<Timer>();
+ m_DemoTimer = boost::make_shared<Timer>();
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();
}
* Periodically sends a demo::HelloWorld message.
*
* @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;
request.SetMethod("demo::HelloWorld");
EndpointManager::Ptr endpointManager = GetIcingaApplication()->GetEndpointManager();
endpointManager->SendMulticastMessage(m_DemoEndpoint, request);
-
- return 0;
}
/**
* 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());
-
- return 0;
+ Application::Log(LogInformation, "demo", "Got 'hello world' from address=" + nrea.Sender->GetAddress() + ", identity=" + nrea.Sender->GetIdentity());
}
EXPORT_COMPONENT(demo, DemoComponent);
Timer::Ptr m_DemoTimer;
VirtualEndpoint::Ptr m_DemoEndpoint;
- int DemoTimerHandler(const TimerEventArgs& tea);
- int HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
+ void DemoTimerHandler(void);
+ void HelloWorldRequestHandler(const NewRequestEventArgs& nrea);
};
}
*/
void DiscoveryComponent::Start(void)
{
- m_DiscoveryEndpoint = make_shared<VirtualEndpoint>();
+ m_DiscoveryEndpoint = boost::make_shared<VirtualEndpoint>();
m_DiscoveryEndpoint->RegisterPublication("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->RegisterTopicHandler("discovery::NewComponent",
- bind(&DiscoveryComponent::NewComponentMessageHandler, this, _1));
+ boost::bind(&DiscoveryComponent::NewComponentMessageHandler, this, _1));
m_DiscoveryEndpoint->RegisterTopicHandler("discovery::Welcome",
- bind(&DiscoveryComponent::WelcomeMessageHandler, this, _1));
+ boost::bind(&DiscoveryComponent::WelcomeMessageHandler, this, _1));
- GetEndpointManager()->ForEachEndpoint(bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
- GetEndpointManager()->OnNewEndpoint.connect(bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
+ GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
+ GetEndpointManager()->OnNewEndpoint.connect(boost::bind(&DiscoveryComponent::NewEndpointHandler, this, _1));
GetEndpointManager()->RegisterEndpoint(m_DiscoveryEndpoint);
/* create the reconnect timer */
- m_DiscoveryTimer = make_shared<Timer>();
+ m_DiscoveryTimer = boost::make_shared<Timer>();
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();
/* call the timer as soon as possible */
*
* @param endpoint The endpoint that is to be checked.
* @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)
- return 0;
+ return;
if (!neea.Endpoint->IsConnected())
- return 0;
+ return;
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();
GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
}
-
- return 0;
}
/**
* @param neea Event arguments for the new endpoint.
* @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 */
neea.Endpoint->RegisterPublication("discovery::RegisterComponent");
/* accept discovery::Welcome messages from any endpoint */
neea.Endpoint->RegisterPublication("discovery::Welcome");
-
- return 0;
}
/**
* @param info Component information object.
* @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;
for (i = neea.Endpoint->BeginPublications(); i != neea.Endpoint->EndPublications(); i++) {
info->Publications.insert(*i);
}
-
- return 0;
}
/**
{
if (component == GetEndpointManager()->GetIdentity()) {
/* Build fake discovery info for ourselves */
- *info = make_shared<ComponentDiscoveryInfo>();
- GetEndpointManager()->ForEachEndpoint(bind(&DiscoveryComponent::DiscoveryEndpointHandler, this, _1, *info));
+ *info = boost::make_shared<ComponentDiscoveryInfo>();
+ GetEndpointManager()->ForEachEndpoint(boost::bind(&DiscoveryComponent::DiscoveryEndpointHandler, this, _1, *info));
(*info)->LastSeen = 0;
(*info)->Node = GetIcingaApplication()->GetNode();
* @param ea Event arguments for the component.
* @returns 0
*/
-int DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
+void DiscoveryComponent::NewIdentityHandler(const EventArgs& ea)
{
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(ea.Source);
string identity = endpoint->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();
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
// discovery::RegisterComponent messages from us
// we don't know the other component yet, so
// wait until we get a discovery::NewComponent message
// from a broker
- return 0;
+ return;
}
// register published/subscribed topics for this endpoint
endpoint->RegisterSubscription(*it);
FinishDiscoverySetup(endpoint);
-
- return 0;
}
/**
* @param nrea Event arguments for the request.
* @returns 0
*/
-int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
+void DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& nrea)
{
Endpoint::Ptr endpoint = nrea.Sender;
if (endpoint->HasReceivedWelcome())
- return 0;
+ return;
endpoint->SetReceivedWelcome(true);
ea.Source = endpoint;
endpoint->OnSessionEstablished(ea);
}
-
- return 0;
}
/**
if (identity == GetEndpointManager()->GetIdentity())
return;
- ComponentDiscoveryInfo::Ptr info = make_shared<ComponentDiscoveryInfo>();
+ ComponentDiscoveryInfo::Ptr info = boost::make_shared<ComponentDiscoveryInfo>();
time(&(info->LastSeen));
* Processes "discovery::NewComponent" messages.
*
* @param nrea Event arguments for the request.
- * @returns 0
*/
-int DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& nrea)
+void DiscoveryComponent::NewComponentMessageHandler(const NewRequestEventArgs& nrea)
{
DiscoveryMessage message;
nrea.Request.GetParams(&message);
string identity;
if (!message.GetIdentity(&identity))
- return 0;
+ return;
ProcessDiscoveryMessage(identity, message, true);
- return 0;
}
/**
* Processes "discovery::RegisterComponent" messages.
*
* @param nrea Event arguments for the request.
- * @returns 0
*/
-int DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArgs& nrea)
+void DiscoveryComponent::RegisterComponentMessageHandler(const NewRequestEventArgs& nrea)
{
DiscoveryMessage message;
nrea.Request.GetParams(&message);
ProcessDiscoveryMessage(nrea.Sender->GetIdentity(), message, false);
-
- return 0;
}
/**
* Checks whether we have to reconnect to other components and removes stale
* 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->AddConnection(info->Node, info->Service);
}
}
-
- return 0;
}
EXPORT_COMPONENT(discovery, DiscoveryComponent);
map<string, ComponentDiscoveryInfo::Ptr> m_Components;
Timer::Ptr m_DiscoveryTimer;
- int NewEndpointHandler(const NewEndpointEventArgs& neea);
- int NewIdentityHandler(const EventArgs& ea);
+ void NewEndpointHandler(const NewEndpointEventArgs& neea);
+ void NewIdentityHandler(const EventArgs& ea);
- int NewComponentMessageHandler(const NewRequestEventArgs& nrea);
- int RegisterComponentMessageHandler(const NewRequestEventArgs& nrea);
+ void NewComponentMessageHandler(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 ProcessDiscoveryMessage(string identity, DiscoveryMessage message, bool trusted);
bool GetComponentDiscoveryInfo(string component, ComponentDiscoveryInfo::Ptr *info) const;
- int CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
- int DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
+ void CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewEndpointEventArgs& neea);
+ void DiscoveryEndpointHandler(const NewEndpointEventArgs& neea, ComponentDiscoveryInfo::Ptr info) const;
- int DiscoveryTimerHandler(const TimerEventArgs& tea);
+ void DiscoveryTimerHandler(void);
void FinishDiscoverySetup(Endpoint::Ptr endpoint);
+++ /dev/null
-# ============================================================================
-# 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
-])
AM_PROG_LEX
AC_PROG_YACC
AC_PROG_LIBTOOL
-AX_CXX_COMPILE_STDCXX_0X
AX_CXX_GCC_ABI_DEMANGLE
AX_PTHREAD
AX_BOOST_BASE
/* Line 1806 of yacc.c */
#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[(5) - (5)].text));
}
/* Line 1806 of yacc.c */
#line 180 "config_parser.yy"
{
- m_ExpressionLists.push(make_shared<ExpressionList>());
+ m_ExpressionLists.push(boost::make_shared<ExpressionList>());
}
break;
free((yyvsp[(3) - (6)].text));
delete (yyvsp[(6) - (6)].variant);
- ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
+ ExpressionList::Ptr subexprl = boost::make_shared<ExpressionList>();
subexprl->AddExpression(subexpr);
Expression expr((yyvsp[(1) - (6)].text), OperatorPlus, subexprl, yylloc);
/* Line 1806 of yacc.c */
#line 261 "config_parser.yy"
{
- m_Array = make_shared<Dictionary>();
+ m_Array = boost::make_shared<Dictionary>();
}
break;
}
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($5);
}
expressionlist: '{'
{
- m_ExpressionLists.push(make_shared<ExpressionList>());
+ m_ExpressionLists.push(boost::make_shared<ExpressionList>());
}
expressions
'}'
free($3);
delete $6;
- ExpressionList::Ptr subexprl = make_shared<ExpressionList>();
+ ExpressionList::Ptr subexprl = boost::make_shared<ExpressionList>();
subexprl->AddExpression(subexpr);
Expression expr($1, OperatorPlus, subexprl, yylloc);
tuple: '('
{
- m_Array = make_shared<Dictionary>();
+ m_Array = boost::make_shared<Dictionary>();
}
tupleitems
')'
#include "i2-dyn.h"
+using std::ifstream;
+
using namespace icinga;
ConfigCompiler::ConfigCompiler(istream *input)
size_t ConfigCompiler::ReadInput(char *buffer, size_t 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
static ObjectSet<ConfigItem::Ptr>::Ptr allObjects;
if (!allObjects) {
- allObjects = make_shared<ObjectSet<ConfigItem::Ptr> >();
+ allObjects = boost::make_shared<ObjectSet<ConfigItem::Ptr> >();
allObjects->Start();
}
static ConfigItem::TNMap::Ptr tnmap;
if (!tnmap) {
- tnmap = make_shared<ConfigItem::TNMap>(GetAllObjects(), &ConfigItem::GetTypeAndName);
+ tnmap = boost::make_shared<ConfigItem::TNMap>(GetAllObjects(), &ConfigItem::GetTypeAndName);
tnmap->Start();
}
{
ConfigObject::Ptr dobj = m_ConfigObject.lock();
- Dictionary::Ptr properties = make_shared<Dictionary>();
+ Dictionary::Ptr properties = boost::make_shared<Dictionary>();
CalculateProperties(properties);
if (!dobj)
dobj = ConfigObject::GetObject(GetType(), GetName());
if (!dobj)
- dobj = make_shared<ConfigObject>(properties);
+ dobj = boost::make_shared<ConfigObject>(properties);
else
dobj->SetProperties(properties);
switch (m_Operator) {
case OperatorSet:
if (exprl) {
- Dictionary::Ptr dict = make_shared<Dictionary>();
+ Dictionary::Ptr dict = boost::make_shared<Dictionary>();
exprl->Execute(dict);
newValue = dict;
}
throw domain_error(message.str());
}
- dict = make_shared<Dictionary>();
+ dict = boost::make_shared<Dictionary>();
}
exprl->Execute(dict);
#include <stack>
#include <fstream>
+using std::stack;
+using std::istream;
+using std::ostream;
+using std::cin;
+using std::endl;
+
#ifdef I2_DYN_BUILD
# define I2_DYN_API I2_EXPORT
#else /* I2_DYN_BUILD */
#include <i2-dyn.h>
//#include <i2-jsonrpc.h>
+using std::cout;
+using std::endl;
+
using namespace icinga;
int main(int argc, char **argv)
LTDL_SET_PRELOADED_SYMBOLS();
#endif /* _WIN32 */
- IcingaApplication::Ptr instance = make_shared<IcingaApplication>();
+ IcingaApplication::Ptr instance = boost::make_shared<IcingaApplication>();
return instance->Run(argc, argv);
}
stringstream s;
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);
server->Bind(service, AF_INET6);
{
stringstream s;
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);
endpoint->Connect(node, service, m_SSLContext);
}
void EndpointManager::RegisterServer(JsonRpcServer::Ptr server)
{
m_Servers.push_back(server);
- server->OnNewClient.connect(bind(&EndpointManager::NewClientHandler,
+ server->OnNewClient.connect(boost::bind(&EndpointManager::NewClientHandler,
this, _1));
}
*
* @param ncea Event arguments.
*/
-int EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
+void EndpointManager::NewClientHandler(const NewClientEventArgs& ncea)
{
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));
RegisterEndpoint(endpoint);
-
- return 0;
}
/**
*
* @param callback The callback function.
*/
-void EndpointManager::ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback)
+void EndpointManager::ForEachEndpoint(function<void (const NewEndpointEventArgs&)> callback)
{
NewEndpointEventArgs neea;
neea.Source = shared_from_this();
void EndpointManager::SendAPIMessage(Endpoint::Ptr sender,
RequestMessage& message,
- function<int(const NewResponseEventArgs&)> callback, time_t timeout)
+ function<void(const NewResponseEventArgs&)> callback, time_t timeout)
{
m_NextMessageID++;
&EndpointManager::RequestTimeoutLessComparer);
if (!m_RequestTimer) {
- m_RequestTimer = make_shared<Timer>();
- m_RequestTimer->OnTimerExpired.connect(bind(&EndpointManager::RequestTimerHandler, this, _1));
+ m_RequestTimer = boost::make_shared<Timer>();
+ m_RequestTimer->OnTimerExpired.connect(boost::bind(&EndpointManager::RequestTimerHandler, this));
}
if (it != m_Requests.end()) {
}
}
-int EndpointManager::RequestTimerHandler(const TimerEventArgs& ea)
+void EndpointManager::RequestTimerHandler(void)
{
map<string, PendingRequest>::iterator it;
for (it = m_Requests.begin(); it != m_Requests.end(); it++) {
}
RescheduleRequestTimer();
-
- return 0;
}
void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message)
{
time_t Timeout;
RequestMessage Request;
- function<int(const NewResponseEventArgs&)> Callback;
+ function<void(const NewResponseEventArgs&)> Callback;
bool HasTimedOut(void) const
{
void SendMulticastMessage(Endpoint::Ptr sender, const 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 ForEachEndpoint(function<int (const NewEndpointEventArgs&)> callback);
+ void ForEachEndpoint(function<void (const NewEndpointEventArgs&)> callback);
Endpoint::Ptr GetEndpointByIdentity(string identity) const;
static bool RequestTimeoutLessComparer(const pair<string, PendingRequest>& a, const pair<string, PendingRequest>& b);
void RescheduleRequestTimer(void);
- int RequestTimerHandler(const TimerEventArgs& ea);
+ void RequestTimerHandler(void);
- int NewClientHandler(const NewClientEventArgs& ncea);
+ void NewClientHandler(const NewClientEventArgs& ncea);
};
}
int IcingaApplication::Main(const vector<string>& args)
{
#ifdef _WIN32
- Application::Log("Icinga component loader");
+ Application::Log(LogInformation, "icinga", "Icinga component loader");
#else /* _WIN32 */
- Application::Log("Icinga component loader (version: " ICINGA_VERSION ")");
+ Application::Log(LogInformation, "icinga", "Icinga component loader (version: " ICINGA_VERSION ")");
#endif /* _WIN32 */
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;
}
- m_EndpointManager = make_shared<EndpointManager>();
+ m_EndpointManager = boost::make_shared<EndpointManager>();
string componentDirectory = GetExeDirectory() + "/../lib/icinga2";
AddComponentSearchDir(componentDirectory);
/* register handler for 'component' config objects */
- static ConfigObject::Set::Ptr componentObjects = make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
- function<int (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = bind(&IcingaApplication::NewComponentHandler, this, _1);
+ static ConfigObject::Set::Ptr componentObjects = boost::make_shared<ConfigObject::Set>(ConfigObject::GetAllObjects(), ConfigObject::MakeTypePredicate("component"));
+ function<void (const ObjectSetEventArgs<ConfigObject::Ptr>&)> NewComponentHandler = boost::bind(&IcingaApplication::NewComponentHandler, this, _1);
componentObjects->OnObjectAdded.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();
/* load config file */
- ConfigObject::Ptr fileComponentConfig = make_shared<ConfigObject>("component", "configfile");
+ ConfigObject::Ptr fileComponentConfig = boost::make_shared<ConfigObject>("component", "configfile");
fileComponentConfig->SetLocal(true);
fileComponentConfig->SetProperty("configFilename", args[1]);
fileComponentConfig->Commit();
/* set up SSL context */
shared_ptr<X509> cert = Utility::GetX509Certificate(GetPublicKeyFile());
string identity = Utility::GetCertificateCN(cert);
- Application::Log("My identity: " + identity);
+ Application::Log(LogInformation, "icinga", "My identity: " + identity);
m_EndpointManager->SetIdentity(identity);
shared_ptr<SSL_CTX> sslContext = Utility::MakeSSLContext(GetPublicKeyFile(), GetPrivateKeyFile(), GetCAKeyFile());
return m_EndpointManager;
}
-int IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
+void IcingaApplication::NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea)
{
ConfigObject::Ptr object = ea.Target;
}
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;
Component::Ptr component = GetComponent(object->GetName());
UnregisterComponent(component);
-
- return 0;
}
string IcingaApplication::GetPrivateKeyFile(void) const
string m_Node;
string m_Service;
- int NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
- int 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);
+ void NewComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
+ void DeletedComponentHandler(const ObjectSetEventArgs<ConfigObject::Ptr>& ea);
};
}
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);
client->Connect(node, service);
client->Start();
void JsonRpcEndpoint::SetClient(JsonRpcClient::Ptr client)
{
m_Client = client;
- client->OnNewMessage.connect(bind(&JsonRpcEndpoint::NewMessageHandler, this, _1));
- client->OnClosed.connect(bind(&JsonRpcEndpoint::ClientClosedHandler, this, _1));
- client->OnError.connect(bind(&JsonRpcEndpoint::ClientErrorHandler, this, _1));
- client->OnVerifyCertificate.connect(bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _1));
+ client->OnNewMessage.connect(boost::bind(&JsonRpcEndpoint::NewMessageHandler, this, _1));
+ client->OnClosed.connect(boost::bind(&JsonRpcEndpoint::ClientClosedHandler, this, _1));
+ client->OnError.connect(boost::bind(&JsonRpcEndpoint::ClientErrorHandler, this, _1));
+ client->OnVerifyCertificate.connect(boost::bind(&JsonRpcEndpoint::VerifyCertificateHandler, this, _1));
}
bool JsonRpcEndpoint::IsLocal(void) const
m_Client->SendMessage(message);
}
-int JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
+void JsonRpcEndpoint::NewMessageHandler(const NewMessageEventArgs& nmea)
{
const MessagePart& message = nmea.Message;
Endpoint::Ptr sender = static_pointer_cast<Endpoint>(shared_from_this());
/* rather than routing the message to the right virtual
* endpoint we just process it here right away. */
GetEndpointManager()->ProcessResponseMessage(sender, message);
- return 0;
+ return;
}
string method;
if (!message.GetProperty("method", &method))
- return 0;
+ return;
if (!HasPublication(method))
- return 0;
+ return;
RequestMessage request = message;
GetEndpointManager()->SendAnycastMessage(sender, request);
else
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_Client.reset();
// 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) {
string identity = Utility::GetCertificateCN(ea.Certificate);
if (GetIdentity().empty() && !identity.empty())
SetIdentity(identity);
}
-
- return 0;
}
void JsonRpcEndpoint::Stop(void)
JsonRpcClient::Ptr m_Client;
map<string, Endpoint::Ptr> m_PendingCalls;
- int NewMessageHandler(const NewMessageEventArgs& nmea);
- int ClientClosedHandler(const EventArgs& ea);
- int ClientErrorHandler(const SocketErrorEventArgs& ea);
- int VerifyCertificateHandler(const VerifyCertificateEventArgs& ea);
+ void NewMessageHandler(const NewMessageEventArgs& nmea);
+ void ClientClosedHandler(const EventArgs& ea);
+ void ClientErrorHandler(const SocketErrorEventArgs& ea);
+ void VerifyCertificateHandler(const VerifyCertificateEventArgs& ea);
};
}
string command = m_Command + " 2>&1";
- Application::Log("Nagios check command: " + command);
+ Application::Log(LogDebug, "icinga", "Nagios check command: " + command);
#ifdef _MSC_VER
fp = _popen(command.c_str(), "r");
cr.Output = output.str();
- Application::Log("Nagios plugin output: " + cr.Output);
+ Application::Log(LogDebug, "icinga", "Nagios plugin output: " + cr.Output);
int status, exitcode;
#ifdef _MSC_VER
{
assert(service.GetCheckType() == "nagios");
- return make_shared<NagiosCheckTask>(service);
+ return boost::make_shared<NagiosCheckTask>(service);
}
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;
it = m_TopicHandlers.find(topic);
shared_ptr<boost::signal<void (const NewRequestEventArgs&)> > sig;
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));
} else {
sig = it->second;
RegisterSubscription(topic);
}
-void VirtualEndpoint::UnregisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback)
+void VirtualEndpoint::UnregisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback)
{
// TODO: implement
//m_TopicHandlers[method] -= callback;
typedef shared_ptr<VirtualEndpoint> Ptr;
typedef weak_ptr<VirtualEndpoint> WeakPtr;
- void RegisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback);
- void UnregisterTopicHandler(string topic, function<int (const NewRequestEventArgs&)> callback);
+ void RegisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback);
+ void UnregisterTopicHandler(string topic, function<void (const NewRequestEventArgs&)> callback);
virtual string GetAddress(void) const;
{
TlsClient::Start();
- OnDataAvailable.connect(bind(&JsonRpcClient::DataAvailableHandler, this, _1));
+ OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this, _1));
}
/**
* @param - Event arguments for the event.
* @returns 0
*/
-int JsonRpcClient::DataAvailableHandler(const EventArgs&)
+void JsonRpcClient::DataAvailableHandler(const EventArgs&)
{
for (;;) {
try {
MessagePart message;
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
- break;
+ return;
message = MessagePart(jsonString);
nea.Message = message;
OnNewMessage(nea);
} 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();
- return 0;
+ return;
}
}
-
- return 0;
}
/**
*/
JsonRpcClient::Ptr icinga::JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
{
- return make_shared<JsonRpcClient>(role, sslContext);
+ return boost::make_shared<JsonRpcClient>(role, sslContext);
}
boost::signal<void (const NewMessageEventArgs&)> OnNewMessage;
private:
- int DataAvailableHandler(const EventArgs&);
+ void DataAvailableHandler(const EventArgs&);
};
JsonRpcClient::Ptr JsonRpcClientFactory(TcpClientRole role, shared_ptr<SSL_CTX> sslContext);
*/
JsonRpcServer::JsonRpcServer(shared_ptr<SSL_CTX> sslContext)
{
- SetClientFactory(bind(&JsonRpcClientFactory, RoleInbound, sslContext));
+ SetClientFactory(boost::bind(&JsonRpcClientFactory, RoleInbound, sslContext));
}
*/
MessagePart::MessagePart(void)
{
- m_Dictionary = make_shared<Dictionary>();
+ m_Dictionary = boost::make_shared<Dictionary>();
}
/**
*/
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) {
switch (i->type) {