mirror of https://github.com/Icinga/icinga2.git
Merge branch 'master' into compatido
This commit is contained in:
commit
454adc5a90
|
@ -37,3 +37,4 @@ stamp-h1
|
||||||
.libs
|
.libs
|
||||||
icinga-app/icinga
|
icinga-app/icinga
|
||||||
docs/dev
|
docs/dev
|
||||||
|
m4/ylwrap
|
||||||
|
|
24
INSTALL
24
INSTALL
|
@ -12,15 +12,16 @@ Build Requirements
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The following requirements need to be fulfilled in order to build the
|
The following requirements need to be fulfilled in order to build the
|
||||||
application using a dist tarball (package names in parenthesis):
|
application using a dist tarball (package names for RHEL and Debian in
|
||||||
|
parenthesis):
|
||||||
|
|
||||||
* GNU make (make on RHEL and Debian)
|
* GNU make (make)
|
||||||
* C++ compiler (gcc-c++ on RHEL, build-essential on Debian)
|
* C++ compiler (gcc-c++ on RHEL, build-essential on Debian)
|
||||||
* OpenSSL library and header files (openssl-devel on RHEL, libssl-dev
|
* OpenSSL library and header files (openssl-devel on RHEL, libssl-dev
|
||||||
on Debian)
|
on Debian)
|
||||||
* Boost library and header files (boost-devel on RHEL, libboost-all-dev
|
* Boost library and header files (boost-devel on RHEL, libboost-all-dev
|
||||||
on Debian)
|
on Debian)
|
||||||
* optional: Doxygen (doxygen on RHEL and Debian)
|
* optional: Doxygen (doxygen)
|
||||||
|
|
||||||
Packaging Requirements
|
Packaging Requirements
|
||||||
----------------------
|
----------------------
|
||||||
|
@ -29,12 +30,12 @@ In order to build a dist tarball for the application the following external
|
||||||
software components need to be installed in addition to the build requirements
|
software components need to be installed in addition to the build requirements
|
||||||
mentioned above:
|
mentioned above:
|
||||||
|
|
||||||
* GNU Automake (automake on RHEL and Debian)
|
* GNU Automake (automake)
|
||||||
* GNU Autoconf (autoconf on RHEL and Debian)
|
* GNU Autoconf (autoconf)
|
||||||
* GNU Libtool (libtool and libtool-ltdl-devel on RHEL, libtool and
|
* GNU Libtool (libtool and libtool-ltdl-devel on RHEL, libtool and
|
||||||
libltdl-dev on Debian)
|
libltdl-dev on Debian)
|
||||||
* GNU bison (bison on RHEL and Debian)
|
* GNU bison (bison)
|
||||||
* GNU flex (flex on RHEL and Debian)
|
* GNU flex (flex)
|
||||||
|
|
||||||
Debian Packages
|
Debian Packages
|
||||||
---------------
|
---------------
|
||||||
|
@ -58,6 +59,12 @@ The configure script supports all the usual parameters one comes to expect
|
||||||
from autoconf. In particular you may want to use --prefix to specify an
|
from autoconf. In particular you may want to use --prefix to specify an
|
||||||
alternative installation prefix.
|
alternative installation prefix.
|
||||||
|
|
||||||
|
Note: The Git repository does not contain any auto-generated Autotools files,
|
||||||
|
i.e. there is no 'configure' script. In this case you will need to regenerate
|
||||||
|
the 'configure' script by running 'autogen.sh'. However, as an end-user you
|
||||||
|
should reconsider whether you really want to use the code from the Git
|
||||||
|
repository. In general it is advisable to use one of the dist tarballs instead.
|
||||||
|
|
||||||
Running Icinga 2
|
Running Icinga 2
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
@ -73,3 +80,6 @@ Icinga 2 reads a single configuration file which is used to specify all
|
||||||
configuration settings (global settings, hosts, services, etc.). The
|
configuration settings (global settings, hosts, services, etc.). The
|
||||||
configuration format is explained in detail in the docs/icinga2-config.txt
|
configuration format is explained in detail in the docs/icinga2-config.txt
|
||||||
file.
|
file.
|
||||||
|
|
||||||
|
By default "make install" installs example configuration files to /etc/icinga2
|
||||||
|
unless you have specified a different prefix or sysconfdir.
|
||||||
|
|
2
README
2
README
|
@ -7,5 +7,7 @@ information about how to install it.
|
||||||
The documentation file docs/icinga2-intro.txt contains an in-depth overview
|
The documentation file docs/icinga2-intro.txt contains an in-depth overview
|
||||||
of currently implemented and planned features for Icinga 2.
|
of currently implemented and planned features for Icinga 2.
|
||||||
|
|
||||||
|
Read the INSTALL file for information on how to install Icinga 2.
|
||||||
|
|
||||||
Check the project website at http://www.icinga.org/ for status updates and
|
Check the project website at http://www.icinga.org/ for status updates and
|
||||||
https://www.icinga.org/support/ if you want to contact us.
|
https://www.icinga.org/support/ if you want to contact us.
|
||||||
|
|
|
@ -30,7 +30,7 @@ void CheckerComponent::Start(void)
|
||||||
m_Endpoint->RegisterSubscription("checker");
|
m_Endpoint->RegisterSubscription("checker");
|
||||||
|
|
||||||
Service::OnCheckerChanged.connect(bind(&CheckerComponent::CheckerChangedHandler, this, _1));
|
Service::OnCheckerChanged.connect(bind(&CheckerComponent::CheckerChangedHandler, this, _1));
|
||||||
DynamicObject::OnUnregistered.connect(bind(&CheckerComponent::ServiceRemovedHandler, this, _1));
|
DynamicObject::OnUnregistered.connect(bind(&CheckerComponent::ObjectRemovedHandler, this, _1));
|
||||||
|
|
||||||
m_CheckTimer = boost::make_shared<Timer>();
|
m_CheckTimer = boost::make_shared<Timer>();
|
||||||
m_CheckTimer->SetInterval(1);
|
m_CheckTimer->SetInterval(1);
|
||||||
|
@ -184,7 +184,7 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
|
void CheckerComponent::ObjectRemovedHandler(const DynamicObject::Ptr& object)
|
||||||
{
|
{
|
||||||
Service::Ptr service = dynamic_pointer_cast<Service>(object);
|
Service::Ptr service = dynamic_pointer_cast<Service>(object);
|
||||||
|
|
||||||
|
@ -197,3 +197,4 @@ void CheckerComponent::ServiceRemovedHandler(const DynamicObject::Ptr& object)
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(checker, CheckerComponent);
|
EXPORT_COMPONENT(checker, CheckerComponent);
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup checker
|
||||||
|
*/
|
||||||
struct ServiceNextCheckExtractor
|
struct ServiceNextCheckExtractor
|
||||||
{
|
{
|
||||||
typedef double result_type;
|
typedef double result_type;
|
||||||
|
@ -71,10 +74,7 @@ private:
|
||||||
void AdjustCheckTimer(void);
|
void AdjustCheckTimer(void);
|
||||||
|
|
||||||
void CheckerChangedHandler(const Service::Ptr& service);
|
void CheckerChangedHandler(const Service::Ptr& service);
|
||||||
void ServiceRemovedHandler(const DynamicObject::Ptr& object);
|
void ObjectRemovedHandler(const DynamicObject::Ptr& object);
|
||||||
|
|
||||||
//void AssignServiceRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
|
||||||
//void ClearServicesRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ void CompatComponent::StatusTimerHandler(void)
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
statusfp << "programstatus {" << "\n"
|
statusfp << "programstatus {" << "\n"
|
||||||
|
<< "icinga_pid=" << Utility::GetPid() << "\n"
|
||||||
<< "\t" << "daemon_mode=1" << "\n"
|
<< "\t" << "daemon_mode=1" << "\n"
|
||||||
<< "\t" << "program_start=" << IcingaApplication::GetInstance()->GetStartTime() << "\n"
|
<< "\t" << "program_start=" << IcingaApplication::GetInstance()->GetStartTime() << "\n"
|
||||||
<< "\t" << "active_service_checks_enabled=1" << "\n"
|
<< "\t" << "active_service_checks_enabled=1" << "\n"
|
||||||
|
|
|
@ -26,8 +26,8 @@ using namespace icinga;
|
||||||
*/
|
*/
|
||||||
void ConvenienceComponent::Start(void)
|
void ConvenienceComponent::Start(void)
|
||||||
{
|
{
|
||||||
ConfigItem::OnCommitted.connect(boost::bind(&ConvenienceComponent::HostCommittedHandler, this, _1));
|
ConfigItem::OnCommitted.connect(boost::bind(&ConvenienceComponent::ObjectCommittedHandler, this, _1));
|
||||||
ConfigItem::OnRemoved.connect(boost::bind(&ConvenienceComponent::HostRemovedHandler, this, _1));
|
ConfigItem::OnRemoved.connect(boost::bind(&ConvenienceComponent::ObjectRemovedHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TDict>
|
template<typename TDict>
|
||||||
|
@ -68,7 +68,7 @@ static void CopyServiceAttributes(const Host::Ptr& host, TDict serviceDesc,
|
||||||
Service::ResolveDependencies(host, hostchecks));
|
Service::ResolveDependencies(host, hostchecks));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
void ConvenienceComponent::ObjectCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
{
|
{
|
||||||
if (item->GetType() != "Host")
|
if (item->GetType() != "Host")
|
||||||
return;
|
return;
|
||||||
|
@ -139,7 +139,7 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
||||||
host->Set("convenience_services", newServices);
|
host->Set("convenience_services", newServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
|
void ConvenienceComponent::ObjectRemovedHandler(const ConfigItem::Ptr& item)
|
||||||
{
|
{
|
||||||
if (item->GetType() != "Host")
|
if (item->GetType() != "Host")
|
||||||
return;
|
return;
|
||||||
|
@ -161,3 +161,4 @@ void ConvenienceComponent::HostRemovedHandler(const ConfigItem::Ptr& item)
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(convenience, ConvenienceComponent);
|
EXPORT_COMPONENT(convenience, ConvenienceComponent);
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,8 @@ public:
|
||||||
virtual void Start(void);
|
virtual void Start(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void HostAddedHandler(const ConfigItem::Ptr& item);
|
void ObjectCommittedHandler(const ConfigItem::Ptr& item);
|
||||||
void HostCommittedHandler(const ConfigItem::Ptr& item);
|
void ObjectRemovedHandler(const ConfigItem::Ptr& item);
|
||||||
void HostRemovedHandler(const ConfigItem::Ptr& item);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ void DemoComponent::Start(void)
|
||||||
{
|
{
|
||||||
m_Endpoint = Endpoint::MakeEndpoint("demo", true);
|
m_Endpoint = Endpoint::MakeEndpoint("demo", true);
|
||||||
m_Endpoint->RegisterTopicHandler("demo::HelloWorld",
|
m_Endpoint->RegisterTopicHandler("demo::HelloWorld",
|
||||||
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2, _3));
|
boost::bind(&DemoComponent::HelloWorldRequestHandler, this, _2,
|
||||||
|
_3));
|
||||||
|
|
||||||
m_DemoTimer = boost::make_shared<Timer>();
|
m_DemoTimer = boost::make_shared<Timer>();
|
||||||
m_DemoTimer->SetInterval(5);
|
m_DemoTimer->SetInterval(5);
|
||||||
|
@ -51,20 +52,25 @@ void DemoComponent::Stop(void)
|
||||||
*/
|
*/
|
||||||
void DemoComponent::DemoTimerHandler(void)
|
void DemoComponent::DemoTimerHandler(void)
|
||||||
{
|
{
|
||||||
Logger::Write(LogInformation, "demo", "Sending multicast 'hello world' message.");
|
Logger::Write(LogInformation, "demo", "Sending multicast 'hello"
|
||||||
|
" world' message.");
|
||||||
|
|
||||||
RequestMessage request;
|
RequestMessage request;
|
||||||
request.SetMethod("demo::HelloWorld");
|
request.SetMethod("demo::HelloWorld");
|
||||||
|
|
||||||
EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint, request);
|
EndpointManager::GetInstance()->SendMulticastMessage(m_Endpoint,
|
||||||
|
request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes demo::HelloWorld messages.
|
* Processes demo::HelloWorld messages.
|
||||||
*/
|
*/
|
||||||
void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request)
|
void DemoComponent::HelloWorldRequestHandler(const Endpoint::Ptr& sender,
|
||||||
|
const RequestMessage& request)
|
||||||
{
|
{
|
||||||
Logger::Write(LogInformation, "demo", "Got 'hello world' from address=" + sender->GetAddress() + ", identity=" + sender->GetName());
|
Logger::Write(LogInformation, "demo", "Got 'hello world' from"
|
||||||
|
" address=" + sender->GetAddress() + ", identity=" +
|
||||||
|
sender->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_COMPONENT(demo, DemoComponent);
|
EXPORT_COMPONENT(demo, DemoComponent);
|
||||||
|
|
|
@ -51,7 +51,7 @@ AM_PROG_LEX
|
||||||
AC_PROG_YACC
|
AC_PROG_YACC
|
||||||
AC_PROG_LIBTOOL
|
AC_PROG_LIBTOOL
|
||||||
AX_CXX_GCC_ABI_DEMANGLE
|
AX_CXX_GCC_ABI_DEMANGLE
|
||||||
AX_BOOST_BASE([1.46], [], [AC_MSG_ERROR([You need the Boost headers and libraries in order to build this application])])
|
AX_BOOST_BASE([1.41], [], [AC_MSG_ERROR([You need the Boost headers and libraries in order to build this application])])
|
||||||
AX_BOOST_SIGNALS
|
AX_BOOST_SIGNALS
|
||||||
AX_BOOST_THREAD
|
AX_BOOST_THREAD
|
||||||
AX_BOOST_SYSTEM
|
AX_BOOST_SYSTEM
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[git-buildpackage]
|
||||||
|
prebuild = NOCONFIGURE=1 ./autogen.sh
|
|
@ -648,7 +648,7 @@ WARN_LOGFILE =
|
||||||
# directories like "/usr/src/myproject". Separate the files or directories
|
# directories like "/usr/src/myproject". Separate the files or directories
|
||||||
# with spaces.
|
# with spaces.
|
||||||
|
|
||||||
INPUT = @top_srcdir@/base @top_srcdir@/jsonrpc @top_srcdir@/icinga @top_srcdir@/components @top_srcdir@/icinga-app
|
INPUT = lib/base lib/config lib/icinga lib/remoting components icinga-app
|
||||||
|
|
||||||
# This tag can be used to specify the character encoding of the source files
|
# This tag can be used to specify the character encoding of the source files
|
||||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
|
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
|
||||||
|
@ -694,7 +694,7 @@ EXCLUDE_SYMLINKS = NO
|
||||||
# against the file with absolute path, so to exclude all test directories
|
# against the file with absolute path, so to exclude all test directories
|
||||||
# for example use the pattern */test/*
|
# for example use the pattern */test/*
|
||||||
|
|
||||||
EXCLUDE_PATTERNS =
|
EXCLUDE_PATTERNS = */lib/config/config_parser* */lib/config/config_lexer*
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
|
|
|
@ -4,12 +4,12 @@ SUBDIRS = \
|
||||||
config
|
config
|
||||||
|
|
||||||
bin_PROGRAMS = \
|
bin_PROGRAMS = \
|
||||||
icinga
|
icinga2
|
||||||
|
|
||||||
icinga_SOURCES = \
|
icinga2_SOURCES = \
|
||||||
icinga.cpp
|
icinga.cpp
|
||||||
|
|
||||||
icinga_CPPFLAGS = \
|
icinga2_CPPFLAGS = \
|
||||||
-DI2_ICINGALAUNCHER_BUILD \
|
-DI2_ICINGALAUNCHER_BUILD \
|
||||||
$(LTDLINCL) \
|
$(LTDLINCL) \
|
||||||
$(BOOST_CPPFLAGS) \
|
$(BOOST_CPPFLAGS) \
|
||||||
|
@ -19,10 +19,10 @@ icinga_CPPFLAGS = \
|
||||||
-I${top_srcdir}/lib/icinga \
|
-I${top_srcdir}/lib/icinga \
|
||||||
-I${top_srcdir}
|
-I${top_srcdir}
|
||||||
|
|
||||||
icinga_LDFLAGS = \
|
icinga2_LDFLAGS = \
|
||||||
$(BOOST_LDFLAGS)
|
$(BOOST_LDFLAGS)
|
||||||
|
|
||||||
icinga_LDADD = \
|
icinga2_LDADD = \
|
||||||
$(LIBLTDL) \
|
$(LIBLTDL) \
|
||||||
$(BOOST_SIGNALS_LIB) \
|
$(BOOST_SIGNALS_LIB) \
|
||||||
$(BOOST_THREAD_LIB) \
|
$(BOOST_THREAD_LIB) \
|
||||||
|
@ -38,6 +38,6 @@ icinga_LDADD = \
|
||||||
-dlopen ${top_builddir}/components/delegation/delegation.la \
|
-dlopen ${top_builddir}/components/delegation/delegation.la \
|
||||||
-dlopen ${top_builddir}/components/demo/demo.la
|
-dlopen ${top_builddir}/components/demo/demo.la
|
||||||
|
|
||||||
icinga_DEPENDENCIES = \
|
icinga2_DEPENDENCIES = \
|
||||||
${top_builddir}/components/replication/replication.la \
|
${top_builddir}/components/replication/replication.la \
|
||||||
${top_builddir}/components/convenience/convenience.la
|
${top_builddir}/components/convenience/convenience.la
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
icinga2confdir = $(sysconfdir)/icinga2
|
||||||
|
icinga2conf_DATA = \
|
||||||
|
icinga2.conf.dist \
|
||||||
|
example-ca.crt \
|
||||||
|
example-ca.key \
|
||||||
|
icinga-c1.pem \
|
||||||
|
icinga-c2.pem \
|
||||||
|
icinga-c3.pem
|
||||||
|
|
||||||
|
EXTRA_DIST = $(icinga2conf_DATA)
|
|
@ -24,8 +24,6 @@
|
||||||
# define ICINGA_VERSION VERSION ", " GIT_MESSAGE
|
# define ICINGA_VERSION VERSION ", " GIT_MESSAGE
|
||||||
|
|
||||||
# include <ltdl.h>
|
# include <ltdl.h>
|
||||||
#else /* _WIN32 */
|
|
||||||
# define ICINGA_VERSION VERSION
|
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
@ -51,7 +49,11 @@ int main(int argc, char **argv)
|
||||||
* in the base library. */
|
* in the base library. */
|
||||||
Application::SetMainThread();
|
Application::SetMainThread();
|
||||||
|
|
||||||
Logger::Write(LogInformation, "icinga", "Icinga application loader (version: " ICINGA_VERSION ")");
|
Logger::Write(LogInformation, "icinga", "Icinga application loader"
|
||||||
|
#ifndef _WIN32
|
||||||
|
" (version: " ICINGA_VERSION ")"
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
);
|
||||||
|
|
||||||
if (argc < 3 || strcmp(argv[1], "-c") != 0) {
|
if (argc < 3 || strcmp(argv[1], "-c") != 0) {
|
||||||
stringstream msgbuf;
|
stringstream msgbuf;
|
||||||
|
|
|
@ -33,7 +33,7 @@ make install DESTDIR=%{buildroot}
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%defattr(-,root,root)
|
%defattr(-,root,root)
|
||||||
%{_bindir}/icinga
|
%{_bindir}/icinga2
|
||||||
%{_datadir}/doc/icinga2
|
%{_datadir}/doc/icinga2
|
||||||
%{_libdir}/icinga2
|
%{_libdir}/icinga2
|
||||||
%{_sysconfdir}/icinga2
|
%{_sysconfdir}/icinga2
|
||||||
|
|
|
@ -347,13 +347,7 @@ void Application::UpdatePidFile(const String& filename)
|
||||||
}
|
}
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
#ifndef _WIN32
|
fprintf(m_PidFile, "%d", Utility::GetPid());
|
||||||
pid_t pid = getpid();
|
|
||||||
#else /* _WIN32 */
|
|
||||||
DWORD pid = GetCurrentProcessId();
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
fprintf(m_PidFile, "%d", pid);
|
|
||||||
fflush(m_PidFile);
|
fflush(m_PidFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,12 @@ public:
|
||||||
|
|
||||||
int Run(int argc, char **argv);
|
int Run(int argc, char **argv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the application.
|
||||||
|
*
|
||||||
|
* @param args Arguments for the application.
|
||||||
|
* @returns The exit code of the application.
|
||||||
|
*/
|
||||||
virtual int Main(const vector<String>& args) = 0;
|
virtual int Main(const vector<String>& args) = 0;
|
||||||
|
|
||||||
static void Shutdown(void);
|
static void Shutdown(void);
|
||||||
|
|
|
@ -35,6 +35,9 @@ public:
|
||||||
typedef shared_ptr<AsyncTask<TClass, TResult> > Ptr;
|
typedef shared_ptr<AsyncTask<TClass, TResult> > Ptr;
|
||||||
typedef weak_ptr<AsyncTask<TClass, TResult> > WeakPtr;
|
typedef weak_ptr<AsyncTask<TClass, TResult> > WeakPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A completion callback for an AsyncTask.
|
||||||
|
*/
|
||||||
typedef function<void (const shared_ptr<TClass>&)> CompletionCallback;
|
typedef function<void (const shared_ptr<TClass>&)> CompletionCallback;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,6 +121,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Begins executing the task. The Run method must ensure
|
||||||
|
* that one of the Finish*() functions is executed on the task
|
||||||
|
* object (possibly after the Run method has returned).
|
||||||
|
*/
|
||||||
virtual void Run(void) = 0;
|
virtual void Run(void) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
<ClCompile Include="tcpclient.cpp" />
|
<ClCompile Include="tcpclient.cpp" />
|
||||||
<ClCompile Include="tcpserver.cpp" />
|
<ClCompile Include="tcpserver.cpp" />
|
||||||
<ClCompile Include="tcpsocket.cpp" />
|
<ClCompile Include="tcpsocket.cpp" />
|
||||||
<ClCompile Include="threadpool.cpp" />
|
|
||||||
<ClCompile Include="timer.cpp" />
|
<ClCompile Include="timer.cpp" />
|
||||||
<ClCompile Include="tlsclient.cpp" />
|
<ClCompile Include="tlsclient.cpp" />
|
||||||
<ClCompile Include="unix.cpp" />
|
<ClCompile Include="unix.cpp" />
|
||||||
|
@ -69,7 +68,6 @@
|
||||||
<ClInclude Include="tcpclient.h" />
|
<ClInclude Include="tcpclient.h" />
|
||||||
<ClInclude Include="tcpserver.h" />
|
<ClInclude Include="tcpserver.h" />
|
||||||
<ClInclude Include="tcpsocket.h" />
|
<ClInclude Include="tcpsocket.h" />
|
||||||
<ClInclude Include="threadpool.h" />
|
|
||||||
<ClInclude Include="timer.h" />
|
<ClInclude Include="timer.h" />
|
||||||
<ClInclude Include="tlsclient.h" />
|
<ClInclude Include="tlsclient.h" />
|
||||||
<ClInclude Include="unix.h" />
|
<ClInclude Include="unix.h" />
|
||||||
|
|
|
@ -34,9 +34,6 @@
|
||||||
<ClCompile Include="tcpsocket.cpp">
|
<ClCompile Include="tcpsocket.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="threadpool.cpp">
|
|
||||||
<Filter>Quelldateien</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="timer.cpp">
|
<ClCompile Include="timer.cpp">
|
||||||
<Filter>Quelldateien</Filter>
|
<Filter>Quelldateien</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -129,9 +126,6 @@
|
||||||
<ClInclude Include="tcpsocket.h">
|
<ClInclude Include="tcpsocket.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="threadpool.h">
|
|
||||||
<Filter>Headerdateien</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="timer.h">
|
<ClInclude Include="timer.h">
|
||||||
<Filter>Headerdateien</Filter>
|
<Filter>Headerdateien</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for application extensions.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API IComponent : public Object
|
class I2_BASE_API IComponent : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -36,7 +41,8 @@ protected:
|
||||||
DynamicObject::Ptr GetConfig(void) const;
|
DynamicObject::Ptr GetConfig(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DynamicObject *m_Config;
|
DynamicObject *m_Config; /**< The configuration object for this
|
||||||
|
component. */
|
||||||
|
|
||||||
friend class Component;
|
friend class Component;
|
||||||
};
|
};
|
||||||
|
@ -59,7 +65,8 @@ public:
|
||||||
static void AddSearchDir(const String& componentDirectory);
|
static void AddSearchDir(const String& componentDirectory);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IComponent::Ptr m_Impl;
|
IComponent::Ptr m_Impl; /**< The implementation object for this
|
||||||
|
component. */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef IComponent *(*CreateComponentFunction)(void);
|
typedef IComponent *(*CreateComponentFunction)(void);
|
||||||
|
|
|
@ -23,15 +23,31 @@
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the keys of dictionary keys using the less operator.
|
* Compares dictionary keys using the less operator.
|
||||||
*/
|
*/
|
||||||
struct DictionaryKeyLessComparer
|
struct DictionaryKeyLessComparer
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Compares two keys.
|
||||||
|
*
|
||||||
|
* @param a The first key.
|
||||||
|
* @param b The second key.
|
||||||
|
* @returns true if the first key is less than the second key, false
|
||||||
|
* otherwise
|
||||||
|
*/
|
||||||
bool operator()(const pair<String, Value>& a, const char *b)
|
bool operator()(const pair<String, Value>& a, const char *b)
|
||||||
{
|
{
|
||||||
return a.first < b;
|
return a.first < b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two keys.
|
||||||
|
*
|
||||||
|
* @param a The first key.
|
||||||
|
* @param b The second key.
|
||||||
|
* @returns true if the first key is less than the second key, false
|
||||||
|
* otherwise
|
||||||
|
*/
|
||||||
bool operator()(const char *a, const pair<String, Value>& b)
|
bool operator()(const char *a, const pair<String, Value>& b)
|
||||||
{
|
{
|
||||||
return a < b.first;
|
return a < b.first;
|
||||||
|
@ -217,9 +233,8 @@ Dictionary::Ptr Dictionary::FromJson(cJSON *json)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a dictionary to a JSON object.
|
* Converts this dictionary to a JSON object.
|
||||||
*
|
*
|
||||||
* @param dictionary The dictionary.
|
|
||||||
* @returns A JSON object that is equivalent to the dictionary. Values that
|
* @returns A JSON object that is equivalent to the dictionary. Values that
|
||||||
* cannot be represented in JSON are omitted.
|
* cannot be represented in JSON are omitted.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -34,6 +34,9 @@ public:
|
||||||
typedef shared_ptr<Dictionary> Ptr;
|
typedef shared_ptr<Dictionary> Ptr;
|
||||||
typedef weak_ptr<Dictionary> WeakPtr;
|
typedef weak_ptr<Dictionary> WeakPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An iterator that can be used to iterate over dictionary elements.
|
||||||
|
*/
|
||||||
typedef map<String, Value>::iterator Iterator;
|
typedef map<String, Value>::iterator Iterator;
|
||||||
|
|
||||||
Value Get(const char *key) const;
|
Value Get(const char *key) const;
|
||||||
|
@ -56,7 +59,7 @@ public:
|
||||||
cJSON *ToJson(void) const;
|
cJSON *ToJson(void) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
map<String, Value> m_Data;
|
map<String, Value> m_Data; /**< The data for the dictionary. */
|
||||||
};
|
};
|
||||||
|
|
||||||
inline Dictionary::Iterator range_begin(Dictionary::Ptr x)
|
inline Dictionary::Iterator range_begin(Dictionary::Ptr x)
|
||||||
|
|
|
@ -85,15 +85,18 @@ Dictionary::Ptr DynamicObject::BuildUpdate(double sinceTx, int attributeTypes) c
|
||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes)
|
void DynamicObject::ApplyUpdate(const Dictionary::Ptr& serializedUpdate,
|
||||||
|
int allowedTypes)
|
||||||
{
|
{
|
||||||
InternalApplyUpdate(serializedUpdate, allowedTypes, false);
|
InternalApplyUpdate(serializedUpdate, allowedTypes, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes, bool suppressEvents)
|
void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate,
|
||||||
|
int allowedTypes, bool suppressEvents)
|
||||||
{
|
{
|
||||||
double configTx = 0;
|
double configTx = 0;
|
||||||
if ((allowedTypes & Attribute_Config) != 0 && serializedUpdate->Contains("configTx")) {
|
if ((allowedTypes & Attribute_Config) != 0 &&
|
||||||
|
serializedUpdate->Contains("configTx")) {
|
||||||
configTx = serializedUpdate->Get("configTx");
|
configTx = serializedUpdate->Get("configTx");
|
||||||
|
|
||||||
if (configTx > m_ConfigTx)
|
if (configTx > m_ConfigTx)
|
||||||
|
@ -127,7 +130,8 @@ void DynamicObject::InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicObject::RegisterAttribute(const String& name, DynamicAttributeType type)
|
void DynamicObject::RegisterAttribute(const String& name,
|
||||||
|
DynamicAttributeType type)
|
||||||
{
|
{
|
||||||
DynamicAttribute attr;
|
DynamicAttribute attr;
|
||||||
attr.Type = type;
|
attr.Type = type;
|
||||||
|
@ -155,7 +159,8 @@ Value DynamicObject::Get(const String& name) const
|
||||||
return InternalGetAttribute(name);
|
return InternalGetAttribute(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicObject::InternalSetAttribute(const String& name, const Value& data, double tx, bool suppressEvent)
|
void DynamicObject::InternalSetAttribute(const String& name, const Value& data,
|
||||||
|
double tx, bool suppressEvent)
|
||||||
{
|
{
|
||||||
DynamicAttribute attr;
|
DynamicAttribute attr;
|
||||||
attr.Type = Attribute_Transient;
|
attr.Type = Attribute_Transient;
|
||||||
|
@ -214,16 +219,6 @@ void DynamicObject::ClearAttributesByType(DynamicAttributeType type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicObject::AttributeConstIterator DynamicObject::AttributeBegin(void) const
|
|
||||||
{
|
|
||||||
return m_Attributes.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
DynamicObject::AttributeConstIterator DynamicObject::AttributeEnd(void) const
|
|
||||||
{
|
|
||||||
return m_Attributes.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
String DynamicObject::GetType(void) const
|
String DynamicObject::GetType(void) const
|
||||||
{
|
{
|
||||||
return Get("__type");
|
return Get("__type");
|
||||||
|
@ -422,7 +417,8 @@ void DynamicObject::RestoreObjects(const String& filename)
|
||||||
std::ifstream fp;
|
std::ifstream fp;
|
||||||
fp.open(filename.CStr());
|
fp.open(filename.CStr());
|
||||||
|
|
||||||
/* TODO: Fix this horrible mess. */
|
/* TODO: Fix this horrible mess by implementing a class that provides
|
||||||
|
* IOQueue functionality for files. */
|
||||||
FIFO::Ptr fifo = boost::make_shared<FIFO>();
|
FIFO::Ptr fifo = boost::make_shared<FIFO>();
|
||||||
while (fp) {
|
while (fp) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of an attribute for a DynamicObject.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
enum DynamicAttributeType
|
enum DynamicAttributeType
|
||||||
{
|
{
|
||||||
Attribute_Transient = 1,
|
Attribute_Transient = 1,
|
||||||
|
@ -43,15 +48,21 @@ enum DynamicAttributeType
|
||||||
Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Replicated | Attribute_Config
|
Attribute_All = Attribute_Transient | Attribute_Local | Attribute_Replicated | Attribute_Config
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An attribute for a DynamicObject.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
struct DynamicAttribute
|
struct DynamicAttribute
|
||||||
{
|
{
|
||||||
Value Data;
|
Value Data; /**< The current value of the attribute. */
|
||||||
DynamicAttributeType Type;
|
DynamicAttributeType Type; /**< The type of the attribute. */
|
||||||
double Tx;
|
double Tx; /**< The timestamp of the last value change. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dynamic object that can be instantiated from the configuration file.
|
* A dynamic object that can be instantiated from the configuration file
|
||||||
|
* and that supports attribute replication to remote application instances.
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
|
@ -86,9 +97,6 @@ public:
|
||||||
|
|
||||||
void ClearAttributesByType(DynamicAttributeType type);
|
void ClearAttributesByType(DynamicAttributeType type);
|
||||||
|
|
||||||
AttributeConstIterator AttributeBegin(void) const;
|
|
||||||
AttributeConstIterator AttributeEnd(void) const;
|
|
||||||
|
|
||||||
static boost::signal<void (const DynamicObject::Ptr&)> OnRegistered;
|
static boost::signal<void (const DynamicObject::Ptr&)> OnRegistered;
|
||||||
static boost::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
|
static boost::signal<void (const DynamicObject::Ptr&)> OnUnregistered;
|
||||||
static boost::signal<void (const set<DynamicObject::Ptr>&)> OnTransactionClosing;
|
static boost::signal<void (const set<DynamicObject::Ptr>&)> OnTransactionClosing;
|
||||||
|
@ -147,6 +155,11 @@ private:
|
||||||
void InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes, bool suppressEvents);
|
void InternalApplyUpdate(const Dictionary::Ptr& serializedUpdate, int allowedTypes, bool suppressEvents);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for registering DynamicObject implementation classes.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class RegisterClassHelper
|
class RegisterClassHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -157,6 +170,11 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory function for DynamicObject-based classes.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
shared_ptr<T> DynamicObjectFactory(const Dictionary::Ptr& serializedUpdate)
|
shared_ptr<T> DynamicObjectFactory(const Dictionary::Ptr& serializedUpdate)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A thread-safe event that can be posted to the main thread's event queue.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API Event
|
class I2_BASE_API Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -86,6 +86,8 @@ DEFINE_EXCEPTION_CLASS(NotImplementedException);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/**
|
/**
|
||||||
* A Win32 error encapsulated in an exception.
|
* A Win32 error encapsulated in an exception.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class Win32Exception : public Exception
|
class Win32Exception : public Exception
|
||||||
{
|
{
|
||||||
|
@ -112,6 +114,8 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Posix error encapsulated in an exception.
|
* A Posix error encapsulated in an exception.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class PosixException : public Exception
|
class PosixException : public Exception
|
||||||
{
|
{
|
||||||
|
@ -137,6 +141,8 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An OpenSSL error encapsulated in an exception.
|
* An OpenSSL error encapsulated in an exception.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class OpenSSLException : public Exception
|
class OpenSSLException : public Exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -130,21 +130,6 @@ void FIFO::Read(void *buffer, size_t count)
|
||||||
Optimize();
|
Optimize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a pointer to the start of the write buffer.
|
|
||||||
*
|
|
||||||
* @param count Minimum size of the buffer; on return this parameter
|
|
||||||
* contains the actual size of the available buffer which can
|
|
||||||
* be larger than the requested size.
|
|
||||||
*/
|
|
||||||
/*void *FIFO::GetWriteBuffer(size_t *count)
|
|
||||||
{
|
|
||||||
ResizeBuffer(m_Offset + m_DataSize + *count);
|
|
||||||
*count = m_AllocSize - m_Offset - m_DataSize;
|
|
||||||
|
|
||||||
return m_Buffer + m_Offset + m_DataSize;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements IOQueue::Write.
|
* Implements IOQueue::Write.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,8 @@ namespace icinga
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An I/O queue.
|
* An I/O queue.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class IOQueue
|
class IOQueue
|
||||||
{
|
{
|
||||||
|
@ -41,8 +43,8 @@ public:
|
||||||
* to read more data than is available in the queue is a programming error.
|
* to read more data than is available in the queue is a programming error.
|
||||||
* Use GetBytesAvailable() to check how much data is available.
|
* Use GetBytesAvailable() to check how much data is available.
|
||||||
*
|
*
|
||||||
* @buffer The buffer where data should be stored. May be NULL if you're
|
* @param buffer The buffer where data should be stored. May be NULL if
|
||||||
* not actually interested in the data.
|
* you're not actually interested in the data.
|
||||||
* @param count The number of bytes to read from the queue.
|
* @param count The number of bytes to read from the queue.
|
||||||
*/
|
*/
|
||||||
virtual void Peek(void *buffer, size_t count) = 0;
|
virtual void Peek(void *buffer, size_t count) = 0;
|
||||||
|
|
|
@ -24,10 +24,9 @@ using namespace icinga;
|
||||||
REGISTER_CLASS(Logger);
|
REGISTER_CLASS(Logger);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the logger class.
|
* Constructor for the Logger class.
|
||||||
*
|
*
|
||||||
* @param minSeverity The minimum severity of log messages that should be sent
|
* @param properties A serialized dictionary containing attributes.
|
||||||
* to this logger.
|
|
||||||
*/
|
*/
|
||||||
Logger::Logger(const Dictionary::Ptr& properties)
|
Logger::Logger(const Dictionary::Ptr& properties)
|
||||||
: DynamicObject(properties)
|
: DynamicObject(properties)
|
||||||
|
@ -165,3 +164,14 @@ LogSeverity Logger::StringToSeverity(const String& severity)
|
||||||
else
|
else
|
||||||
throw_exception(invalid_argument("Invalid severity: " + severity));
|
throw_exception(invalid_argument("Invalid severity: " + severity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the configuration object that belongs to this logger.
|
||||||
|
*
|
||||||
|
* @returns The configuration object.
|
||||||
|
*/
|
||||||
|
DynamicObject::Ptr ILogger::GetConfig(void) const
|
||||||
|
{
|
||||||
|
return m_Config->GetSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,14 +42,16 @@ enum LogSeverity
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
struct LogEntry {
|
struct LogEntry {
|
||||||
double Timestamp;
|
double Timestamp; /**< The timestamp when this log entry was created. */
|
||||||
LogSeverity Severity;
|
LogSeverity Severity; /**< The severity of this log entry. */
|
||||||
String Facility;
|
String Facility; /**< The facility this log entry belongs to. */
|
||||||
String Message;
|
String Message; /**< The log entry's message. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all loggers.
|
* Base class for all loggers.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API ILogger : public Object
|
class I2_BASE_API ILogger : public Object
|
||||||
{
|
{
|
||||||
|
@ -57,6 +59,12 @@ public:
|
||||||
typedef shared_ptr<ILogger> Ptr;
|
typedef shared_ptr<ILogger> Ptr;
|
||||||
typedef weak_ptr<ILogger> WeakPtr;
|
typedef weak_ptr<ILogger> WeakPtr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the log entry and writes it to the log that is
|
||||||
|
* represented by this ILogger object.
|
||||||
|
*
|
||||||
|
* @param entry The log entry that is to be processed.
|
||||||
|
*/
|
||||||
virtual void ProcessLogEntry(const LogEntry& entry) = 0;
|
virtual void ProcessLogEntry(const LogEntry& entry) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -68,6 +76,11 @@ private:
|
||||||
friend class Logger;
|
friend class Logger;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A log provider. Can be instantiated from the config.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API Logger : public DynamicObject
|
class I2_BASE_API Logger : public DynamicObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -24,9 +24,9 @@ using namespace icinga;
|
||||||
/**
|
/**
|
||||||
* Reads data from an IOQueue in netString format.
|
* Reads data from an IOQueue in netString format.
|
||||||
*
|
*
|
||||||
* @param fifo The IOQueue to read from.
|
* @param queue The IOQueue to read from.
|
||||||
* @param[out] str The String that has been read from the FIFO.
|
* @param[out] str The String that has been read from the IOQueue.
|
||||||
* @returns true if a complete String was read from the FIFO, false otherwise.
|
* @returns true if a complete String was read from the IOQueue, false otherwise.
|
||||||
* @exception invalid_argument The input stream is invalid.
|
* @exception invalid_argument The input stream is invalid.
|
||||||
* @see https://github.com/PeterScott/netString-c/blob/master/netString.c
|
* @see https://github.com/PeterScott/netString-c/blob/master/netString.c
|
||||||
*/
|
*/
|
||||||
|
@ -104,16 +104,16 @@ bool NetString::ReadStringFromIOQueue(IOQueue *queue, String *str)
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
/* remove the data from the fifo */
|
/* remove the data from the IOQueue */
|
||||||
queue->Read(NULL, buffer_length);
|
queue->Read(NULL, buffer_length);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes data into a FIFO using the netString format.
|
* Writes data into an IOQueue using the netString format.
|
||||||
*
|
*
|
||||||
* @param fifo The FIFO.
|
* @param queue The IOQueue.
|
||||||
* @param str The String that is to be written.
|
* @param str The String that is to be written.
|
||||||
*/
|
*/
|
||||||
void NetString::WriteStringToIOQueue(IOQueue *queue, const String& str)
|
void NetString::WriteStringToIOQueue(IOQueue *queue, const String& str)
|
||||||
|
|
|
@ -24,9 +24,9 @@ namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper functions for reading/writing messages in the netString format.
|
* Helper functions for reading/writing messages in the netstring format.
|
||||||
*
|
*
|
||||||
* @see http://cr.yp.to/proto/netStrings.txt
|
* @see http://cr.yp.to/proto/netstrings.txt
|
||||||
*
|
*
|
||||||
* @ingroup base
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,14 +42,28 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds a shared pointer and provides support for implicit upcasts.
|
* Holds a shared pointer and provides support for implicit upcasts.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class SharedPtrHolder
|
class SharedPtrHolder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor for the SharedPtrHolder class.
|
||||||
|
*
|
||||||
|
* @param object The shared pointer that should be used to
|
||||||
|
* construct this shared pointer holder.
|
||||||
|
*/
|
||||||
explicit SharedPtrHolder(const Object::Ptr& object)
|
explicit SharedPtrHolder(const Object::Ptr& object)
|
||||||
: m_Object(object)
|
: m_Object(object)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a shared pointer for the object that is associated
|
||||||
|
* this holder instance.
|
||||||
|
*
|
||||||
|
* @returns A shared pointer.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
operator shared_ptr<T>(void) const
|
operator shared_ptr<T>(void) const
|
||||||
{
|
{
|
||||||
|
@ -63,6 +77,12 @@ public:
|
||||||
return other;
|
return other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a weak pointer for the object that is associated
|
||||||
|
* with this holder instance.
|
||||||
|
*
|
||||||
|
* @returns A weak pointer.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
operator weak_ptr<T>(void) const
|
operator weak_ptr<T>(void) const
|
||||||
{
|
{
|
||||||
|
@ -70,7 +90,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Object::Ptr m_Object;
|
Object::Ptr m_Object; /**< The object that belongs to this
|
||||||
|
holder instance */
|
||||||
};
|
};
|
||||||
|
|
||||||
SharedPtrHolder GetSelf(void);
|
SharedPtrHolder GetSelf(void);
|
||||||
|
@ -88,23 +109,33 @@ private:
|
||||||
Object(const Object& other);
|
Object(const Object& other);
|
||||||
Object& operator=(const Object& rhs);
|
Object& operator=(const Object& rhs);
|
||||||
|
|
||||||
static boost::mutex m_Mutex;
|
static boost::mutex m_Mutex; /**< Mutex which protects static members
|
||||||
static vector<Object::Ptr> m_HeldObjects;
|
of the Object class. */
|
||||||
|
static vector<Object::Ptr> m_HeldObjects; /**< Currently held
|
||||||
|
objects. */
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
static set<Object *> m_AliveObjects;
|
static set<Object *> m_AliveObjects; /**< Currently alive objects -
|
||||||
|
for debugging purposes. */
|
||||||
#endif /* _DEBUG */
|
#endif /* _DEBUG */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares a weak pointer with a raw pointer.
|
* Compares a weak pointer with a raw pointer.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
struct WeakPtrEqual
|
struct WeakPtrEqual
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const void *m_Ref;
|
const void *m_Ref; /**< The object. */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor for the WeakPtrEqual class.
|
||||||
|
*
|
||||||
|
* @param ref The object that should be compared with the weak pointer.
|
||||||
|
*/
|
||||||
WeakPtrEqual(const void *ref) : m_Ref(ref) { }
|
WeakPtrEqual(const void *ref) : m_Ref(ref) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of a Process task.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
struct ProcessResult
|
struct ProcessResult
|
||||||
{
|
{
|
||||||
double ExecutionStart;
|
double ExecutionStart;
|
||||||
|
@ -31,6 +36,12 @@ struct ProcessResult
|
||||||
String Output;
|
String Output;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A process task. Executes an external application and returns the exit
|
||||||
|
* code and console output.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API Process : public AsyncTask<Process, ProcessResult>
|
class I2_BASE_API Process : public AsyncTask<Process, ProcessResult>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License *
|
||||||
|
* as published by the Free Software Foundation; either version 2 *
|
||||||
|
* of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#include "i2-base.h"
|
#include "i2-base.h"
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* 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 STRING_H
|
#ifndef STRING_H
|
||||||
#define STRING_H
|
#define STRING_H
|
||||||
|
|
||||||
|
@ -6,7 +25,7 @@ namespace icinga {
|
||||||
/**
|
/**
|
||||||
* String class.
|
* String class.
|
||||||
*
|
*
|
||||||
* Rationale: The std::string class has an ambiguous assignment
|
* Rationale for having this: The std::string class has an ambiguous assignment
|
||||||
* operator when used in conjunction with the Value class.
|
* operator when used in conjunction with the Value class.
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API String
|
class I2_BASE_API String
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A ring buffer that holds a pre-defined number of integers.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API RingBuffer
|
class I2_BASE_API RingBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -25,6 +25,11 @@ namespace icinga
|
||||||
|
|
||||||
class ScriptTask;
|
class ScriptTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A script function that can be used to execute a script task.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API ScriptFunction : public Object
|
class I2_BASE_API ScriptFunction : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A script task.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
|
*/
|
||||||
class I2_BASE_API ScriptTask : public AsyncTask<ScriptTask, Value>
|
class I2_BASE_API ScriptTask : public AsyncTask<ScriptTask, Value>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -13,7 +13,6 @@ StreamLogger::StreamLogger(void)
|
||||||
* Constructor for the StreamLogger class.
|
* Constructor for the StreamLogger class.
|
||||||
*
|
*
|
||||||
* @param stream The stream.
|
* @param stream The stream.
|
||||||
* @param minSeverity Minimum severity for log messages.
|
|
||||||
*/
|
*/
|
||||||
StreamLogger::StreamLogger(ostream *stream)
|
StreamLogger::StreamLogger(ostream *stream)
|
||||||
: ILogger(), m_Stream(stream), m_OwnsStream(false)
|
: ILogger(), m_Stream(stream), m_OwnsStream(false)
|
||||||
|
|
|
@ -5,7 +5,9 @@ namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A logger that logs to stdout.
|
* A logger that logs to an iostream.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API StreamLogger : public ILogger
|
class I2_BASE_API StreamLogger : public ILogger
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or *
|
||||||
|
* modify it under the terms of the GNU General Public License *
|
||||||
|
* as published by the Free Software Foundation; either version 2 *
|
||||||
|
* of the License, or (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License for more details. *
|
||||||
|
* *
|
||||||
|
* You should have received a copy of the GNU General Public License *
|
||||||
|
* along with this program; if not, write to the Free Software Foundation *
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
#include "i2-base.h"
|
#include "i2-base.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
|
|
@ -1,3 +1,22 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* 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 SYSLOGLOGGER_H
|
#ifndef SYSLOGLOGGER_H
|
||||||
#define SYSLOGLOGGER_H
|
#define SYSLOGLOGGER_H
|
||||||
|
|
||||||
|
@ -7,6 +26,8 @@ namespace icinga
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A logger that logs to syslog.
|
* A logger that logs to syslog.
|
||||||
|
*
|
||||||
|
* @ingroup base
|
||||||
*/
|
*/
|
||||||
class I2_BASE_API SyslogLogger : public ILogger
|
class I2_BASE_API SyslogLogger : public ILogger
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
TcpServer(void);
|
TcpServer(void);
|
||||||
|
|
||||||
void SetClientFactory(const ClientFactory& function);
|
void SetClientFactory(const ClientFactory& clientFactory);
|
||||||
ClientFactory GetFactoryFunction(void) const;
|
ClientFactory GetFactoryFunction(void) const;
|
||||||
|
|
||||||
void Listen(void);
|
void Listen(void);
|
||||||
|
|
|
@ -145,10 +145,12 @@ String Utility::GetCertificateCN(const shared_ptr<X509>& certificate)
|
||||||
{
|
{
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
|
||||||
int rc = X509_NAME_get_text_by_NID(X509_get_subject_name(certificate.get()), NID_commonName, buffer, sizeof(buffer));
|
int rc = X509_NAME_get_text_by_NID(X509_get_subject_name(certificate.get()),
|
||||||
|
NID_commonName, buffer, sizeof(buffer));
|
||||||
|
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
throw_exception(OpenSSLException("X509 certificate has no CN attribute", ERR_get_error()));
|
throw_exception(OpenSSLException("X509 certificate has no CN"
|
||||||
|
" attribute", ERR_get_error()));
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -165,14 +167,17 @@ shared_ptr<X509> Utility::GetX509Certificate(String pemfile)
|
||||||
BIO *fpcert = BIO_new(BIO_s_file());
|
BIO *fpcert = BIO_new(BIO_s_file());
|
||||||
|
|
||||||
if (fpcert == NULL)
|
if (fpcert == NULL)
|
||||||
throw_exception(OpenSSLException("BIO_new failed", ERR_get_error()));
|
throw_exception(OpenSSLException("BIO_new failed",
|
||||||
|
ERR_get_error()));
|
||||||
|
|
||||||
if (BIO_read_filename(fpcert, pemfile.CStr()) < 0)
|
if (BIO_read_filename(fpcert, pemfile.CStr()) < 0)
|
||||||
throw_exception(OpenSSLException("BIO_read_filename failed", ERR_get_error()));
|
throw_exception(OpenSSLException("BIO_read_filename failed",
|
||||||
|
ERR_get_error()));
|
||||||
|
|
||||||
cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL);
|
cert = PEM_read_bio_X509_AUX(fpcert, NULL, NULL, NULL);
|
||||||
if (cert == NULL)
|
if (cert == NULL)
|
||||||
throw_exception(OpenSSLException("PEM_read_bio_X509_AUX failed", ERR_get_error()));
|
throw_exception(OpenSSLException("PEM_read_bio_X509_AUX failed",
|
||||||
|
ERR_get_error()));
|
||||||
|
|
||||||
BIO_free(fpcert);
|
BIO_free(fpcert);
|
||||||
|
|
||||||
|
@ -210,7 +215,8 @@ String Utility::DirName(const String& path)
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
if (!PathRemoveFileSpec(dir)) {
|
if (!PathRemoveFileSpec(dir)) {
|
||||||
free(dir);
|
free(dir);
|
||||||
throw_exception(Win32Exception("PathRemoveFileSpec() failed", GetLastError()));
|
throw_exception(Win32Exception("PathRemoveFileSpec() failed",
|
||||||
|
GetLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
result = dir;
|
result = dir;
|
||||||
|
@ -249,7 +255,7 @@ String Utility::BaseName(const String& path)
|
||||||
/**
|
/**
|
||||||
* Null deleter. Used as a parameter for the shared_ptr constructor.
|
* Null deleter. Used as a parameter for the shared_ptr constructor.
|
||||||
*
|
*
|
||||||
* @param -- The object that should be deleted.
|
* @param - The object that should be deleted.
|
||||||
*/
|
*/
|
||||||
void Utility::NullDeleter(void *)
|
void Utility::NullDeleter(void *)
|
||||||
{
|
{
|
||||||
|
@ -289,3 +295,17 @@ double Utility::GetTime(void)
|
||||||
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
return tv.tv_sec + tv.tv_usec / 1000000.0;
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the current process.
|
||||||
|
*
|
||||||
|
* @returns The PID.
|
||||||
|
*/
|
||||||
|
pid_t Utility::GetPid(void)
|
||||||
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
|
return getpid();
|
||||||
|
#else /* _WIN32 */
|
||||||
|
return GetCurrentProcessId();
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
}
|
||||||
|
|
|
@ -44,10 +44,12 @@ public:
|
||||||
static String DirName(const String& path);
|
static String DirName(const String& path);
|
||||||
static String BaseName(const String& path);
|
static String BaseName(const String& path);
|
||||||
|
|
||||||
static void NullDeleter(void *obj);
|
static void NullDeleter(void *);
|
||||||
|
|
||||||
static double GetTime(void);
|
static double GetTime(void);
|
||||||
|
|
||||||
|
static pid_t GetPid(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool m_SSLInitialized;
|
static bool m_SSLInitialized;
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ cJSON *Value::ToJson(void) const
|
||||||
/**
|
/**
|
||||||
* Deserializes the string representation of a variant.
|
* Deserializes the string representation of a variant.
|
||||||
*
|
*
|
||||||
* @params jsonString A JSON string obtained from Value::Serialize
|
* @param jsonString A JSON string obtained from Value::Serialize
|
||||||
* @returns The newly deserialized variant.
|
* @returns The newly deserialized variant.
|
||||||
*/
|
*/
|
||||||
Value Value::Deserialize(const String& jsonString)
|
Value Value::Deserialize(const String& jsonString)
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#endif /* __MINGW32__ */
|
#endif /* __MINGW32__ */
|
||||||
|
|
||||||
typedef int socklen_t;
|
typedef int socklen_t;
|
||||||
|
typedef DWORD pid_t;
|
||||||
|
|
||||||
#define MAXPATHLEN MAX_PATH
|
#define MAXPATHLEN MAX_PATH
|
||||||
|
|
||||||
|
|
|
@ -23,38 +23,78 @@ using std::ifstream;
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
ConfigCompiler::ConfigCompiler(const String& path, istream *input, HandleIncludeFunc includeHandler)
|
/**
|
||||||
|
* Constructor for the ConfigCompiler class.
|
||||||
|
*
|
||||||
|
* @param path The path of the configuration file (or another name that
|
||||||
|
* identifies the source of the configuration text).
|
||||||
|
* @param input Input stream for the configuration file.
|
||||||
|
* @param includeHandler Handler function for #include directives.
|
||||||
|
*/
|
||||||
|
ConfigCompiler::ConfigCompiler(const String& path, istream *input,
|
||||||
|
HandleIncludeFunc includeHandler)
|
||||||
: m_Path(path), m_Input(input), m_HandleInclude(includeHandler)
|
: m_Path(path), m_Input(input), m_HandleInclude(includeHandler)
|
||||||
{
|
{
|
||||||
InitializeScanner();
|
InitializeScanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor for the ConfigCompiler class.
|
||||||
|
*/
|
||||||
ConfigCompiler::~ConfigCompiler(void)
|
ConfigCompiler::~ConfigCompiler(void)
|
||||||
{
|
{
|
||||||
DestroyScanner();
|
DestroyScanner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads data from the input stream. Used internally by the lexer.
|
||||||
|
*
|
||||||
|
* @param buffer Where to store data.
|
||||||
|
* @param max_size The maximum number of bytes to read from the stream.
|
||||||
|
* @returns The actual number of bytes read.
|
||||||
|
*/
|
||||||
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 static_cast<size_t>(m_Input->gcount());
|
return static_cast<size_t>(m_Input->gcount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the scanner object.
|
||||||
|
*
|
||||||
|
* @returns The scanner object.
|
||||||
|
*/
|
||||||
void *ConfigCompiler::GetScanner(void) const
|
void *ConfigCompiler::GetScanner(void) const
|
||||||
{
|
{
|
||||||
return m_Scanner;
|
return m_Scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the result from the compiler.
|
||||||
|
*
|
||||||
|
* @returns A list of configuration items.
|
||||||
|
*/
|
||||||
vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
|
vector<ConfigItem::Ptr> ConfigCompiler::GetResult(void) const
|
||||||
{
|
{
|
||||||
return m_Result;
|
return m_Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the path for the input file.
|
||||||
|
*
|
||||||
|
* @returns The path.
|
||||||
|
*/
|
||||||
String ConfigCompiler::GetPath(void) const
|
String ConfigCompiler::GetPath(void) const
|
||||||
{
|
{
|
||||||
return m_Path;
|
return m_Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles an include directive by calling the include handler callback
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* @param include The path from the include directive.
|
||||||
|
*/
|
||||||
void ConfigCompiler::HandleInclude(const String& include)
|
void ConfigCompiler::HandleInclude(const String& include)
|
||||||
{
|
{
|
||||||
String path = Utility::DirName(GetPath()) + "/" + include;
|
String path = Utility::DirName(GetPath()) + "/" + include;
|
||||||
|
@ -62,13 +102,27 @@ void ConfigCompiler::HandleInclude(const String& include)
|
||||||
std::copy(items.begin(), items.end(), back_inserter(m_Result));
|
std::copy(items.begin(), items.end(), back_inserter(m_Result));
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<ConfigItem::Ptr> ConfigCompiler::CompileStream(const String& path, istream *stream)
|
/**
|
||||||
|
* Compiles a stream.
|
||||||
|
*
|
||||||
|
* @param path A name identifying the stream.
|
||||||
|
* @param stream The input stream.
|
||||||
|
* @returns Configuration items.
|
||||||
|
*/
|
||||||
|
vector<ConfigItem::Ptr> ConfigCompiler::CompileStream(const String& path,
|
||||||
|
istream *stream)
|
||||||
{
|
{
|
||||||
ConfigCompiler ctx(path, stream);
|
ConfigCompiler ctx(path, stream);
|
||||||
ctx.Compile();
|
ctx.Compile();
|
||||||
return ctx.GetResult();
|
return ctx.GetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles a file.
|
||||||
|
*
|
||||||
|
* @param path The path.
|
||||||
|
* @returns Configuration items.
|
||||||
|
*/
|
||||||
vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const String& path)
|
vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const String& path)
|
||||||
{
|
{
|
||||||
ifstream stream;
|
ifstream stream;
|
||||||
|
@ -82,18 +136,38 @@ vector<ConfigItem::Ptr> ConfigCompiler::CompileFile(const String& path)
|
||||||
return CompileStream(path, &stream);
|
return CompileStream(path, &stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<ConfigItem::Ptr> ConfigCompiler::CompileText(const String& path, const String& text)
|
/**
|
||||||
|
* Compiles a snippet of text.
|
||||||
|
*
|
||||||
|
* @param path A name identifying the text.
|
||||||
|
* @param text The text.
|
||||||
|
* @returns Configuration items.
|
||||||
|
*/
|
||||||
|
vector<ConfigItem::Ptr> ConfigCompiler::CompileText(const String& path,
|
||||||
|
const String& text)
|
||||||
{
|
{
|
||||||
stringstream stream(text);
|
stringstream stream(text);
|
||||||
return CompileStream(path, &stream);
|
return CompileStream(path, &stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default include handler. Includes the file and returns a list of
|
||||||
|
* configuration items.
|
||||||
|
*
|
||||||
|
* @param include The path from the include directive.
|
||||||
|
* @returns A list of configuration objects.
|
||||||
|
*/
|
||||||
vector<ConfigItem::Ptr> ConfigCompiler::HandleFileInclude(const String& include)
|
vector<ConfigItem::Ptr> ConfigCompiler::HandleFileInclude(const String& include)
|
||||||
{
|
{
|
||||||
/* TODO: implement wildcard includes */
|
/* TODO: implement wildcard includes */
|
||||||
return CompileFile(include);
|
return CompileFile(include);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an object to the result.
|
||||||
|
*
|
||||||
|
* @param object The configuration item.
|
||||||
|
*/
|
||||||
void ConfigCompiler::AddObject(const ConfigItem::Ptr& object)
|
void ConfigCompiler::AddObject(const ConfigItem::Ptr& object)
|
||||||
{
|
{
|
||||||
m_Result.push_back(object);
|
m_Result.push_back(object);
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The configuration compiler can be used to compile a configuration file
|
||||||
|
* into a number of configuration items.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
class I2_CONFIG_API ConfigCompiler
|
class I2_CONFIG_API ConfigCompiler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -34,9 +40,11 @@ public:
|
||||||
|
|
||||||
void Compile(void);
|
void Compile(void);
|
||||||
|
|
||||||
static vector<ConfigItem::Ptr> CompileStream(const String& path, istream *stream);
|
static vector<ConfigItem::Ptr> CompileStream(const String& path,
|
||||||
|
istream *stream);
|
||||||
static vector<ConfigItem::Ptr> CompileFile(const String& path);
|
static vector<ConfigItem::Ptr> CompileFile(const String& path);
|
||||||
static vector<ConfigItem::Ptr> CompileText(const String& path, const String& text);
|
static vector<ConfigItem::Ptr> CompileText(const String& path,
|
||||||
|
const String& text);
|
||||||
|
|
||||||
static vector<ConfigItem::Ptr> HandleFileInclude(const String& include);
|
static vector<ConfigItem::Ptr> HandleFileInclude(const String& include);
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,15 @@ ConfigItem::ItemMap ConfigItem::m_Items;
|
||||||
boost::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnCommitted;
|
boost::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnCommitted;
|
||||||
boost::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
|
boost::signal<void (const ConfigItem::Ptr&)> ConfigItem::OnRemoved;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the ConfigItem class.
|
||||||
|
*
|
||||||
|
* @param type The object type.
|
||||||
|
* @param name The name of the item.
|
||||||
|
* @param exprl Expression list for the item.
|
||||||
|
* @param parents Parent objects for the item.
|
||||||
|
* @param debuginfo Debug information.
|
||||||
|
*/
|
||||||
ConfigItem::ConfigItem(const String& type, const String& name,
|
ConfigItem::ConfigItem(const String& type, const String& name,
|
||||||
const ExpressionList::Ptr& exprl, const vector<String>& parents,
|
const ExpressionList::Ptr& exprl, const vector<String>& parents,
|
||||||
const DebugInfo& debuginfo)
|
const DebugInfo& debuginfo)
|
||||||
|
@ -33,31 +42,63 @@ ConfigItem::ConfigItem(const String& type, const String& name,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the type of the configuration item.
|
||||||
|
*
|
||||||
|
* @returns The type.
|
||||||
|
*/
|
||||||
String ConfigItem::GetType(void) const
|
String ConfigItem::GetType(void) const
|
||||||
{
|
{
|
||||||
return m_Type;
|
return m_Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the name of the configuration item.
|
||||||
|
*
|
||||||
|
* @returns The name.
|
||||||
|
*/
|
||||||
String ConfigItem::GetName(void) const
|
String ConfigItem::GetName(void) const
|
||||||
{
|
{
|
||||||
return m_Name;
|
return m_Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the debug information for the configuration item.
|
||||||
|
*
|
||||||
|
* @returns The debug information.
|
||||||
|
*/
|
||||||
DebugInfo ConfigItem::GetDebugInfo(void) const
|
DebugInfo ConfigItem::GetDebugInfo(void) const
|
||||||
{
|
{
|
||||||
return m_DebugInfo;
|
return m_DebugInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the expression list for the configuration item.
|
||||||
|
*
|
||||||
|
* @returns The expression list.
|
||||||
|
*/
|
||||||
ExpressionList::Ptr ConfigItem::GetExpressionList(void) const
|
ExpressionList::Ptr ConfigItem::GetExpressionList(void) const
|
||||||
{
|
{
|
||||||
return m_ExpressionList;
|
return m_ExpressionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the list of parents for the configuration item.
|
||||||
|
*
|
||||||
|
* @returns The list of parents.
|
||||||
|
*/
|
||||||
vector<String> ConfigItem::GetParents(void) const
|
vector<String> ConfigItem::GetParents(void) const
|
||||||
{
|
{
|
||||||
return m_Parents;
|
return m_Parents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the object's properties based on parent objects and the object's
|
||||||
|
* expression list.
|
||||||
|
*
|
||||||
|
* @param dictionary The dictionary that should be used to store the
|
||||||
|
* properties.
|
||||||
|
*/
|
||||||
void ConfigItem::CalculateProperties(const Dictionary::Ptr& dictionary) const
|
void ConfigItem::CalculateProperties(const Dictionary::Ptr& dictionary) const
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const String& name, m_Parents) {
|
BOOST_FOREACH(const String& name, m_Parents) {
|
||||||
|
@ -65,7 +106,8 @@ void ConfigItem::CalculateProperties(const Dictionary::Ptr& dictionary) const
|
||||||
|
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "Parent object '" << name << "' does not exist (" << m_DebugInfo << ")";
|
message << "Parent object '" << name << "' does not"
|
||||||
|
" exist (" << m_DebugInfo << ")";
|
||||||
throw_exception(domain_error(message.str()));
|
throw_exception(domain_error(message.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +117,12 @@ void ConfigItem::CalculateProperties(const Dictionary::Ptr& dictionary) const
|
||||||
m_ExpressionList->Execute(dictionary);
|
m_ExpressionList->Execute(dictionary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Commits the configuration item by creating or updating a DynamicObject
|
||||||
|
* object.
|
||||||
|
*
|
||||||
|
* @returns The DynamicObject that was created/updated.
|
||||||
|
*/
|
||||||
DynamicObject::Ptr ConfigItem::Commit(void)
|
DynamicObject::Ptr ConfigItem::Commit(void)
|
||||||
{
|
{
|
||||||
DynamicObject::Ptr dobj = m_DynamicObject.lock();
|
DynamicObject::Ptr dobj = m_DynamicObject.lock();
|
||||||
|
@ -125,6 +173,9 @@ DynamicObject::Ptr ConfigItem::Commit(void)
|
||||||
return dobj;
|
return dobj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters the configuration item.
|
||||||
|
*/
|
||||||
void ConfigItem::Unregister(void)
|
void ConfigItem::Unregister(void)
|
||||||
{
|
{
|
||||||
DynamicObject::Ptr dobj = m_DynamicObject.lock();
|
DynamicObject::Ptr dobj = m_DynamicObject.lock();
|
||||||
|
@ -141,11 +192,23 @@ void ConfigItem::Unregister(void)
|
||||||
OnRemoved(GetSelf());
|
OnRemoved(GetSelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the DynamicObject that belongs to the configuration item.
|
||||||
|
*
|
||||||
|
* @returns The DynamicObject.
|
||||||
|
*/
|
||||||
DynamicObject::Ptr ConfigItem::GetDynamicObject(void) const
|
DynamicObject::Ptr ConfigItem::GetDynamicObject(void) const
|
||||||
{
|
{
|
||||||
return m_DynamicObject.lock();
|
return m_DynamicObject.lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a configuration item by type and name.
|
||||||
|
*
|
||||||
|
* @param type The type of the ConfigItem that is to be looked up.
|
||||||
|
* @param name The name of the ConfigItem that is to be looked up.
|
||||||
|
* @returns The configuration item.
|
||||||
|
*/
|
||||||
ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name)
|
ConfigItem::Ptr ConfigItem::GetObject(const String& type, const String& name)
|
||||||
{
|
{
|
||||||
ConfigItem::ItemMap::iterator it;
|
ConfigItem::ItemMap::iterator it;
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A configuration item. Non-abstract configuration items can be used to
|
||||||
|
* create configuration objects at runtime.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
class I2_CONFIG_API ConfigItem : public Object {
|
class I2_CONFIG_API ConfigItem : public Object {
|
||||||
public:
|
public:
|
||||||
typedef shared_ptr<ConfigItem> Ptr;
|
typedef shared_ptr<ConfigItem> Ptr;
|
||||||
|
@ -46,7 +52,8 @@ public:
|
||||||
|
|
||||||
DebugInfo GetDebugInfo(void) const;
|
DebugInfo GetDebugInfo(void) const;
|
||||||
|
|
||||||
static ConfigItem::Ptr GetObject(const String& type, const String& name);
|
static ConfigItem::Ptr GetObject(const String& type,
|
||||||
|
const String& name);
|
||||||
|
|
||||||
static boost::signal<void (const ConfigItem::Ptr&)> OnCommitted;
|
static boost::signal<void (const ConfigItem::Ptr&)> OnCommitted;
|
||||||
static boost::signal<void (const ConfigItem::Ptr&)> OnRemoved;
|
static boost::signal<void (const ConfigItem::Ptr&)> OnRemoved;
|
||||||
|
@ -54,17 +61,20 @@ public:
|
||||||
private:
|
private:
|
||||||
void CalculateProperties(const Dictionary::Ptr& dictionary) const;
|
void CalculateProperties(const Dictionary::Ptr& dictionary) const;
|
||||||
|
|
||||||
String m_Type;
|
String m_Type; /**< The object type. */
|
||||||
String m_Name;
|
String m_Name; /**< The name. */
|
||||||
|
|
||||||
ExpressionList::Ptr m_ExpressionList;
|
ExpressionList::Ptr m_ExpressionList;
|
||||||
vector<String> m_Parents;
|
vector<String> m_Parents; /**< The names of parent configuration
|
||||||
DebugInfo m_DebugInfo;
|
items. */
|
||||||
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||||
|
|
||||||
DynamicObject::WeakPtr m_DynamicObject;
|
DynamicObject::WeakPtr m_DynamicObject; /**< The instantiated version
|
||||||
|
of this configuration
|
||||||
|
item */
|
||||||
|
|
||||||
typedef map<pair<String, String>, ConfigItem::Ptr> ItemMap;
|
typedef map<pair<String, String>, ConfigItem::Ptr> ItemMap;
|
||||||
static ItemMap m_Items;
|
static ItemMap m_Items; /**< All registered configuration items. */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,8 @@ void ConfigItemBuilder::AddExpression(const Expression& expr)
|
||||||
m_ExpressionList->AddExpression(expr);
|
m_ExpressionList->AddExpression(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigItemBuilder::AddExpression(const String& key, ExpressionOperator op, const Value& value)
|
void ConfigItemBuilder::AddExpression(const String& key, ExpressionOperator op,
|
||||||
|
const Value& value)
|
||||||
{
|
{
|
||||||
Expression expr(key, op, value, m_DebugInfo);
|
Expression expr(key, op, value, m_DebugInfo);
|
||||||
AddExpression(expr);
|
AddExpression(expr);
|
||||||
|
@ -101,5 +102,6 @@ ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
||||||
Expression abstractExpr("__abstract", OperatorSet, m_Abstract, m_DebugInfo);
|
Expression abstractExpr("__abstract", OperatorSet, m_Abstract, m_DebugInfo);
|
||||||
exprl->AddExpression(abstractExpr);
|
exprl->AddExpression(abstractExpr);
|
||||||
|
|
||||||
return boost::make_shared<ConfigItem>(m_Type, m_Name, exprl, m_Parents, m_DebugInfo);
|
return boost::make_shared<ConfigItem>(m_Type, m_Name, exprl, m_Parents,
|
||||||
|
m_DebugInfo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config item builder. Used to dynamically build configuration objects
|
||||||
|
* at runtime.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
class I2_CONFIG_API ConfigItemBuilder : public Object
|
class I2_CONFIG_API ConfigItemBuilder : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -40,19 +46,21 @@ public:
|
||||||
void AddParent(const String& parent);
|
void AddParent(const String& parent);
|
||||||
|
|
||||||
void AddExpression(const Expression& expr);
|
void AddExpression(const Expression& expr);
|
||||||
void AddExpression(const String& key, ExpressionOperator op, const Value& value);
|
void AddExpression(const String& key, ExpressionOperator op,
|
||||||
|
const Value& value);
|
||||||
void AddExpressionList(const ExpressionList::Ptr& exprl);
|
void AddExpressionList(const ExpressionList::Ptr& exprl);
|
||||||
|
|
||||||
ConfigItem::Ptr Compile(void);
|
ConfigItem::Ptr Compile(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_Type;
|
String m_Type; /**< The object type. */
|
||||||
String m_Name;
|
String m_Name; /**< The name. */
|
||||||
bool m_Local;
|
bool m_Local; /**< Whether the item is local. */
|
||||||
bool m_Abstract;
|
bool m_Abstract; /**< Whether the item is abstract. */
|
||||||
vector<String> m_Parents;
|
vector<String> m_Parents; /**< The names of parent configuration
|
||||||
ExpressionList::Ptr m_ExpressionList;
|
items. */
|
||||||
DebugInfo m_DebugInfo;
|
ExpressionList::Ptr m_ExpressionList; /**< Expressions for this item. */
|
||||||
|
DebugInfo m_DebugInfo; /**< Debug information. */
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debug information for a configuration element.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
struct DebugInfo
|
struct DebugInfo
|
||||||
{
|
{
|
||||||
String Path;
|
String Path;
|
||||||
|
@ -52,6 +57,13 @@ struct DebugInfo
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs a DebugInfo struct to a stream.
|
||||||
|
*
|
||||||
|
* @param out The output stream.
|
||||||
|
* @param val The DebugInfo struct.
|
||||||
|
* @returns The output stream.
|
||||||
|
*/
|
||||||
inline ostream& operator<<(ostream& out, const DebugInfo& val)
|
inline ostream& operator<<(ostream& out, const DebugInfo& val)
|
||||||
{
|
{
|
||||||
out << "in " << val.Path << ": "
|
out << "in " << val.Path << ": "
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
Expression::Expression(const String& key, ExpressionOperator op, const Value& value, const DebugInfo& debuginfo)
|
Expression::Expression(const String& key, ExpressionOperator op,
|
||||||
|
const Value& value, const DebugInfo& debuginfo)
|
||||||
: m_Key(key), m_Operator(op), m_Value(value), m_DebugInfo(debuginfo)
|
: m_Key(key), m_Operator(op), m_Value(value), m_DebugInfo(debuginfo)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,10 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
||||||
if (!dict) {
|
if (!dict) {
|
||||||
if (!oldValue.IsEmpty()) {
|
if (!oldValue.IsEmpty()) {
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "Wrong argument types for += (non-dictionary and dictionary) (" << m_DebugInfo << ")";
|
message << "Wrong argument types for"
|
||||||
|
" += (non-dictionary and"
|
||||||
|
" dictionary) ("
|
||||||
|
<< m_DebugInfo << ")";
|
||||||
throw_exception(domain_error(message.str()));
|
throw_exception(domain_error(message.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +92,8 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "+= only works for dictionaries (" << m_DebugInfo << ")";
|
message << "+= only works for dictionaries ("
|
||||||
|
<< m_DebugInfo << ")";
|
||||||
throw_exception(domain_error(message.str()));
|
throw_exception(domain_error(message.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operator in a configuration expression.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
enum ExpressionOperator
|
enum ExpressionOperator
|
||||||
{
|
{
|
||||||
OperatorExecute,
|
OperatorExecute,
|
||||||
|
@ -33,10 +38,16 @@ enum ExpressionOperator
|
||||||
OperatorDivide
|
OperatorDivide
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A configuration expression.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
struct I2_CONFIG_API Expression
|
struct I2_CONFIG_API Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Expression(const String& key, ExpressionOperator op, const Value& value, const DebugInfo& debuginfo);
|
Expression(const String& key, ExpressionOperator op, const Value& value,
|
||||||
|
const DebugInfo& debuginfo);
|
||||||
|
|
||||||
void Execute(const Dictionary::Ptr& dictionary) const;
|
void Execute(const Dictionary::Ptr& dictionary) const;
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,32 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an expression to an expression list.
|
||||||
|
*
|
||||||
|
* @param expression The expression that should be added.
|
||||||
|
*/
|
||||||
void ExpressionList::AddExpression(const Expression& expression)
|
void ExpressionList::AddExpression(const Expression& expression)
|
||||||
{
|
{
|
||||||
m_Expressions.push_back(expression);
|
m_Expressions.push_back(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of items currently contained in the expression list.
|
||||||
|
*
|
||||||
|
* @returns The length of the list.
|
||||||
|
*/
|
||||||
size_t ExpressionList::GetLength(void) const
|
size_t ExpressionList::GetLength(void) const
|
||||||
{
|
{
|
||||||
return m_Expressions.size();
|
return m_Expressions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the expression list.
|
||||||
|
*
|
||||||
|
* @param dictionary The dictionary that should be manipulated by the
|
||||||
|
* expressions.
|
||||||
|
*/
|
||||||
void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
|
void ExpressionList::Execute(const Dictionary::Ptr& dictionary) const
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const Expression& expression, m_Expressions) {
|
BOOST_FOREACH(const Expression& expression, m_Expressions) {
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of configuration expressions.
|
||||||
|
*
|
||||||
|
* @ingroup config
|
||||||
|
*/
|
||||||
class I2_CONFIG_API ExpressionList : public Object
|
class I2_CONFIG_API ExpressionList : public Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -21,10 +21,11 @@
|
||||||
#define I2CONFIG_H
|
#define I2CONFIG_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup config Dynamic object library
|
* @defgroup config Configuration library
|
||||||
*
|
*
|
||||||
* The dynamic object library implements serializable objects which support
|
* The configuration library implements a compiler for Icinga 2's configuration
|
||||||
* inheritance.
|
* format. It also provides functionality for creating configuration objects
|
||||||
|
* at runtime.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <i2-base.h>
|
#include <i2-base.h>
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common Information Base class. Holds some statistics (and will likely be
|
||||||
|
* removed/refactored).
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API CIB
|
class I2_ICINGA_API CIB
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Icinga host.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API Host : public DynamicObject
|
class I2_ICINGA_API Host : public DynamicObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Icinga host group.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API HostGroup : public DynamicObject
|
class I2_ICINGA_API HostGroup : public DynamicObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
#define I2ICINGA_H
|
#define I2ICINGA_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup icinga Icinga application
|
* @defgroup icinga Icinga library
|
||||||
*
|
*
|
||||||
* The Icinga application is in charge of boot-strapping the Icinga
|
* The Icinga library implements all Icinga-specific functionality that is
|
||||||
* environment and loading additional components.
|
* common to all components (e.g. hosts, services, etc.).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <i2-base.h>
|
#include <i2-base.h>
|
||||||
|
|
|
@ -28,19 +28,19 @@
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
const String IcingaApplication::DefaultPidPath = "icinga.pid";
|
const String IcingaApplication::DefaultPidPath = "icinga2.pid";
|
||||||
const String IcingaApplication::DefaultStatePath = "icinga.state";
|
const String IcingaApplication::DefaultStatePath = "icinga2.state";
|
||||||
|
|
||||||
IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate)
|
IcingaApplication::IcingaApplication(const Dictionary::Ptr& serializedUpdate)
|
||||||
: Application(serializedUpdate)
|
: Application(serializedUpdate)
|
||||||
{
|
{
|
||||||
/* load cibsync config component */
|
/* load replication config component */
|
||||||
ConfigItemBuilder::Ptr cibsyncComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
ConfigItemBuilder::Ptr replicationComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
||||||
cibsyncComponentConfig->SetType("Component");
|
replicationComponentConfig->SetType("Component");
|
||||||
cibsyncComponentConfig->SetName("cibsync");
|
replicationComponentConfig->SetName("replication");
|
||||||
cibsyncComponentConfig->SetLocal(true);
|
replicationComponentConfig->SetLocal(true);
|
||||||
cibsyncComponentConfig->Compile()->Commit();
|
replicationComponentConfig->Compile()->Commit();
|
||||||
cibsyncComponentConfig.reset();
|
replicationComponentConfig.reset();
|
||||||
|
|
||||||
/* load convenience config component */
|
/* load convenience config component */
|
||||||
ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves macros.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API MacroProcessor
|
class I2_ICINGA_API MacroProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements Nagios(TM)-style checks.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API NagiosCheckTask
|
class I2_ICINGA_API NagiosCheckTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for additional check types. Implements the "null" check type.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API NullCheckTask
|
class I2_ICINGA_API NullCheckTask
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state of a service.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
enum ServiceState
|
enum ServiceState
|
||||||
{
|
{
|
||||||
StateOK,
|
StateOK,
|
||||||
|
@ -32,6 +37,11 @@ enum ServiceState
|
||||||
StateUncheckable,
|
StateUncheckable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The state type of a service.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
enum ServiceStateType
|
enum ServiceStateType
|
||||||
{
|
{
|
||||||
StateTypeSoft,
|
StateTypeSoft,
|
||||||
|
@ -41,6 +51,11 @@ enum ServiceStateType
|
||||||
class CheckResultMessage;
|
class CheckResultMessage;
|
||||||
class ServiceStatusMessage;
|
class ServiceStatusMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Icinga service.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API Service : public DynamicObject
|
class I2_ICINGA_API Service : public DynamicObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Icinga service group.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API ServiceGroup : public DynamicObject
|
class I2_ICINGA_API ServiceGroup : public DynamicObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A state change message for a service.
|
||||||
|
*
|
||||||
|
* @ingroup icinga
|
||||||
|
*/
|
||||||
class I2_ICINGA_API ServiceStateChangeMessage : public MessagePart
|
class I2_ICINGA_API ServiceStateChangeMessage : public MessagePart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -28,6 +28,11 @@ boost::signal<void (const Endpoint::Ptr&)> Endpoint::OnDisconnected;
|
||||||
boost::signal<void (const Endpoint::Ptr&, const String& topic)> Endpoint::OnSubscriptionRegistered;
|
boost::signal<void (const Endpoint::Ptr&, const String& topic)> Endpoint::OnSubscriptionRegistered;
|
||||||
boost::signal<void (const Endpoint::Ptr&, const String& topic)> Endpoint::OnSubscriptionUnregistered;
|
boost::signal<void (const Endpoint::Ptr&, const String& topic)> Endpoint::OnSubscriptionUnregistered;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for the Endpoint class.
|
||||||
|
*
|
||||||
|
* @param properties A serialized dictionary containing attributes.
|
||||||
|
*/
|
||||||
Endpoint::Endpoint(const Dictionary::Ptr& serializedUpdate)
|
Endpoint::Endpoint(const Dictionary::Ptr& serializedUpdate)
|
||||||
: DynamicObject(serializedUpdate)
|
: DynamicObject(serializedUpdate)
|
||||||
{
|
{
|
||||||
|
@ -38,11 +43,23 @@ Endpoint::Endpoint(const Dictionary::Ptr& serializedUpdate)
|
||||||
RegisterAttribute("client", Attribute_Transient);
|
RegisterAttribute("client", Attribute_Transient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether an endpoint with the specified name exists.
|
||||||
|
*
|
||||||
|
* @param name The name of the endpoint.
|
||||||
|
* @returns true if the endpoint exists, false otherwise.
|
||||||
|
*/
|
||||||
bool Endpoint::Exists(const String& name)
|
bool Endpoint::Exists(const String& name)
|
||||||
{
|
{
|
||||||
return (DynamicObject::GetObject("Endpoint", name));
|
return (DynamicObject::GetObject("Endpoint", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an endpoint by name.
|
||||||
|
*
|
||||||
|
* @param name The name of the endpoint.
|
||||||
|
* @returns The endpoint.
|
||||||
|
*/
|
||||||
Endpoint::Ptr Endpoint::GetByName(const String& name)
|
Endpoint::Ptr Endpoint::GetByName(const String& name)
|
||||||
{
|
{
|
||||||
DynamicObject::Ptr configObject = DynamicObject::GetObject("Endpoint", name);
|
DynamicObject::Ptr configObject = DynamicObject::GetObject("Endpoint", name);
|
||||||
|
@ -53,6 +70,13 @@ Endpoint::Ptr Endpoint::GetByName(const String& name)
|
||||||
return dynamic_pointer_cast<Endpoint>(configObject);
|
return dynamic_pointer_cast<Endpoint>(configObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for creating new endpoint objects.
|
||||||
|
*
|
||||||
|
* @param name The name of the new endpoint.
|
||||||
|
* @param local Whether the new endpoint should be local.
|
||||||
|
* @returns The new endpoint.
|
||||||
|
*/
|
||||||
Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool local)
|
Endpoint::Ptr Endpoint::MakeEndpoint(const String& name, bool local)
|
||||||
{
|
{
|
||||||
ConfigItemBuilder::Ptr endpointConfig = boost::make_shared<ConfigItemBuilder>();
|
ConfigItemBuilder::Ptr endpointConfig = boost::make_shared<ConfigItemBuilder>();
|
||||||
|
@ -334,11 +358,21 @@ void Endpoint::ClientClosedHandler(void)
|
||||||
OnDisconnected(GetSelf());
|
OnDisconnected(GetSelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the node address for this endpoint.
|
||||||
|
*
|
||||||
|
* @returns The node address (hostname).
|
||||||
|
*/
|
||||||
String Endpoint::GetNode(void) const
|
String Endpoint::GetNode(void) const
|
||||||
{
|
{
|
||||||
return Get("node");
|
return Get("node");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the service name for this endpoint.
|
||||||
|
*
|
||||||
|
* @returns The service name (port).
|
||||||
|
*/
|
||||||
String Endpoint::GetService(void) const
|
String Endpoint::GetService(void) const
|
||||||
{
|
{
|
||||||
return Get("service");
|
return Get("service");
|
||||||
|
|
|
@ -28,7 +28,7 @@ class EndpointManager;
|
||||||
/**
|
/**
|
||||||
* An endpoint that can be used to send and receive messages.
|
* An endpoint that can be used to send and receive messages.
|
||||||
*
|
*
|
||||||
* @ingroup icinga
|
* @ingroup remoting
|
||||||
*/
|
*/
|
||||||
class I2_REMOTING_API Endpoint : public DynamicObject
|
class I2_REMOTING_API Endpoint : public DynamicObject
|
||||||
{
|
{
|
||||||
|
|
|
@ -258,25 +258,9 @@ void EndpointManager::SendMulticastMessage(const Endpoint::Ptr& sender,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls the specified callback function for each registered endpoint.
|
|
||||||
*
|
|
||||||
* @param callback The callback function.
|
|
||||||
*/
|
|
||||||
//void EndpointManager::ForEachEndpoint(function<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> callback)
|
|
||||||
//{
|
|
||||||
// map<String, Endpoint::Ptr>::iterator prev, i;
|
|
||||||
// for (i = m_Endpoints.begin(); i != m_Endpoints.end(); ) {
|
|
||||||
// prev = i;
|
|
||||||
// i++;
|
|
||||||
//
|
|
||||||
// callback(GetSelf(), prev->second);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
void EndpointManager::SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient,
|
void EndpointManager::SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient,
|
||||||
RequestMessage& message,
|
RequestMessage& message,
|
||||||
function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, double timeout)
|
const EndpointManager::APICallback& callback, double timeout)
|
||||||
{
|
{
|
||||||
m_NextMessageID++;
|
m_NextMessageID++;
|
||||||
|
|
||||||
|
@ -322,7 +306,8 @@ void EndpointManager::SubscriptionTimerHandler(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Endpoint->SetSubscriptions(subscriptions);
|
if (m_Endpoint)
|
||||||
|
m_Endpoint->SetSubscriptions(subscriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndpointManager::ReconnectTimerHandler(void)
|
void EndpointManager::ReconnectTimerHandler(void)
|
||||||
|
@ -354,7 +339,8 @@ 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++) {
|
||||||
if (it->second.HasTimedOut()) {
|
if (it->second.HasTimedOut()) {
|
||||||
it->second.Callback(GetSelf(), Endpoint::Ptr(), it->second.Request, ResponseMessage(), true);
|
it->second.Callback(GetSelf(), Endpoint::Ptr(),
|
||||||
|
it->second.Request, ResponseMessage(), true);
|
||||||
|
|
||||||
m_Requests.erase(it);
|
m_Requests.erase(it);
|
||||||
|
|
||||||
|
@ -363,7 +349,8 @@ void EndpointManager::RequestTimerHandler(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message)
|
void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender,
|
||||||
|
const ResponseMessage& message)
|
||||||
{
|
{
|
||||||
String id;
|
String id;
|
||||||
if (!message.GetID(&id))
|
if (!message.GetID(&id))
|
||||||
|
@ -380,16 +367,6 @@ void EndpointManager::ProcessResponseMessage(const Endpoint::Ptr& sender, const
|
||||||
m_Requests.erase(it);
|
m_Requests.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
//EndpointManager::Iterator EndpointManager::Begin(void)
|
|
||||||
//{
|
|
||||||
// return m_Endpoints.begin();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//EndpointManager::Iterator EndpointManager::End(void)
|
|
||||||
//{
|
|
||||||
// return m_Endpoints.end();
|
|
||||||
//}
|
|
||||||
|
|
||||||
EndpointManager::Ptr EndpointManager::GetInstance(void)
|
EndpointManager::Ptr EndpointManager::GetInstance(void)
|
||||||
{
|
{
|
||||||
static EndpointManager::Ptr instance;
|
static EndpointManager::Ptr instance;
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace icinga
|
||||||
/**
|
/**
|
||||||
* Forwards messages between endpoints.
|
* Forwards messages between endpoints.
|
||||||
*
|
*
|
||||||
* @ingroup icinga
|
* @ingroup remoting
|
||||||
*/
|
*/
|
||||||
class I2_REMOTING_API EndpointManager : public Object
|
class I2_REMOTING_API EndpointManager : public Object
|
||||||
{
|
{
|
||||||
|
@ -51,15 +51,13 @@ public:
|
||||||
void SendAnycastMessage(const Endpoint::Ptr& sender, const RequestMessage& message);
|
void SendAnycastMessage(const Endpoint::Ptr& sender, const RequestMessage& message);
|
||||||
void SendMulticastMessage(const Endpoint::Ptr& sender, const RequestMessage& message);
|
void SendMulticastMessage(const Endpoint::Ptr& sender, const RequestMessage& message);
|
||||||
|
|
||||||
|
typedef function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> APICallback;
|
||||||
|
|
||||||
void SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, RequestMessage& message,
|
void SendAPIMessage(const Endpoint::Ptr& sender, const Endpoint::Ptr& recipient, RequestMessage& message,
|
||||||
function<void(const EndpointManager::Ptr&, const Endpoint::Ptr, const RequestMessage&, const ResponseMessage&, bool TimedOut)> callback, double timeout = 30);
|
const APICallback& callback, double timeout = 30);
|
||||||
|
|
||||||
void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
|
void ProcessResponseMessage(const Endpoint::Ptr& sender, const ResponseMessage& message);
|
||||||
|
|
||||||
// void ForEachEndpoint(function<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> callback);
|
|
||||||
// Iterator Begin(void);
|
|
||||||
// Iterator End(void);
|
|
||||||
|
|
||||||
boost::signal<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> OnNewEndpoint;
|
boost::signal<void (const EndpointManager::Ptr&, const Endpoint::Ptr&)> OnNewEndpoint;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -78,7 +76,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Information about a pending API request.
|
* Information about a pending API request.
|
||||||
*
|
*
|
||||||
* @ingroup icinga
|
* @ingroup remoting
|
||||||
*/
|
*/
|
||||||
struct I2_REMOTING_API PendingRequest
|
struct I2_REMOTING_API PendingRequest
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
#define I2REMOTING_H
|
#define I2REMOTING_H
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup remoting JSON-RPC library
|
* @defgroup remoting Remoting library
|
||||||
*
|
*
|
||||||
* The JSON-RPC library implements server and client classes for the JSON-RPC
|
* Implements server and client classes for the JSON-RPC protocol. Also
|
||||||
* protocol.
|
* supports endpoint-based communication using messages.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <i2-base.h>
|
#include <i2-base.h>
|
||||||
|
|
|
@ -30,7 +30,8 @@ using namespace icinga;
|
||||||
JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
JsonRpcClient::JsonRpcClient(TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
||||||
: TlsClient(role, sslContext)
|
: TlsClient(role, sslContext)
|
||||||
{
|
{
|
||||||
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler, this));
|
OnDataAvailable.connect(boost::bind(&JsonRpcClient::DataAvailableHandler,
|
||||||
|
this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,12 +60,16 @@ void JsonRpcClient::DataAvailableHandler(void)
|
||||||
try {
|
try {
|
||||||
Value value = Value::Deserialize(jsonString);
|
Value value = Value::Deserialize(jsonString);
|
||||||
|
|
||||||
if (!value.IsObjectType<Dictionary>())
|
if (!value.IsObjectType<Dictionary>()) {
|
||||||
throw_exception(invalid_argument("JSON-RPC message must be a dictionary."));
|
throw_exception(invalid_argument("JSON-RPC"
|
||||||
|
" message must be a dictionary."));
|
||||||
|
}
|
||||||
|
|
||||||
OnNewMessage(GetSelf(), MessagePart(value));
|
OnNewMessage(GetSelf(), MessagePart(value));
|
||||||
} catch (const exception& ex) {
|
} catch (const exception& ex) {
|
||||||
Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + String(ex.what()));
|
Logger::Write(LogCritical, "remoting", "Exception"
|
||||||
|
" while processing message from JSON-RPC client: " +
|
||||||
|
String(ex.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,9 +82,11 @@ void JsonRpcClient::DataAvailableHandler(void)
|
||||||
* @param sslContext SSL context for the TLS connection.
|
* @param sslContext SSL context for the TLS connection.
|
||||||
* @returns A new JSON-RPC client.
|
* @returns A new JSON-RPC client.
|
||||||
*/
|
*/
|
||||||
JsonRpcClient::Ptr icinga::JsonRpcClientFactory(SOCKET fd, TcpClientRole role, shared_ptr<SSL_CTX> sslContext)
|
JsonRpcClient::Ptr icinga::JsonRpcClientFactory(SOCKET fd, TcpClientRole role,
|
||||||
|
shared_ptr<SSL_CTX> sslContext)
|
||||||
{
|
{
|
||||||
JsonRpcClient::Ptr client = boost::make_shared<JsonRpcClient>(role, sslContext);
|
JsonRpcClient::Ptr client = boost::make_shared<JsonRpcClient>(role,
|
||||||
|
sslContext);
|
||||||
client->SetFD(fd);
|
client->SetFD(fd);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ Dictionary::Ptr MessagePart::GetDictionary(void) const
|
||||||
* Retrieves a property's value.
|
* Retrieves a property's value.
|
||||||
*
|
*
|
||||||
* @param key The name of the property.
|
* @param key The name of the property.
|
||||||
* @param[out] The value.
|
* @param[out] value The value.
|
||||||
* @returns true if the value was retrieved, false otherwise.
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool MessagePart::Get(String key, MessagePart *value) const
|
bool MessagePart::Get(String key, MessagePart *value) const
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
* Retrieves a property's value.
|
* Retrieves a property's value.
|
||||||
*
|
*
|
||||||
* @param key The name of the property.
|
* @param key The name of the property.
|
||||||
* @param[out] The value.
|
* @param[out] value The value.
|
||||||
* @returns true if the value was retrieved, false otherwise.
|
* @returns true if the value was retrieved, false otherwise.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -108,7 +108,7 @@ if test "x$want_boost" = "xyes"; then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
elif test "$cross_compiling" != yes; then
|
elif test "$cross_compiling" != yes; then
|
||||||
for ac_boost_path_tmp in /usr /usr/local /opt /opt/local "`pwd`/compat" ; do
|
for ac_boost_path_tmp in /usr /usr/local /opt /opt/local /usr/g++ "`pwd`/compat" ; do
|
||||||
if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
|
if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
|
||||||
for libsubdir in $libsubdirs ; do
|
for libsubdir in $libsubdirs ; do
|
||||||
if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
|
if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
|
||||||
|
|
|
@ -83,14 +83,14 @@ AC_DEFUN([AX_BOOST_SYSTEM],
|
||||||
|
|
||||||
LDFLAGS_SAVE=$LDFLAGS
|
LDFLAGS_SAVE=$LDFLAGS
|
||||||
if test "x$ax_boost_user_system_lib" = "x"; then
|
if test "x$ax_boost_user_system_lib" = "x"; then
|
||||||
for libextension in `ls $BOOSTLIBDIR/libboost_system*.a* $BOOSTLIBDIR/libboost_system*.so* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_system.*\)\.\(so\|a\).*$;\1;' | tac` ; do
|
for libextension in `ls $BOOSTLIBDIR/libboost_system*.so* $BOOSTLIBDIR/libboost_system*.dylib* $BOOSTLIBDIR/libboost_system*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_system.*\)\.so.*$;\1;' -e 's;^lib\(boost_system.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_system.*\)\.a.*$;\1;'` ; do
|
||||||
ax_lib=${libextension}
|
ax_lib=${libextension}
|
||||||
AC_CHECK_LIB($ax_lib, exit,
|
AC_CHECK_LIB($ax_lib, exit,
|
||||||
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
|
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
|
||||||
[link_system="no"])
|
[link_system="no"])
|
||||||
done
|
done
|
||||||
if test "x$link_system" != "xyes"; then
|
if test "x$link_system" != "xyes"; then
|
||||||
for libextension in `ls $BOOSTLIBDIR/boost_system*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_system.*\)\.\(dll\|a\).*$;\1;' | tac` ; do
|
for libextension in `ls $BOOSTLIBDIR/boost_system*.dll* $BOOSTLIBDIR/boost_system*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_system.*\)\.dll.*$;\1;' -e 's;^\(boost_system.*\)\.a*$;\1;'` ; do
|
||||||
ax_lib=${libextension}
|
ax_lib=${libextension}
|
||||||
AC_CHECK_LIB($ax_lib, exit,
|
AC_CHECK_LIB($ax_lib, exit,
|
||||||
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
|
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
|
||||||
|
|
Loading…
Reference in New Issue